【Easylive】seataServer.properties 配置文件详细解析
【Easylive】项目常见问题解答(自用&持续更新中…) 汇总版
以下是针对你提供的 seataServer.properties
配置文件的详细解析和优化建议,结合你的 easylive-cloud
微服务架构:
以下是针对 Seata配置文件在Nacos注册中心的作用 和 seataServer.properties
文件本身作用 的详细解析,结合你的实际配置:
在Nacos中配置seataServer.properties
的作用
-
集中化管理配置
• 动态生效:所有Seata客户端(TM/RM)从Nacos读取配置,无需重启服务即可调整参数(如超时时间、重试次数)。• 一致性保证:避免每个微服务本地配置不一致导致的事务协调问题。
-
与Seata Server的关联
• 服务发现:Seata客户端通过Nacos找到Seata Server(TC)的地址(如service.default.grouplist=127.0.0.1:8091
)。• 配置共享:Seata Server的存储模式(如
store.mode=db
)、事务分组规则(如service.vgroupMapping
)对所有客户端生效。 -
典型场景示例
• 修改事务超时时间:在Nacos中更新
client.tm.defaultGlobalTransactionTimeout=120000
,所有微服务立即生效。
• 切换存储模式:将
store.mode
从file
改为db
,Seata Server自动切换持久化方式。
1. 核心配置分类说明
(1) 网络通信配置(Transport)
transport.type=TCP # 使用TCP协议
transport.server=NIO # 服务端使用NIO模型
transport.heartbeat=true # 启用心跳检测
transport.serialization=seata # 使用Seata自有序列化协议
作用:控制Seata Server与客户端的通信方式,保持默认即可。
(2) 事务分组与路由
service.vgroupMapping.default_tx_group=default # 事务组映射到Seata集群
service.default.grouplist=127.0.0.1:8091 # 直连模式下的TC地址
问题:
• 你的微服务中配置的是 easylive_tx_group
,但此处映射的是 default_tx_group
,需保持一致。
修正:
service.vgroupMapping.easylive_tx_group=default
(3) 客户端(RM/TM)配置
client.rm.lock.retryTimes=30 # 分支事务锁重试次数
client.tm.commitRetryCount=5 # 全局事务提交重试次数
client.undo.logTable=undo_log # 指定undo_log表名
关键项:
• client.undo.dataValidation=true
:开启undo日志数据校验,建议生产环境开启。
• client.rm.tableMetaCheckEnable=true
:开启表元数据检查,避免字段不一致导致回滚失败。
(4) 存储模式(核心配置)
store.mode=db # 使用数据库存储事务日志
store.db.url=jdbc:mysql://127.0.0.1:3306/easylive
store.db.user=root
store.db.password=root
store.db.globalTable=global_table # Seata Server持久化表
必须检查:
-
数据库需提前创建三张表:
•global_table
(全局事务表)•
branch_table
(分支事务表)•
lock_table
(全局锁表) -
确保JDBC驱动类正确(MySQL 8+需用
com.mysql.cj.jdbc.Driver
)。
(5) 高可用与重试机制
server.recovery.committingRetryPeriod=1000 # 已提交事务的重试间隔(ms)
server.maxCommitRetryTimeout=-1 # 提交重试无超时限制
生产建议:
• 设置合理的超时时间(如 server.maxCommitRetryTimeout=60000
),避免无限重试。
2. 关键优化建议
(1) 数据库连接池调整
store.db.minConn=5 # 最小连接数(建议≥10)
store.db.maxConn=30 # 最大连接数(根据并发量调整)
store.db.maxWait=5000 # 获取连接超时时间(ms)
场景适配:
• 高并发场景下,增大 maxConn
(如100)并配合连接池监控。
(2) TCC模式配置
tcc.fence.logTableName=tcc_fence_log # TCC防悬挂日志表
tcc.fence.cleanPeriod=1h # 日志清理间隔
使用条件:
• 仅在业务中使用TCC事务模式时需创建此表。
(3) 安全增强
# store.publicKey= # 启用密码加密时配置
store.db.password=加密后的密码 # 建议生产环境使用加密密码
3. 完整配置表示例(关键部分)
# 事务组映射(与客户端一致)
service.vgroupMapping.easylive_tx_group=default# 数据库存储配置
store.mode=db
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?useSSL=false&serverTimezone=UTC
store.db.user=seata_user
store.db.password=加密密码
store.db.minConn=10
store.db.maxConn=100# 客户端事务控制
client.rm.lock.retryTimes=30
client.tm.defaultGlobalTransactionTimeout=60000
client.undo.dataValidation=true
4. 验证与排查
-
检查表结构
• 确保global_table
、branch_table
、lock_table
已创建(SQL脚本在Seata发布包的script/server/db
目录)。 -
日志监控
• 查看Seata Server日志(logs/seata_gc.log
),确认无Could not get JDBC Connection
等数据库连接错误。 -
客户端与服务端版本匹配
• 确保所有微服务引入的Seata客户端版本与Server一致(如1.6.1)。
总结
• 核心原则:服务端与客户端的事务组名(vgroupMapping
)必须一致。
• 存储模式:生产环境推荐 db
模式,需提前初始化数据库表。
• 性能调优:根据并发量调整连接池参数和重试策略。
配置完成后,通过故意触发分布式事务失败,观察
undo_log
和global_table
的变化,验证回滚是否生效。
seataServer.properties
#For details about configuration items, see https://seata.io/zh-cn/docs/user/configurations.html
#Transport configuration, for client and server
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableTmClientBatchSendRequest=false
transport.enableRmClientBatchSendRequest=true
transport.enableTcServerBatchSendResponse=false
transport.rpcRmRequestTimeout=30000
transport.rpcTmRequestTimeout=30000
transport.rpcTcRequestTimeout=30000
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#Transaction routing rules configuration, only for the client
service.vgroupMapping.default_tx_group=default
#If you use a registry, you can ignore it
service.default.grouplist=127.0.0.1:8091
service.enableDegrade=false
service.disableGlobalTransaction=false#Transaction rule configuration, only for the client
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=true
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
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
#For TCC transaction mode
tcc.fence.logTableName=tcc_fence_log
tcc.fence.cleanPeriod=1h#Log rule configuration, for client and server
log.exceptionRate=100#Transaction storage configuration, only for the server. The file, db, and redis configuration values are optional.
store.mode=db
store.lock.mode=db
store.session.mode=db
#Used for password encryption
#store.publicKey=#If `store.mode,store.lock.mode,store.session.mode` are not equal to `file`, you can remove the configuration block.#These configurations are required if the `store mode` is `db`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `db`, you can remove the configuration block.
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/easylive?useSSL=false&&serverTimezone=GMT%2B8&useInformationSchema=true
store.db.user=root
store.db.password=root
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#These configurations are required if the `store mode` is `redis`. If `store.mode,store.lock.mode,store.session.mode` are not equal to `redis`, you can remove the configuration block.#Transaction rule configuration, only for the server
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.xaerNotaRetryTimeout=60000
server.session.branchAsyncQueueSize=5000
server.session.enableBranchAsyncRemove=false
server.enableParallelRequestHandle=false#Metrics configuration, only for the server
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898