1. 运行nacos容器
docker run -d --name nacos -e MODE=standalone -p 8848:8848 nacos/nacos-server:1.4.0
2. 运行seata容器
docker run -d --name seata -p 8091:8091 seataio/seata-server:1.4.0
3. copy配置文件
mkdir ~/seata-config
docker cp seata:/seata-server/resources ~/seata-config
4. 删除容器
docker rm -f seata
5. 修改配置文件注册进nacos,配置文件位置: ~/seata-config/registry.conf。若指定命名空间则配置文件进行相应调整,注意namespace的值为命名空间ID
registry {
type = "nacos"
loadBalance = "RandomLoadBalance"
loadBalanceVirtualNodes = 10
nacos {
application = "seata-server"
# 写自己的ip:port
serverAddr = "localhost:8848"
group = "SEATA_GROUP"
# 这里替换自己的namespace ID
namespace = "seata"
username = "nacos"
password = "nacos"
}
}
config {
type = "nacos"
nacos {
serverAddr = "localhost:8848"
namespace = "seata"
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
}
}
6. 到github的seata源码库弄来两个文件,config.txt 、nacos/nacos-config.sh
https://github.com/seata/seata/tree/develop/script/config-center
7. 配置文件位置如下
/root/seata-config/nacos-seata/config.txt
/root/seata-config/nacos-seata/nacos/nacos-config.sh
8. 修改config.txt
# 这里值随意,但需与客户端保持一致
service.vgroupMapping.my_test_tx_group=fps_tx_group
store.db.driverClassName=com.mysql.cj.jdbc.Driver
# 这里替换自己的mysql地址
store.db.url=jdbc:mysql://localhost:3306/seata?characterEncoding=utf8&useSSL=false&serverTimezone=UTC
store.db.user=root
store.db.password=root
9. 执行 .sh 文件,将seata配置推送到nacos
cd /root/seata-config/nacos-seata/nacos
bash nacos-config.sh -h localhost -p 8848 -g SEATA_GROUP -t seata -u nacos -w nacos
10. nacos配置列表
11. seata服务端,建立seata库,运行sql
https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql
12. 运行seata容器并将配置文件挂载出来
# 这里替换自己的ip
docker run -d --name seata -p 8091:8091 -e SEATA_IP=127.0.0.1 -e SEATA_CONFIG_NAME=file:/seata-server/resources/registry -v ~/seata-config:/seata-server/resources seataio/seata-server:1.4.0
13. 查看seata容器日志
docker logs -f seata
14. nacos服务列表
本案例操作系统为Ubuntu20.04,nacos为单例模式,未使用mysql进行持久化,集群及mysql使用详见官网
https://nacos.io/zh-cn/docs/quick-start-docker.html