1. 運(yùn)行nacos容器
docker run -d --name nacos -e MODE=standalone -p 8848:8848 nacos/nacos-server:1.4.0
2. 運(yùn)行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. 修改配置文件注冊進(jìn)nacos邓了,配置文件位置: ~/seata-config/registry.conf。若指定命名空間則配置文件進(jìn)行相應(yīng)調(diào)整,注意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源碼庫弄來兩個(gè)文件捐川,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. 執(zhí)行 .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服務(wù)端综看,建立seata庫,運(yùn)行sql
https://github.com/seata/seata/blob/develop/script/server/db/mysql.sql
12. 運(yùn)行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服務(wù)列表
本案例操作系統(tǒng)為Ubuntu20.04岖食,nacos為單例模式红碑,未使用mysql進(jìn)行持久化,集群及mysql使用詳見官網(wǎng)
https://nacos.io/zh-cn/docs/quick-start-docker.html