Seata(1.4.2)环境搭建-SpringCloudAlibaba微服务

SEATA官方文档:https://seata.io/zh-cn/docs/overview/what-is-seata.html

 一、seata-server 的安装配置

 1、下载seata-server:

        访问seata官方文档地址>下载>1.4.2>binary 以及 source

2、seata-server-1.4.2.tar.gz上传至服务器,并解压至/home/data/seata-server-1.4.2

tar -zxvf seata-server-1.4.2.tar.gz -C /home/data/seata-server-1.4.2/

3、 解压seata-1.4.2.zip文件,并将script目录复制到seata-server-1.4.2目录中

seata-1.4.2/script目录为配置文件脚本以及seata_server数据库表脚本等信息

4、创建seata数据库

创建cloud-seata数据库,并执行 script\server\db\mysql.sql 数据库脚本

5、修改conf/file.conf文件

修改 mode = "db" 并配置db对应数据源信息

store {
  ## store mode: file、db、redis
  mode = "db"
  ## rsa decryption public key
  publicKey = ""

  ## 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://192.168.2.1: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、修改conf/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"
  }
}

7、修改配置信息script/config-center/config.txt

修改数据源配置,与 file.conf 配置文件的数据源配置一致。

# 事务分组:my_test_tx_group 自定事务分组名称,客户端配置访问事务分组需要与此处名称一致,此处的 default 和客户端配置文件中的注册中心的 cluster 一致
service.vgroupMapping.my_test_tx_group=default
service.default.grouplist=127.0.0.1:8091
# 修改存储模式
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.2.60:3306/cloud-seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=Root@123

8、将配置信息发布到 nacos 配置中心

执行script/config-center/nacos/nacos-config.sh 文件

sh script/config-center/nacos/nacos-config.sh -h 192.168.2.60 -p 8848 -g SEATA_GROUP -t '' -u nacos -w nacos

(linux环境下直接启动,windows环境下可以使用git启动),启动就能将"script/config-center/config.txt"配置信息发布到 nacos 配置中心。配置发布命令如下:

cd script/config-center/nacos/
sh nacos-config.sh -h 192.168.2.60 -p 8848 -g SEATA_GROUP -t '' -u nacos -w nacos

执行后如下:


