一、seata是什么
Seata 是一款开源的分布式事务解决方案,致力于在微服务架构下提供高性能和简单易用的分布式事务服务。Seata将为
用户提供了AT,TCC,SAGA和XA事务模式,为用户打造一站式的分布式解决方案。AT模式是阿里首推
的模式,阿里云上有商用版本的GTS(Global Transaction Service全局事务服务)
二、环境搭建
1、下载服务端包,用的版本要跟alibaba对应
Seata Version 1.3.0
https://seata.io/zh-cn/docs/ops/deploy-guide-beginner
https://github.com/seata/seata/releases
https://github.com/seata/seata/releases/tag/v1.3.0
这边就直接用window环境来体验了:seata-server-1.3.0.zip
2、配置
1、建表
https://github.com/seata/seata/tree/master/script/server/db
mysql.sql
create dabase seata;
再执行表
2、修改启动模式
修改: seata—>conf—>file.conf,修改store.mode=”db或者redis”
这里改为db
4、修改注册中心和配置中心
nacos环境搭建参考:一、springCloudAlibaba-nacos环境搭建
修改:seata—>conf—>registry.conf
将注册中心和配置中心的类型都改为nacos
type = "nacos"
5、配置中心配置
下载对应版本的script
https://github.com/seata/seata/tree/1.3.0
这里用的是1.3版本,贼麻烦,配置中心注册后也贼恶心的配置文件结构,不过听说新版优化了。
解压获得script后放到seata的目录下,当然不放也可以
修改:script—>config-center—>config.txt
修改如下地方
模式改为db
store.mode=db
还有对应的数据库配置。
事务分组:异地机房停电容错机制,这里写成guangzhou
service.vgroupMapping.guangzhou=default
这里配置后到时候client也要对应配置
配置到配置中心,1.3.0版本贼恶心,需要执行对应的脚本配置,这里执行的是sh脚本
script—>config-center—>nacos—>nacos-config.sh
我这里是先打开Git Bash Here,然后执行sh nacos-config.sh

Git的安装自行百度
执行完后登录nacos可以看到
这是什么奇葩设定,每一行一个配置文件?
版本低也是原罪,没办法,为了跟我这套学习笔记对应的alibaba的版本对应。
3、启动
进入cmd,进行seata的启动
seata-server.bat -p 8092
然后再启动个
seata-server.bat -p 8091
可以看到nacos控制台有集群了
真的一点都不优雅啊!
三、1.3.0版本对应的配置
sql脚本
-- -------------------------------- The script used when storeMode is 'db' ---------------------------------- the table to store GlobalSession dataCREATE TABLE IF NOT EXISTS `global_table`(`xid` VARCHAR(128) NOT NULL,`transaction_id` BIGINT,`status` TINYINT NOT NULL,`application_id` VARCHAR(32),`transaction_service_group` VARCHAR(32),`transaction_name` VARCHAR(128),`timeout` INT,`begin_time` BIGINT,`application_data` VARCHAR(2000),`gmt_create` DATETIME,`gmt_modified` DATETIME,PRIMARY KEY (`xid`),KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),KEY `idx_transaction_id` (`transaction_id`)) ENGINE = InnoDBDEFAULT CHARSET = utf8;-- the table to store BranchSession dataCREATE TABLE IF NOT EXISTS `branch_table`(`branch_id` BIGINT NOT NULL,`xid` VARCHAR(128) NOT NULL,`transaction_id` BIGINT,`resource_group_id` VARCHAR(32),`resource_id` VARCHAR(256),`branch_type` VARCHAR(8),`status` TINYINT,`client_id` VARCHAR(64),`application_data` VARCHAR(2000),`gmt_create` DATETIME(6),`gmt_modified` DATETIME(6),PRIMARY KEY (`branch_id`),KEY `idx_xid` (`xid`)) ENGINE = InnoDBDEFAULT CHARSET = utf8;-- the table to store lock dataCREATE TABLE IF NOT EXISTS `lock_table`(`row_key` VARCHAR(128) NOT NULL,`xid` VARCHAR(96),`transaction_id` BIGINT,`branch_id` BIGINT NOT NULL,`resource_id` VARCHAR(256),`table_name` VARCHAR(32),`pk` VARCHAR(36),`gmt_create` DATETIME,`gmt_modified` DATETIME,PRIMARY KEY (`row_key`),KEY `idx_branch_id` (`branch_id`)) ENGINE = InnoDBDEFAULT CHARSET = utf8;
config.xml
下面是我修改后的
transport.type=TCPtransport.server=NIOtransport.heartbeat=truetransport.enableClientBatchSendRequest=falsetransport.threadFactory.bossThreadPrefix=NettyBosstransport.threadFactory.workerThreadPrefix=NettyServerNIOWorkertransport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandlertransport.threadFactory.shareBossWorker=falsetransport.threadFactory.clientSelectorThreadPrefix=NettyClientSelectortransport.threadFactory.clientSelectorThreadSize=1transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThreadtransport.threadFactory.bossThreadSize=1transport.threadFactory.workerThreadSize=defaulttransport.shutdown.wait=3service.vgroupMapping.guangzhou=defaultservice.default.grouplist=127.0.0.1:8091service.enableDegrade=falseservice.disableGlobalTransaction=falseclient.rm.asyncCommitBufferLimit=10000client.rm.lock.retryInterval=10client.rm.lock.retryTimes=30client.rm.lock.retryPolicyBranchRollbackOnConflict=trueclient.rm.reportRetryCount=5client.rm.tableMetaCheckEnable=falseclient.rm.sqlParserType=druidclient.rm.reportSuccessEnable=falseclient.rm.sagaBranchRegisterEnable=falseclient.tm.commitRetryCount=5client.tm.rollbackRetryCount=5client.tm.degradeCheck=falseclient.tm.degradeCheckAllowTimes=10client.tm.degradeCheckPeriod=2000store.mode=dbstore.file.dir=file_store/datastore.file.maxBranchSessionSize=16384store.file.maxGlobalSessionSize=512store.file.fileWriteBufferCacheSize=16384store.file.flushDiskMode=asyncstore.file.sessionReloadReadSize=100store.db.datasource=druidstore.db.dbType=mysqlstore.db.driverClassName=com.mysql.jdbc.Driverstore.db.url=jdbc:mysql://192.168.192.19:3309/seata?useUnicode=truestore.db.user=rootstore.db.password=123456store.db.minConn=5store.db.maxConn=30store.db.globalTable=global_tablestore.db.branchTable=branch_tablestore.db.queryLimit=100store.db.lockTable=lock_tablestore.db.maxWait=5000store.redis.host=127.0.0.1store.redis.port=6379store.redis.maxConn=10store.redis.minConn=1store.redis.database=0store.redis.password=nullstore.redis.queryLimit=100server.recovery.committingRetryPeriod=1000server.recovery.asynCommittingRetryPeriod=1000server.recovery.rollbackingRetryPeriod=1000server.recovery.timeoutRetryPeriod=1000server.maxCommitRetryTimeout=-1server.maxRollbackRetryTimeout=-1server.rollbackRetryTimeoutUnlockEnable=falseclient.undo.dataValidation=trueclient.undo.logSerialization=jacksonclient.undo.onlyCareUpdateColumns=trueserver.undo.logSaveDays=7server.undo.logDeletePeriod=86400000client.undo.logTable=undo_logclient.log.exceptionRate=100transport.serialization=seatatransport.compressor=nonemetrics.enabled=falsemetrics.registryType=compactmetrics.exporterList=prometheusmetrics.exporterPrometheusPort=9898
