Docker安装Seata分布式事务
【摘要】 1、简介 之前已经对分布式事务Seata做了详细介绍,可参考: 分布式事务解决方案:Spring Cloud + Nacos + Seata整合 接下来直接上手,Docker安装部署Seata。 2、下载镜像docker pull seataio/seata-server:1.4.2 3、启动容器docker run -d --name seata-server -p 8091...
1、简介
之前已经对分布式事务Seata做了详细介绍,可参考:
分布式事务解决方案:Spring Cloud + Nacos + Seata整合
接下来直接上手,Docker安装部署Seata。
2、下载镜像
docker pull seataio/seata-server:1.4.2
3、启动容器
docker run -d --name seata-server -p 8091:8091 seataio/seata-server:1.4.2
4、拷贝文件
docker cp seata-server:/seata-server /docker-data/seata
5、修改配置文件
(1)修改配置文件/docker-data/seata/resources/registry.conf,改为Nacos信息。
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "nacos"
nacos {
application = "seata-server"
serverAddr = "127.0.0.1:8848"
group = "SEATA_GROUP"
namespace = ""
cluster = "default"
username = "nacos"
password = "nacos"
}
......
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
serverAddr = "127.0.0.1:8848"
namespace = ""
group = "SEATA_GROUP"
username = "nacos"
password = "nacos"
dataId = "seataServer.properties"
}
}
(2)修改配置文件/docker-data/seata/resources/file.conf,改为DB信息。
## transaction log store, only used in seata-server
store {
## store mode: file、db、redis
mode = "db"
......
## database store property
db {
## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp)/HikariDataSource(hikari) etc.
datasource = "druid"
## mysql/oracle/postgresql/h2/oceanbase etc.
dbType = "mysql"
driverClassName = "com.mysql.cj.jdbc.Driver"
## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
url = "jdbc:mysql://localhost:3306/seata?rewriteBatchedStatements=true"
user = "root"
password = "root"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
......
}
6、停掉旧容器
docker stop seata-server
docker rm seata-server
7、启动新容器
docker run -d \
--restart always \
--name seata-server \
-p 8091:8091 \
-v /docker-data/seata:/seata-server \
-e SEATA_IP=外网IP \
-e SEATA_PORT=8091 \
seataio/seata-server:1.4.2
注意: 遇到的坑,如果是部署云服务器,没有设置SEATA_IP,默认注册的是docker的内网ip,seata启动虽然没有问题,但是微服务项目启动连接时,会报错can not register RM,err:can not connect to services-server.
8、查看Nacos注册情况
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)