set group=SEATA_GROUP
Set transport.type=TCP successfully 
Set transport.server=NIO successfully 
Set transport.heartbeat=true successfully 
Set transport.enableClientBatchSendRequest=false successfully 
Set transport.threadFactory.bossThreadPrefix=NettyBoss successfully 
Set transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker successfully 
Set transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler successfully 
Set transport.threadFactory.shareBossWorker=false successfully 
Set transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector successfully 
Set transport.threadFactory.clientSelectorThreadSize=1 successfully 
Set transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread successfully 
Set transport.threadFactory.bossThreadSize=1 successfully 
Set transport.threadFactory.workerThreadSize=default successfully 
Set transport.shutdown.wait=3 successfully 
Set service.vgroupMapping.my_test_tx_group=default successfully 
Set service.default.grouplist=127.0.0.1:8091 successfully 
Set service.enableDegrade=false successfully 
Set service.disableGlobalTransaction=false successfully 
Set client.rm.asyncCommitBufferLimit=10000 successfully 
Set client.rm.lock.retryInterval=10 successfully 
Set client.rm.lock.retryTimes=30 successfully 
Set client.rm.lock.retryPolicyBranchRollbackOnConflict=true successfully 
Set client.rm.reportRetryCount=5 successfully 
Set client.rm.tableMetaCheckEnable=false successfully 
Set client.rm.tableMetaCheckerInterval=60000 successfully 
Set client.rm.sqlParserType=druid successfully 
Set client.rm.reportSuccessEnable=false successfully 
Set client.rm.sagaBranchRegisterEnable=false successfully 
Set client.tm.commitRetryCount=5 successfully 
Set client.tm.rollbackRetryCount=5 successfully 
Set client.tm.defaultGlobalTransactionTimeout=60000 successfully 
Set client.tm.degradeCheck=false successfully 
Set client.tm.degradeCheckAllowTimes=10 successfully 
Set client.tm.degradeCheckPeriod=2000 successfully 
Set store.mode=db successfully 
Set store.publicKey= failure 
Set store.file.dir=file_store/data successfully 
Set store.file.maxBranchSessionSize=16384 successfully 
Set store.file.maxGlobalSessionSize=512 successfully 
Set store.file.fileWriteBufferCacheSize=16384 successfully 
Set store.file.flushDiskMode=async successfully 
Set store.file.sessionReloadReadSize=100 successfully 
Set store.db.datasource=druid successfully 
Set store.db.dbType=mysql successfully 
Set store.db.driverClassName=com.mysql.cj.jdbc.Driver successfully 
Set store.db.url=jdbc:mysql://192.168.2.60:3306/seata?useUnicode=true&rewriteBatchedStatements=true successfully 
Set store.db.user=root successfully 
Set store.db.password=Root@123 successfully 
Set store.db.minConn=5 successfully 
Set store.db.maxConn=30 successfully 
Set store.db.globalTable=global_table successfully 
Set store.db.branchTable=branch_table successfully 
Set store.db.queryLimit=100 successfully 
Set store.db.lockTable=lock_table successfully 
Set store.db.maxWait=5000 successfully 
Set store.redis.mode=single successfully 
Set store.redis.single.host=127.0.0.1 successfully 
Set store.redis.single.port=6379 successfully 
Set store.redis.sentinel.masterName= failure 
Set store.redis.sentinel.sentinelHosts= failure 
Set store.redis.maxConn=10 successfully 
Set store.redis.minConn=1 successfully 
Set store.redis.maxTotal=100 successfully 
Set store.redis.database=0 successfully 
Set store.redis.password= failure 
Set store.redis.queryLimit=100 successfully 
Set server.recovery.committingRetryPeriod=1000 successfully 
Set server.recovery.asynCommittingRetryPeriod=1000 successfully 
Set server.recovery.rollbackingRetryPeriod=1000 successfully 
Set server.recovery.timeoutRetryPeriod=1000 successfully 
Set server.maxCommitRetryTimeout=-1 successfully 
Set server.maxRollbackRetryTimeout=-1 successfully 
Set server.rollbackRetryTimeoutUnlockEnable=false successfully 
Set client.undo.dataValidation=true successfully 
Set client.undo.logSerialization=jackson successfully 
Set client.undo.onlyCareUpdateColumns=true successfully 
Set server.undo.logSaveDays=7 successfully 
Set server.undo.logDeletePeriod=86400000 successfully 
Set client.undo.logTable=undo_log successfully 
Set client.undo.compress.enable=true successfully 
Set client.undo.compress.type=zip successfully 
Set client.undo.compress.threshold=64k successfully 
Set log.exceptionRate=100 successfully 
Set transport.serialization=seata successfully 
Set transport.compressor=none successfully 
Set metrics.enabled=false successfully 
Set metrics.registryType=compact successfully 
Set metrics.exporterList=prometheus successfully 
Set metrics.exporterPrometheusPort=9898 successfully 
=========================================================================
 Complete initialization parameters,  total-count:89 ,  failure-count:4 
=========================================================================
 init nacos config fail. 
[root@localhost nacos]# 

在nacos配置中心出现如下配置信息

 9、启动seata服务

sh bin/seata-server.sh -h localhost -p 8091 -m db -n 1 -e dev

dev可配置多环境

[root@localhost seata-server-1.4.2]# cd bin
[root@localhost bin]# sh seata-server.sh -h localhost -p 8091 -m db -n 1

默认启动后窗口要保持开启,如果想要后台启动,则执行:

nohup sh ./seata-server.sh > ./log.log 2>&1 &

 

nohup sh ./seata-server.sh -h localhost -p 8091 -m db -n 1 > ./log.log 2>&1 &

如果启动项目链接报错时,则将localhost换为ip

0101 can not connect to 192.168.122.1:8091 cause:can not register RM,err:can not connect to services-server.

参数说明如下:

参数全写作用备注
-h –host指定注册中心注册的IP不指定获取当前的IP,外部王文部署在云环境和容器中的 server 建议指定
-p–port指定 server 启动的端口默认为8091
-m–storeMode事务日志存储方式支持file、db、redis,默认为 file ,注意 redis 需要 seata-server1.3 以上支持
-n–serverNode用于指定 seata-server 节点ID如 1、2、3…等,默认为1,这里可以配合修改端口和节点ID 来表示启动多个seata-server服务端
-e–seataEnv指定 seata-server 运行环境如 dev、test 等,服务启动时会用使用 registry-dev.conf、registry-test.conf 配置文件,默认不加 -e 参数表示启动时加载 registry.conf

 10、在各业务系统数据库中需要创建回滚日志表

回滚日志表在 seata-server 解压目录下的 script\client\at\db\mysql.sql中

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值