下载地址:https://github.com/seata/seata/releases
安装
cd /usr/local # 下载文件拷贝到当前目录下
tar -zxvf seata-server-1.4.2.tar.gz # 解压
目录介绍
- 可执行文件
bat格式文件为windows系统启动文件
sh格式文件为linux系统启动文件
- 服务端配置文件
# 修改日志文件保存路劲:/usr/local/seata/seata-server-1.4.2/conf/logback/file-appender.xml
<!-- <property name="LOG_HOME" value="${user.home}/logs/seata"/> -->
<property name="LOG_HOME" value="/usr/local/seata/logs"/>
# 设置Seata服务的注册中心为nacos,以下相关配置需要和nacos中的相关配置保持一致
registry {
type = "nacos"
nacos {
application = "serviceSeata"
serverAddr = "*.*.*.*:8840"
group = "SpringCloudAlibaba(此处分组名称需要和相关微服务的分组名称一致,Seata服务引入是为了解决哪个微服务项目的分布式事务)"
namespace = "d50a1a79-cf7c-4b95-ae2e-d0b4096a06dc(nacos控制台中服务管理-服务列表所属的命名空间ID)"
cluster = "default"
username = "nacos账号"
password = "nacos密码"
}
}
# 设置Seata服务的配置中心为nacos,以下相关配置需要和nacos中的相关配置保持一致
# 注意:如果type = "file",则file.conf文件中的配置才会生效
config {
type = "nacos"
nacos {
serverAddr = "*.*.*.*:8840"
namespace = "d50a1a79-cf7c-4b95-ae2e-d0b4096a06dc(nacos控制台中配置管理-配置列表所属的命名空间ID)"
group = "SpringCloudAlibaba(此处分组名称需要和相关微服务的分组名称一致,Seata服务引入是为了解决哪个微服务项目的分布式事务)"
dataId = "seata.properties(自定义Seata服务的配置文件的Data Id)"
username = "nacos账号"
password = "nacos密码"
}
}
上传配置至Nacos配置中心
从v1.4.2版本开始,已支持从一个Nacos dataId中获取所有配置信息,需要在nacos新建配置(dataId为seata.properties)
内容参考https://github.com/seata/seata/tree/develop/script/config-center的config.txt并按需修改保存
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
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
transport.serialization=seata
transport.compressor=none
#
# 服务端
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
server.distributedLockExpireTime=10000
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
#
# 客户端
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.rm.sagaJsonParser=fastjson
client.rm.tccActionInterceptorOrder=-2147482648
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
client.tm.interceptorOrder=-2147482648
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
#
# 服务端事务会话信息存储方式,file本地文件(不支持HA)、db数据库|redis(支持HA)
store.lock.mode=file
store.session.mode=file
store.publicKey=
store.mode=db
# file
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
# db
store.db.datasource=druid
store.db.dbType=mysql
# MySQL8.x 需要将 com.mysql.jdbc.Driver 修改为 com.mysql.cj.jdbc.Driver
# 当前1.4版本使用mysql8连接驱动时,事务回滚时会报错,建议1.5版本以后使用mysql8.0连接驱动
store.db.driverClassName=com.mysql.jdbc.Driver
store.db.url=jdbc:mysql://1.116.1.203:3306/seata?useUnicode=true&rewriteBatchedStatements=true
store.db.user=****
store.db.password=****
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
# redis
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
#
# log
log.exceptionRate=100
#
# metrics
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
#
# tcc
tcc.fence.logTableName=tcc_fence_log
tcc.fence.cleanPeriod=1h
#
# service
# service.vgroupMapping.serviceUser=default中的
# serviceUser需要与对应微服务中bootstrap.yml配置的seata.tx-service-group值一致
# default需要与Seata服务registry.conf配置文件中的cluster值一致
service.vgroupMapping.serviceUser=default
# service.default.grouplist=ip:port为访问seata服务器的地址和端口(仅注册中心为file时使用),8091是默认端口,也可以修改启动端口
# service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
初始化数据库表结构(mysql版本)
- 创建数据库实例
CREATE DATABASE seata default character set utf8 collate utf8_general_ci; # 基于seata的数据库实例对象
GRANT ALL PRIVILEGES on seata.* to 'lixing'@'%'; # 为用户lixing赋予操作数据库实例seata的权限
FLUSH PRIVILEGES; # 刷新权限列表
- 创建服务端 global_table、branch_table、lock_table 表
-- -------------------------------- The script used when storeMode is 'db' --------------------------------
-- the table to store GlobalSession data
CREATE 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 = InnoDB
DEFAULT CHARSET = utf8;
--
-- the table to store BranchSession data
CREATE 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 = InnoDB
DEFAULT CHARSET = utf8;
--
-- the table to store lock data
CREATE 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 = InnoDB
DEFAULT CHARSET = utf8;
- 创建客户端(即每个微服务) undo_log 表(涉及到分布式事务的微服务的数据库实例都要创建)
-- for AT mode you must to init this sql for you business database. the seata server not need it.
CREATE TABLE `undo_log` (
`branch_id` bigint NOT NULL COMMENT '分支事务id',
`xid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '全局事务id',
`context` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '撤消日志上下文',
`rollback_info` longblob NOT NULL COMMENT '回滚信息',
`log_status` int NOT NULL COMMENT '0:正常状态,1:防御状态',
`log_created` datetime NOT NULL COMMENT '创建时间',
`log_modified` datetime NOT NULL COMMENT '修改时间',
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='AT transaction mode undo table';
启动
开启端口:点我
# 后台运行的方式启动
nohup sh /usr/local/seata/seata-server-1.4.2/bin/seata-server.sh -h 192.168.233.134 -p 8091 >/dev/null 2>&1 &