SpringcloudAlibaba+Nacos+Seata1.4.0分布式事务配置

seata-develop链接:https://pan.baidu.com/s/1WAMPzIwof3Z_RwfE-w6JqQ

提取码:df5n

seata-server-1.4.0链接:https://pan.baidu.com/s/1JfsvN2ir6piou3aUbZO_Ow

提取码:6lt3

官网源码地址:https://github.com/seata/seata

网上许多搭建版本趋向于老版本,故自己参考官网 http://seata.io/en-us/ 和其他搭建方法总结出一套完整说明,故记录一哈

 

环境搭建 Seata+Nacos+Springcloud Alibaba

Server配置:

..\seata\conf 目录下

配置:file.conf

SpringcloudAlibaba+Nacos+Seata1.4.0分布式事务配置_第1张图片

 

配置:registry.conf

SpringcloudAlibaba+Nacos+Seata1.4.0分布式事务配置_第2张图片

 

服务端及配置完成,接下来是创建对应数据库

..\seata-develop\script\server\db 目录下根据对应的数据库执行对应的sql文件

先创建数据库或者导入已经使用的数据库,但是需要跟file.conf配置的数据库名字对应即可

SpringcloudAlibaba+Nacos+Seata1.4.0分布式事务配置_第3张图片

 

需要在所有服务数据库下创建回滚日志表

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log`  (
  `id` bigint(0) NOT NULL AUTO_INCREMENT,
  `branch_id` bigint(0) NOT NULL,
  `xid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `context` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `rollback_info` longblob NOT NULL,
  `log_status` int(0) NOT NULL,
  `log_created` datetime(0) NOT NULL,
  `log_modified` datetime(0) NOT NULL,
  `ext` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `ux_undo_log`(`xid`, `branch_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '回滚日志表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of undo_log
-- ----------------------------

SET FOREIGN_KEY_CHECKS = 1;

启动顺序,启动naocs(nacos配置自行百度)

..\seata\bin目录下 执行

遇到问题一:执行日志路径错误

在bin同级创建log文件

seata-server.bat 

启动成功后访问localhost:8848/nacos (nacos默认端口)

 

出现上图表示配置成功

 

接下来配置客户端:

..\seata-develop\script\config-center 该目录下将nacos和config.txt复制到

..\seata\conf目录下

SpringcloudAlibaba+Nacos+Seata1.4.0分布式事务配置_第4张图片

 

然后配置复制后的config.txt

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
#修改my_test_tx_group为自定义服务seata-group
service.vgroupMapping.seata-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
#此处配置file.conf一致
store.mode=db

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.cj.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
store.db.user=root
store.db.password=123123

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.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

然后执行复制过来的nacos文件夹下面的nacos-config.sh脚本

如果启动成功则访问nacos查看配置文件,如果出现下图列表文件,即表示配置成功

SpringcloudAlibaba+Nacos+Seata1.4.0分布式事务配置_第5张图片
然后重新启动seata-server及执行bin目录启动脚本

到此相关配置已经配置完成

接下来配置项目


        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-seata
            ${spring.cloud.alibaba.system.version}
        

        
            io.seata
            seata-spring-boot-starter
            ${seata.version}
        

SpringcloudAlibaba+Nacos+Seata1.4.0分布式事务配置_第6张图片

 

网上很多需要引入文件配置才行,但是现在新增特性配置好 过后不需要引入文件

 

出现这个表示所有配置成功

使用方式:@GlobalTransactional

你可能感兴趣的:(开发问题总览,安装环境配置,java,Seata,分布式事务,微服务)