Linux部署Seata记录(Nacos作为配置和注册中心)

Morgan思炀

SEATA

1. 版本1.2.0

2. 文档地址:http://seata.io/zh-cn/docs/ops/deploy-by-docker.html

3. 使用docker部署seata

3.1 拉取运行镜像

docker pull seataio/seata-server:1.2.0
docker run -d --name seata-server -p 8091:8091 -d  seataio/seata-server:1.2.0

3.2 使用docker cp命令,将容器中的配置文件拷贝出来。

docker cp seata-server:/seata-server/resources ~/seata-script

3.3 进入到seata-script文件夹

cd ~/seata-script

3.4 修改file.conf

vim file.conf

3.5 需要根据自己的环境修改url,user,password

## transaction log store, only used in seata-server
store {
 ## store mode: file、db
 ## 修改此处为db
 mode = "db"
​
 ## file store property
 file {
    ## store location dir
    dir = "sessionStore"
    # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
    maxBranchSessionSize = 16384
    # globe session size , if exceeded throws exceptions
    maxGlobalSessionSize = 512
    # file buffer size , if exceeded allocate new buffer
    fileWriteBufferCacheSize = 16384
    # when recover batch read size
    sessionReloadReadSize = 100
    # async, sync
    flushDiskMode = async
 }
​
 ## database store property
 db {
     ## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.
     datasource = "druid"
     ## mysql/oracle/postgresql/h2/oceanbase etc.
     dbType = "mysql"
     driverClassName = "com.mysql.jdbc.Driver"
     ## 修改为自己数据库的ip、端口和库名
     url = "jdbc:mysql://ip:port/seata_demo"
     ## 修改为自己数据库用户名
     user = "user"
     ## 修改为自己数据库密码
     password = "pass"
     minConn = 5
     maxConn = 30
     globalTable = "global_table"
     branchTable = "branch_table"
     lockTable = "lock_table"
     queryLimit = 100
     maxWait = 5000
 }
}

3.6 修改registry.conf文件

vim registry.conf
registry {
         # file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
         ## 修改为nacos,后面那些配置只要关注nacos就好,其他可以删掉
         type = "nacos"
        ​
         nacos {
             ## 注意,这里其实官网配置文件是有一个坑的,就是`nacos`的`application`配置,旧值为seata-server,我们需要修改为serverAddr
             application = "seataAddr"
             ## 修改为Nacos服务器ip地址
             serverAddr = "127.0.0.1"
             ## 修改为Nacos给Seata用的Namespace,需要上Nacos新建一个
             namespace = "seata"
             cluster = "default"
             ## 修改为Nacos的用户名
             username = "nacos"
             ## 修改为Nacos的密码
             password = "nacos"
         }
         eureka {
             serviceUrl = "http://localhost:8761/eureka"
             application = "default"
             weight = "1"
         }
         redis {
             serverAddr = "localhost:6379"
             db = 0
             password = ""
             cluster = "default"
             timeout = 0
         }
         zk {
             cluster = "default"
             serverAddr = "127.0.0.1:2181"
             sessionTimeout = 6000
             connectTimeout = 2000
             username = ""
             password = ""
         }
         consul {
             cluster = "default"
             serverAddr = "127.0.0.1:8500"
         }
         etcd3 {
             cluster = "default"
             serverAddr = "http://localhost:2379"
         }
         sofa {
             serverAddr = "127.0.0.1:9603"
             application = "default"
             region = "DEFAULT_ZONE"
             datacenter = "DefaultDataCenter"
             cluster = "default"
             group = "SEATA_GROUP"
             addressWaitTime = "3000"
         }
         file {
             name = "file.conf"
         }
        }
        ​
        config {
         # file、nacos 、apollo、zk、consul、etcd3
         ## 修改为nacos
         type = "nacos"
        ​
         ## 修改方法同上
         nacos {
             serverAddr = "127.0.0.1"
             namespace = "seata"
             group = "SEATA_GROUP"
             username = "nacos"
             password = "nacos"
         }
         consul {
             serverAddr = "127.0.0.1:8500"
         }
         apollo {
             appId = "seata-server"
             apolloMeta = "http://192.168.1.204:8801"
             namespace = "application"
         }
         zk {
             serverAddr = "127.0.0.1:2181"
             sessionTimeout = 6000
             connectTimeout = 2000
             username = ""
             password = ""
         }
         etcd3 {
             serverAddr = "http://localhost:2379"
         }
         file {
             name = "file.conf"
         }
        }

3.7 把修改好的配置文件拷贝回seata容器

docker cp registry.conf seata-server:/seata-server/resources
docker cp file.conf seata-server:/seata-server/resources

3.8 重启seata-server容器

docker restart seata-server
如果启动成功会在nacos上看到这个服务
image.png

3.9 通过脚本把配置传到nacos

3.9.1 下载源码:https://github.com/seata/seata/tree/1.2.0
3.9.2 用idea打开
3.9.3 定位到截图位置,并修改/script/config-center/config.txt配置

image.png

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
## 所有需要用到Seata的微服务名,需要跟微服务中Seata的配置一致
service.vgroupMapping.TEST-GROUP=default
service.vgroupMapping.TEST1-GROUP=default
service.vgroupMapping.TEST2-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.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
## 修改为db
store.mode=db
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
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.host=127.0.0.1
store.redis.port=6379
store.redis.maxConn=10
store.redis.minConn=1
store.redis.database=0
store.redis.password=null
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.log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
3.9.4 idea执行nacos-config.sh脚本,86行改为config.txt的路径
 for line in $(cat ../config.txt | sed s/[[:space:]]//g); do

image.png

3.9.5 idea terminal运行,如果运行成功terminal会打印出所有配置,并在nacos上seata对应的namespace也能看到这些配置
bash nacos-config.sh -h nacos的ip -p nacos的端口 -g nacos上seata的group -t nacos上seata的namespace
## 例如
bash nacos-config.sh -h 127.0.0.1 -p 8848 -g seata -t SEATA_GROUP

image.png

阅读 631
4 声望
0 粉丝
0 条评论
4 声望
0 粉丝
宣传栏