• 【环境搭建】linux docker-compose安装seata1.6.1,使用nacos注册、db模式


    新建目录,挂载用

    1. mkdir -p /data/docker/seata/resources
    2. mkdir -p /data/docker/seata/logs

    给权限

    chmod -R 777 /data/docker/seata

    先在/data/docker/seata目录编写一个使用file启动的docker-compose.yml文件(seata包目录的script文件夹有),为了拷贝镜像内的resources文件夹

    1. cd /data/docker/seata
    2. vi docker-compose.yml

    docker-compose.yml文件

    1. version: "3"
    2. services:
    3. seata:
    4. container_name: seata
    5. image: seataio/seata-server:1.6.1
    6. ports:
    7. - "7091:7091"
    8. - "8091:8091"
    9. environment:
    10. - STORE_MODE=file
    11. - SEATA_PORT=8091

    从容器内复制resources文件到当前目录(/data/docker/seata),这一步非常关键,不然seata容器很可能启动不了!

    docker cp seata:/seata-server/resources ./

    到目录

    /data/docker/seata/resources

    修改application.yml,注意不要改动security:这部分配置

    vi application.yml

    application.yml 

    1. server:
    2. port: 7091
    3. spring:
    4. application:
    5. name: seata-server
    6. logging:
    7. config: classpath:logback-spring.xml
    8. file:
    9. path: ${user.home}/logs/seata
    10. extend:
    11. logstash-appender:
    12. destination: 127.0.0.1:4560
    13. kafka-appender:
    14. bootstrap-servers: 127.0.0.1:9092
    15. topic: logback_to_logstash
    16. # seata可视化web界面账号密码
    17. console:
    18. user:
    19. username: seata
    20. password: seata
    21. seata:
    22. config:
    23. # support: nacos 、 consul 、 apollo 、 zk 、 etcd3
    24. type: nacos
    25. nacos:
    26. server-addr: xx:8848
    27. namespace: namespace
    28. group: SEATA_GROUP
    29. username: username
    30. password: password
    31. context-path:
    32. ##if use MSE Nacos with auth, mutex with username/password attribute
    33. #access-key:
    34. #secret-key:
    35. data-id: seataServer.properties
    36. registry:
    37. # support: nacos 、 eureka 、 redis 、 zk 、 consul 、 etcd3 、 sofa
    38. type: nacos
    39. preferred-networks: 30.240.*
    40. nacos:
    41. application: seata-server
    42. server-addr: xx:8848
    43. group: SEATA_GROUP
    44. namespace: namespace
    45. cluster: default
    46. username: username
    47. password: password
    48. context-path:
    49. ##if use MSE Nacos with auth, mutex with username/password attribute
    50. #access-key:
    51. #secret-key:
    52. server:
    53. service-port: 8091 #If not configured, the default is '${server.port} + 1000'
    54. max-commit-retry-timeout: -1
    55. max-rollback-retry-timeout: -1
    56. rollback-retry-timeout-unlock-enable: false
    57. enable-check-auth: true
    58. enable-parallel-request-handle: true
    59. retry-dead-threshold: 130000
    60. xaer-nota-retry-timeout: 60000
    61. enableParallelRequestHandle: true
    62. recovery:
    63. committing-retry-period: 1000
    64. async-committing-retry-period: 1000
    65. rollbacking-retry-period: 1000
    66. timeout-retry-period: 1000
    67. undo:
    68. log-save-days: 7
    69. log-delete-period: 86400000
    70. session:
    71. branch-async-queue-size: 5000 #branch async remove queue size
    72. enable-branch-async-remove: false #enable to asynchronous remove branchSession
    73. store:
    74. # support: file 、 db 、 redis
    75. mode: db
    76. session:
    77. mode: db
    78. lock:
    79. mode: db
    80. db:
    81. datasource: druid
    82. db-type: mysql
    83. driver-class-name: com.mysql.jdbc.Driver
    84. url: jdbc:mysql://xx:3306/seata?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
    85. user: user
    86. password: password
    87. min-conn: 10
    88. max-conn: 100
    89. global-table: global_table
    90. branch-table: branch_table
    91. lock-table: lock_table
    92. distributed-lock-table: distributed_lock
    93. query-limit: 1000
    94. max-wait: 5000
    95. metrics:
    96. enabled: false
    97. registry-type: compact
    98. exporter-list: prometheus
    99. exporter-prometheus-port: 9898
    100. transport:
    101. rpc-tc-request-timeout: 15000
    102. enable-tc-server-batch-send-response: false
    103. shutdown:
    104. wait: 3
    105. thread-factory:
    106. boss-thread-prefix: NettyBoss
    107. worker-thread-prefix: NettyServerNIOWorker
    108. boss-thread-size: 1
    109. security:
    110. secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
    111. tokenValidityInMilliseconds: 1800000
    112. ignore:
    113. urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

    更改docker-compose.yml

    1. cd /data/docker/seata
    2. vi docker-compose.yml

    docker-compose.yml

    1. version: "3"
    2. services:
    3. seata:
    4. container_name: seata
    5. image: seataio/seata-server:1.6.1
    6. ports:
    7. - "7091:7091"
    8. - "8091:8091"
    9. environment:
    10. - STORE_MODE=db
    11. # 以SEATA_IP作为host注册seata server
    12. - SEATA_PORT=8091
    13. - SEATA_IP=公网ip
    14. volumes:
    15. - /data/docker/seata/resources:/seata-server/resources
    16. - /data/docker/seata/logs:/seata-server/logs

     在nacos配置seataServer.properties,注意命名空间和分组要和配置对应

    1. #For details about configuration items, see https://seata.io/zh-cn/docs/user/configurations.html
    2. #Transport configuration, for client and server
    3. transport.type=TCP
    4. transport.server=NIO
    5. transport.heartbeat=true
    6. transport.enableTmClientBatchSendRequest=false
    7. transport.enableRmClientBatchSendRequest=true
    8. transport.enableTcServerBatchSendResponse=false
    9. transport.rpcRmRequestTimeout=30000
    10. transport.rpcTmRequestTimeout=30000
    11. transport.rpcTcRequestTimeout=30000
    12. transport.threadFactory.bossThreadPrefix=NettyBoss
    13. transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
    14. transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
    15. transport.threadFactory.shareBossWorker=false
    16. transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
    17. transport.threadFactory.clientSelectorThreadSize=1
    18. transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
    19. transport.threadFactory.bossThreadSize=1
    20. transport.threadFactory.workerThreadSize=default
    21. transport.shutdown.wait=3
    22. transport.serialization=seata
    23. transport.compressor=none
    24. #Transaction routing rules configuration, only for the client
    25. # 此处的mygroup名字可以自定义,只修改这个值即可
    26. service.vgroupMapping.mygroup=default
    27. #If you use a registry, you can ignore it
    28. #service.default.grouplist=192.168.0.31:8091
    29. service.enableDegrade=false
    30. service.disableGlobalTransaction=false
    31. #Transaction rule configuration, only for the client
    32. client.rm.asyncCommitBufferLimit=10000
    33. client.rm.lock.retryInterval=10
    34. client.rm.lock.retryTimes=30
    35. client.rm.lock.retryPolicyBranchRollbackOnConflict=true
    36. client.rm.reportRetryCount=5
    37. client.rm.tableMetaCheckEnable=true
    38. client.rm.tableMetaCheckerInterval=60000
    39. client.rm.sqlParserType=druid
    40. client.rm.reportSuccessEnable=true
    41. client.rm.sagaBranchRegisterEnable=false
    42. client.rm.sagaJsonParser=fastjson
    43. client.rm.tccActionInterceptorOrder=-2147482648
    44. client.tm.commitRetryCount=5
    45. client.tm.rollbackRetryCount=5
    46. client.tm.defaultGlobalTransactionTimeout=60000
    47. client.tm.degradeCheck=false
    48. client.tm.degradeCheckAllowTimes=10
    49. client.tm.degradeCheckPeriod=2000
    50. client.tm.interceptorOrder=-2147482648
    51. client.undo.dataValidation=true
    52. client.undo.logSerialization=jackson
    53. client.undo.onlyCareUpdateColumns=true
    54. server.undo.logSaveDays=7
    55. server.undo.logDeletePeriod=86400000
    56. client.undo.logTable=undo_log
    57. client.undo.compress.enable=true
    58. client.undo.compress.type=zip
    59. client.undo.compress.threshold=64k
    60. #For TCC transaction mode
    61. tcc.fence.logTableName=tcc_fence_log
    62. tcc.fence.cleanPeriod=1h
    63. #Log rule configuration, for client and server
    64. log.exceptionRate=100
    65. #Transaction storage configuration, only for the server. The file, db, and redis configuration values are optional.
    66. # 默认为file,一定要改为db,我们自己的服务启动会连接不到seata
    67. store.mode=db
    68. store.lock.mode=db
    69. store.session.mode=db
    70. #Used for password encryption
    71. #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.
    72. # 修改mysql的配置
    73. store.db.datasource=druid
    74. store.db.dbType=mysql
    75. store.db.driverClassName=com.mysql.cj.jdbc.Driver
    76. # 指定seata的数据库,下面会提
    77. store.db.url=jdbc:mysql://ip:3306/seata-server?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
    78. store.db.user=user
    79. store.db.password=password
    80. store.db.minConn=5
    81. store.db.maxConn=30
    82. store.db.globalTable=global_table
    83. store.db.branchTable=branch_table
    84. store.db.distributedLockTable=distributed_lock
    85. store.db.queryLimit=100
    86. store.db.lockTable=lock_table
    87. store.db.maxWait=5000
    88. #Transaction rule configuration, only for the server
    89. server.recovery.committingRetryPeriod=1000
    90. server.recovery.asynCommittingRetryPeriod=1000
    91. server.recovery.rollbackingRetryPeriod=1000
    92. server.recovery.timeoutRetryPeriod=1000
    93. server.maxCommitRetryTimeout=-1
    94. server.maxRollbackRetryTimeout=-1
    95. server.rollbackRetryTimeoutUnlockEnable=false
    96. server.distributedLockExpireTime=10000
    97. server.xaerNotaRetryTimeout=60000
    98. server.session.branchAsyncQueueSize=5000
    99. server.session.enableBranchAsyncRemove=false
    100. server.enableParallelRequestHandle=false
    101. #Metrics configuration, only for the server
    102. metrics.enabled=false
    103. metrics.registryType=compact
    104. metrics.exporterList=prometheus
    105. metrics.exporterPrometheusPort=9898

    下载seata 1.6.1版本https://github.com/seata/seata/releases/tag/v1.6.1

    到 seata-server-1.6.1\seata\script\server\db 找到对应建表语句

    新建数据库seata-server

    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目录,重启容器,查看日志

    1. cd /data/docker/seata
    2. docker-compose down --remove-orphans
    3. docker-compose up -d
    4. docker logs seata

    http://ip:7091打开seata控制台

  • 相关阅读:
    c语言实现三子棋
    NoSQL数据库入门
    百度智能云千帆大模型平台 2.0 产品技术解析
    一文了解线上展厅如何制作,线上展厅制作需要注意什么
    zookeeper应用之分布式队列
    定点整数、小数
    CAS:851113-28-5 (生物素-ahx-ahx-酪胺)
    淘宝/天猫获得淘宝店铺详情 API
    Android学习
    『LeetCode|每日一题』---->三数之和
  • 原文地址:https://blog.csdn.net/zhengtuqi/article/details/133844107