1、直接拉取seate1.4
docker pull seataio/seata-server:1.4.0
2、创建对应的seata文件夹,本文在/home下创建的
mkdir seata
3、先启动seata容器,把需要的挂载出来管理的文件夹cp出来
docker run --name seata-server -p 8091:8091 -d seataio/seata-server:1.4.0
docker cp seata-server:/seata-server /home/seata
4、然后停止并删除已创建容器
docker stop seata-server
docker rm seata-server
5、正式启动对应seata容器(注意:-v后/home/seata,需要改为你实际的位置,还有seata_ip地址)
docker run -d --restart always --name seata-server -p 8091:8091 -v /home/seata:/seata-server -e SEATA_IP=xxx.xxx.xxx.xxx -e SEATA_PORT=8091 seataio/seata-server:1.4.0
参数说明:
-v /home/seata:/seata-server
宿主机目录/home/seata与seata容器目录/seata-server进行挂载,数据互通-e SEATA_IP=xxx.xxx.xxx.xxx
, 指定seata-server启动的IP-e SEATA_PORT=8091
, 指定seata-server启动的端口, 默认为 8091
6、接下来我们需要对进行配置nacos为注册中心了 ,需要进入到/home/seata/resources修改registry文件
vi /home/seata/resources/registry.conf
7、注意把里面的type改为nacos,并修改nacos中对应的信息
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
loadBalance = "RandomLoadBalance"
loadBalanceVirtualNodes = 10
nacos {
application = "seata-server"
serverAddr = "xxx.xxx.xxx.xxx:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
.........
8、我们需要在/home/seata下创建一个文件夹,用来配置seata中的信息,例如数据库连接等等
touch config.txt
9、进行编辑,把下面内容修改后复制进去即可保存
vi config.txt
service.vgroupMapping.xxx-system-group=default
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://xxxxxx:3306/yd_seate?useUnicode=true
store.db.user=root
store.db.password=xxxx
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
10、然后我们需要进入/home/seata/resources下写一个shell,用于上传config.txt中的信息上去nacos中
touch nacos-config.sh
注意:创建的shell是没有不能执行的,需要设置一下文件
chmod u+x nacos-config.sh
把以下内容复制进去(不需要修改哟)
vi nacos-config.sh
#!/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
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=$1&group=$group&content=$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
11、保存后执行以下命令(注意以下-h和-u、-w参数),配置信息就上传到nacos拉
sh nacos-config.sh -h xxx.xxx.xxx.xxx -p 8848 -g SEATA_GROUP -u nacos -w nacos
12、然后重启以下docker中的seata容器,就好啦