文章目录
- 一:拉取Seata镜像
- 二:运行Seata容器
- 2.1. 容器内目录拷贝到宿主机
- 2.2. 编辑 registry.conf 和 file.conf
- 2. 2.1. 编辑注册中心相关文件
- 2.2.2. 编辑Seata存储数据的相关配置文件
- 2.3. 宿主机文件拷贝至容器内部
- 三:Nacos注册中心相关配置操作
- 3.1 配置 seataServer.properties
- 3.2 重启seata服务 - > 看是否注入seata
- 3.3 没有注入 - > 进入容器查看配置文件
- 3.4 重启服务或刷新,在此查看,成功
一:拉取Seata镜像
docker pull seataio/seata-server:1.4.2
二:运行Seata容器
docker run -d --name seata-server -p 8091:8091 seataio/seata-server:1.4.2
2.1. 容器内目录拷贝到宿主机
docker cp seata-server:/seata-server /usr/local/home/docker/seata
2.2. 编辑 registry.conf 和 file.conf
[root@master01 resources]# pwd
/usr/local/home/docker/seata/seata-server/resources
[root@master01 resources]# ll
总用量 24
-rw-r--r-- 1 root root 1869 12月 23 01:53 file.conf
-rw-r--r-- 1 root root 3112 1月 1 1970 file.conf.example
drwxr-xr-x 3 root root 19 1月 1 1970 io
drwxr-xr-x 2 root root 114 1月 1 1970 logback
-rw-r--r-- 1 root root 2222 1月 1 1970 logback.xml
drwxr-xr-x 3 root root 22 1月 1 1970 META-INF
-rw-r--r-- 1 root root 1324 1月 1 1970 README.md
-rw-r--r-- 1 root root 1327 1月 1 1970 README-zh.md
-rw-r--r-- 1 root root 1982 12月 23 03:18 registry.conf
2. 2.1. 编辑注册中心相关文件
vim registry.conf
registry {
type = "nacos"
nacos {
# 应用名
application = "seata-server"
# nacos ip 地址
serverAddr = "101.****:8848"
# nacos创建的分组
group = "SEATA_GROUP"
# nacos 创建的命名空间名
namespace = "seata-naming"
cluster = "default"
# nacos登录的账号和密码
username = "nacos"
password = "nacos"
}
config {
# file、nacos 、apollo、zk、consul、etcd3
type = "nacos"
nacos {
# nacos ip 地址
serverAddr = "101.****:8848"
# nacos 创建的命名空间名
namespace = "seata-naming"
# nacos创建的分组
group = "SEATA_GROUP"
# nacos登录的账号和密码
username = "nacos"
password = "nacos"
# nacos配置相当于主键id,唯一标识配置
dataId = "seataServer.properties"
}
file {
name = "file.conf"
}
}
2.2.2. 编辑Seata存储数据的相关配置文件
vim file.conf;
这里面连接的库就是上面执行脚本的库;
## 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.cn.jdbc.Driver"
## if using mysql to store the data, recommend add rewriteBatchedStatements=true in jdbc connection param
url = "jdbc:mysql://182.****:3307/seata-config"
user = "****"
password = "****"
minConn = 5
maxConn = 100
globalTable = "global_table"
branchTable = "branch_table"
lockTable = "lock_table"
queryLimit = 100
maxWait = 5000
}
}
刚刚修改的是宿主机文件,但需注意即使是挂载目录进入容器相关修改的配置文件也不会生效
2.3. 宿主机文件拷贝至容器内部
docker cp /usr/local/home/docker/seata/seata-server/resources/registry.conf 16920a0fb6a5:/seata-server/resources/registry.conf
docker cp /usr/local/home/docker/seata/seata-server/resources/file.conf 16920a0fb6a5:/seata-server/resources/file.conf
三:Nacos注册中心相关配置操作
3.1 配置 seataServer.properties
填写:Data Id = seataServer.properties
GROUP = SEATA_GROUP
配置内容为:
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=false
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
service.vgroupMapping.storage-service-group=default
service.vgroupMapping.order-service-group=default
service.vgroupMapping.account-service-group=default
service.default.grouplist=192.168.23.3:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
store.mode=db
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://192.168.56.104:3306/seata-config?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=123456
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
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
3.2 重启seata服务 - > 看是否注入seata
3.3 没有注入 - > 进入容器查看配置文件
已经生效
[root@master01 resources]# docker exec -it 4d0f7460795d sh
/seata-server # ls
classes libs resources sessionStore
/seata-server # cd resources/
/seata-server/resources # ls
META-INF README.md file.conf.example logback registry.conf
README-zh.md file.conf io logback.xml
/seata-server/resources # vi registry.conf