当前位置:   article > 正文

seata2.0 下载安装部署,使用nacos为配置中心、注册中心

seata2.0

目录

前言

​​​​​一、下载seata安装包

二、指定nacos为配置中心、注册中心

三、上传配置到nacos配置中心

四、创建表

五、启动seata server


前言

Seata分TC、TM和RM三个角色,TC(Server端)为单独服务端部署,TM和RM(Client端)由业务系统集成。此篇为seata Server端部署。 


​​​​​一、下载seata安装包

先在seata官网下载seata安装包

​​

压缩包解压后目录如下:

​​

config目录

​​

script目录:

​​

二、指定nacos为配置中心、注册中心

打开config/application.yml文件,我们主要关注以下几个模块的配置。

1、server端配置中心指定,seata.config.type

2、server端注册中心指定,seata.registry.type

3、server端存储模式指定,seata.store.mode

修改config/application.yml文件,指定nacos为配置中心、注册中心,并将seata.store.mode屏蔽,后续中配置中心中进行配置。

其余配置中心可参考config/application.example.yml文件。

三、上传配置到nacos配置中心

请确保后台已经启动 Nacos 服务。

首先你需要在nacos新建seata配置,此处dataId为seataServer.properties

​​

配置内容参考:

  

# socket通信方式, 公共部分

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

 

# 首先应用程序(客户端)中配置了事务分组,若应用程序是SpringBoot则通过配置seata.tx-service-group=[事务分组配置项]

# 事务群组,service.vgroupMapping.[事务分组配置项]=TC集群的名称

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

# undo配置

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

# You can choose from the following options: fastjson, jackson, gson

tcc.contextJsonParserType=fastjson

 

#Log rule configuration, for client and server

log.exceptionRate=100

 

#事务会话信息存储方式

store.mode=db

#事务锁信息存储方式

store.lock.mode=db

#事务回话信息存储方式

store.session.mode=db

#db或redis存储密码解密公钥

store.publicKey=

 

#存储方式为db

store.db.dbType=mysql

store.db.driverClassName=com.mysql.jdbc.Driver

store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true&rewriteBatchedStatements=true

store.db.user=username

store.db.password=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

 

# 事务规则配置

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.session.branchAsyncQueueSize=5000

server.session.enableBranchAsyncRemove=false

server.enableParallelRequestHandle=true

server.enableParallelHandleBranch=false

 

server.raft.cluster=127.0.0.1:7091,127.0.0.1:7092,127.0.0.1:7093

server.raft.snapshotInterval=600

server.raft.applyBatch=32

server.raft.maxAppendBufferSize=262144

server.raft.maxReplicatorInflightMsgs=256

server.raft.disruptorBufferSize=16384

server.raft.electionTimeoutMs=2000

server.raft.reporterEnabled=false

server.raft.reporterInitialDelay=60

server.raft.serialization=jackson

server.raft.compressor=none

server.raft.sync=true



 

#Metrics配置

metrics.enabled=false

metrics.registryType=compact

metrics.exporterList=prometheus

metrics.exporterPrometheusPort=9898

更多更详细的内容可参考script/config-center/config.txt

四、创建表

在上面的nacos配置文件中,已经配置了存储模型为db以及数据库连接配置,还需建表。

​建表语句在文件script/server/db/mysql.sql

  1. -- -------------------------------- The script used when storeMode is 'db' --------------------------------
  2. -- the table to store GlobalSession data
  3. CREATE TABLE IF NOT EXISTS `global_table`
  4. (
  5. `xid` VARCHAR(128) NOT NULL,
  6. `transaction_id` BIGINT,
  7. `status` TINYINT NOT NULL,
  8. `application_id` VARCHAR(32),
  9. `transaction_service_group` VARCHAR(32),
  10. `transaction_name` VARCHAR(128),
  11. `timeout` INT,
  12. `begin_time` BIGINT,
  13. `application_data` VARCHAR(2000),
  14. `gmt_create` DATETIME,
  15. `gmt_modified` DATETIME,
  16. PRIMARY KEY (`xid`),
  17. KEY `idx_status_gmt_modified` (`status` , `gmt_modified`),
  18. KEY `idx_transaction_id` (`transaction_id`)
  19. ) ENGINE = InnoDB
  20. DEFAULT CHARSET = utf8mb4;
  21. -- the table to store BranchSession data
  22. CREATE TABLE IF NOT EXISTS `branch_table`
  23. (
  24. `branch_id` BIGINT NOT NULL,
  25. `xid` VARCHAR(128) NOT NULL,
  26. `transaction_id` BIGINT,
  27. `resource_group_id` VARCHAR(32),
  28. `resource_id` VARCHAR(256),
  29. `branch_type` VARCHAR(8),
  30. `status` TINYINT,
  31. `client_id` VARCHAR(64),
  32. `application_data` VARCHAR(2000),
  33. `gmt_create` DATETIME(6),
  34. `gmt_modified` DATETIME(6),
  35. PRIMARY KEY (`branch_id`),
  36. KEY `idx_xid` (`xid`)
  37. ) ENGINE = InnoDB
  38. DEFAULT CHARSET = utf8mb4;
  39. -- the table to store lock data
  40. CREATE TABLE IF NOT EXISTS `lock_table`
  41. (
  42. `row_key` VARCHAR(128) NOT NULL,
  43. `xid` VARCHAR(128),
  44. `transaction_id` BIGINT,
  45. `branch_id` BIGINT NOT NULL,
  46. `resource_id` VARCHAR(256),
  47. `table_name` VARCHAR(32),
  48. `pk` VARCHAR(36),
  49. `status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking',
  50. `gmt_create` DATETIME,
  51. `gmt_modified` DATETIME,
  52. PRIMARY KEY (`row_key`),
  53. KEY `idx_status` (`status`),
  54. KEY `idx_branch_id` (`branch_id`),
  55. KEY `idx_xid` (`xid`)
  56. ) ENGINE = InnoDB
  57. DEFAULT CHARSET = utf8mb4;
  58. CREATE TABLE IF NOT EXISTS `distributed_lock`
  59. (
  60. `lock_key` CHAR(20) NOT NULL,
  61. `lock_value` VARCHAR(20) NOT NULL,
  62. `expire` BIGINT,
  63. primary key (`lock_key`)
  64. ) ENGINE = InnoDB
  65. DEFAULT CHARSET = utf8mb4;
  66. INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0);
  67. INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0);
  68. INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0);
  69. INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0);

五、启动seata server

支持的启动命令参数:

​​

切换到seata的bin目录,输入命令 

./seata-server.sh -h 127.0.0.1 -p 8091

​​

 可以看到提示已经启动成功,也可以到提示的日志目录查看日志文件

​​

也可以输入http://localhost:7091​​​​​​​

​​

另外在nacos也可以看到seata-server注册成功 

​​

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/387875
推荐阅读
  

闽ICP备14008679号