SEATAdocker-compose部署
docker-compose 文件
1 | version: '3' |
前提配置
目录结构
创建seata 文件夹
1
mkdir seata
编写config.txt 内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19service.vgroupMapping.${
spring.application.name}-group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://${
host}:${
port}/ry-seata?useUnicode=true
store.db.user=root
store.db.password=${
pwd}
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000编写registry.conf 内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33registry {
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "${
nacosHost:port}"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "${
nacosLoginName}"
password = "${
pwd}"
}
}
config {
type = "nacos"
nacos {
serverAddr = "${
nacosHost:port}"
namespace = ""
group = "SEATA_GROUP"
username = "${
nacosLoginName}"
password = "${
pwd}"
}
}编写nacos-config.sh 内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131#!/usr/bin/env bash
# Copyright 1999-2019 Seata.io Group.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at、
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
while getopts ":h:p:g:t:u:w:" opt
do
case $opt in
h)
host=$OPTARG
;;
p)
port=$OPTARG
;;
g)
group=$OPTARG
;;
t)
tenant=$OPTARG
;;
u)
username=$OPTARG
;;
w)
password=$OPTARG
;;
?)
echo " USAGE OPTION: $0 [-h host] [-p port] [-g group] [-t tenant] [-u username] [-w password] "
exit 1
;;
esac
done
urlencode() {
for ((i=0; i < ${
#1}; i++))
do
char="${
1:$i:1}"
case $char in
[a-zA-Z0-9.~_-]) printf $char ;;
*) printf '%%%02X' "'$char" ;;
esac
done
}
if [[ -z ${
host} ]]; then
host=localhost
fi
if [[ -z ${
port} ]]; then
port=8848
fi
if [[ -z ${
group} ]]; then
group="SEATA_GROUP"
fi
if [[ -z ${
tenant} ]]; then
tenant=""
fi
if [[ -z ${
username} ]]; then
username=""
fi
if [[ -z ${
password} ]]; then
password=""
fi
nacosAddr=$host:$port
contentType="content-type:application/json;charset=UTF-8"
echo "set nacosAddr=$nacosAddr"
echo "set group=$group"
failCount=0
tempLog=$(mktemp -u)
function addConfig() {
curl -X POST -H "${
contentType}" "http://$nacosAddr/nacos/v1/cs/configs?dataId=$(urlencode $1)&group=$group&content=$(urlencode $2)&tenant=$tenant&username=$username&password=$password" >"${
tempLog}" 2>/dev/null
if [[ -z $(cat "${
tempLog}") ]]; then
echo " Please check the cluster status. "
exit 1
fi
if [[ $(cat "${
tempLog}") =~ "true" ]]; then
echo "Set $1=$2 successfully "
else
echo "Set $1=$2 failure "
(( failCount++ ))
fi
}
count=0
for line in $(cat $(dirname "$PWD")/config.txt | sed s/[[:space:]]//g); do
(( count++ ))
key=${
line%%=*}
value=${
line#*=}
addConfig "${
key}" "${
value}"
done
echo "========================================================================="
echo " Complete initialization parameters, total-count:$count , failure-count:$failCount "
echo "========================================================================="
if [[ ${
failCount} -eq 0 ]]; then
echo " Init nacos config finished, please start seata-server. "
else
echo " init nacos config fail. "
fi
运行
1 | docker-compose -f fileName.yaml up -d |
作者声明
1 | 如有问题,欢迎指正! |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 jhj-coding!
评论