基于Docker的Seata1.4.2的Nacos2.0.3服务注册和配置管理

版本

Docker version: 20.10.7, build f0df350
Seata version: 1.4.2
Nacos version: 2.0.3
Mysql version: 8.0.25

容器制作

Docker Nacos 2.0.3容器制作并运行
Nacos 2.x需要多开两个端口 相关见Nacos 2.0.0 兼容性文档

docker run --name nacos-standalone-2.0.3 \ 
      -e MODE=standalone 
      -d 
      -p 8848:8848
      -p 9849:9849 
      -p 9848:9848 
      nacos/nacos-server:2.0.3

制作Seata Server容器之前 下载seata1.4.2的脚本及配置文件

seata 1.4.2

  • /client 是客户端有关的一些配置及脚本文件
  • /config-center 是要推送到配置中心的一些配置 这里使用nacos
  • /logstash/config 日志相关
  • /server 服务端相关的配置
    进入配置目录,向nacos推送配置 你可以先修改 本地目录/seata/script/config-center/config.txt的内容 然后再推送 也可以直接推送 后面在nacos里面改
cd 本地目录/seata/script/config-center/nacos
sh nacos-config.sh 127.0.0.1

推送完毕后可以在nacos中看到我们推送的配置


Nacos中的Seata Server配置

在本地目录中/seata/script/server/config/目录下 只保留 registry.conf 如果你喜欢yaml格式也可以只保留registry.yml
编辑registry.conf 这里注释以及用不到的配置项删除了

## https://github.com/seata/seata/blob/1.4.2/script/server/config/registry.conf
registry {
  type = "nacos"
  nacos {
    application = "seata-server"
    # 192.168.*.* macOS 可以通过 ifconfig | grep cast 查看
    serverAddr = "局域网IP:8848"
    group = "SEATA_GROUP"
    cluster = "default"
    username = "nacos"
    password = "nacos"
  }
}
config {
  type = "nacos"
  nacos {
   serverAddr = "局域网IP:8848"
   group = "SEATA_GROUP"
   username = "nacos"
   password = "nacos"
  }
}

Docker Seata Server容器制作并运行 将刚才修改的registry.conf目录挂载到容器的/root/seta-config 具体见使用 Docker 部署Seata Server 的 "使用自定义配置" 内容

docker run --name seata-server-1.4.2 \
        -d -p 8091:8091 \
        -e SEATA_CONFIG_NAME=file:/root/seata-config/registry \
        -v 本地目录/seata/script/server/config:/root/seata-config   \
        seataio/seata-server:1.4.2

其他

这是前面向nacos推送的默认配置,内容如下

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.my_test_tx_group=default
service.default.grouplist=127.0.0.1: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=file
store.publicKey=
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=username
store.db.password=password
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
store.redis.mode=single
store.redis.single.host=127.0.0.1
store.redis.single.port=6379
store.redis.sentinel.masterName=
store.redis.sentinel.sentinelHosts=
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
store.redis.password=
store.redis.queryLimit=100
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
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898

如果将配置中store.mode=file改为store.mode=db
那么同时还需要在本地的MySQL新建一个seata数据库,并在该库下执行脚本mysql.sql脚本,再修改
store.db.url=jdbc:mysql://局域网IP:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=用户名
store.db.password=密码

你可能感兴趣的:(基于Docker的Seata1.4.2的Nacos2.0.3服务注册和配置管理)