Deploy Seata Server By Docker Compose

Precautions

  • Please avoid directly pulling the latest version image. The latest version is not necessarily a stable version. To avoid unnecessary problems, please go to docker image warehouse to determine the image version to be pulled.
  • Starting from Seata Server version 1.5.0, the configuration file has been changed to application.yml. So when using custom configuration, you need to copy the native configuration first.

Use custom configuration file

In order to obtain the configuration file of seata server 1.5.0, we need to first start a service of seata server 1.5.0, then copy the default configuration file from the started container instance, and then modify it.

docker-compose.yaml

  1. version: "3.1"
  2. services:
  3. seata-server:
  4. image: apache/seata-server:${latest-release-version}
  5. ports:
  6. - "7091:7091"
  7. - "8091:8091"

Next, copy the resource file in the /seata-server/resources location in the container to the specified location of the host through the docker cp command. In the specified location of the host, we can see the corresponding application.yml configuration file, and the relevant configuration only needs to modify this file.

The configuration of application.yml can refer to application.example.yml

Quick Start

No Registration Center, File Storage

In this mode, there is no need for a registration center or any third-party storage center.

docker-compose.yaml

  1. version: "3.1"
  2. services:
  3. seata-server:
  4. image: apache/seata-server:${latest-release-version}
  5. hostname: seata-server
  6. ports:
  7. - "7091:7091"
  8. - "8091:8091"
  9. environment:
  10. - SEATA_PORT=8091
  11. - STORE_MODE=file

No Registration Center, db Storage

The db mode needs to create the corresponding table structure in the database, please refer to [table creation script].

(1)application.yml

The configuration of application.yml can refer to application.example.yml

For more storage mode support, please refer to More Storage Modes.

  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. console:
  17. user:
  18. username: seata
  19. password: seata
  20. seata:
  21. config:
  22. # support: nacos, consul, apollo, zk, etcd3
  23. type: file
  24. registry:
  25. # support: nacos, eureka, redis, zk, consul, etcd3, sofa
  26. type: file
  27. store:
  28. # support: file 、 db 、 redis
  29. mode: db
  30. db:
  31. datasource: druid
  32. dbType: mysql
  33. # Need to adjust driverClassName according to mysql version
  34. # Driver corresponding to mysql8 and above versions is: com.mysql.cj.jdbc.Driver
  35. # Driver for versions below mysql8 is: com.mysql.jdbc.Driver
  36. driverClassName: com.mysql.cj.jdbc.Driver
  37. url: jdbc:mysql://127.0.0.1:3306/seata-server?useUnicode=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
  38. user: "username"
  39. password: "password"
  40. # server:
  41. # service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  42. security:
  43. secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
  44. tokenValidityInMilliseconds: 1800000
  45. ignore:
  46. urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

(2)Prepare file: docker-compose.yaml

  1. version: "3.1"
  2. services:
  3. seata-server:
  4. image: apache/seata-server:2.1.0
  5. ports:
  6. - "7091:7091"
  7. - "8091:8091"
  8. environment:
  9. - STORE_MODE=db
  10. # Register the seata server with SEATA_IP as the host
  11. - SEATA_IP=seata_ip
  12. - SEATA_PORT=8091
  13. volumes:
  14. - "/usr/share/zoneinfo/Asia/Shanghai:/etc/localtime" # Set the system time zone
  15. - "/usr/share/zoneinfo/Asia/Shanghai:/etc/timezone" # Set the time zone
  16. # Suppose we copy the resource file to the relative path `./seata-server/resources` via the `docker cp` command
  17. # If you have questions, please read [Precautions] and [Using Custom Configuration Files] above
  18. - "./seata-server/resources:/seata-server/resources"

Nacos Registration Center, db Storage

The db mode needs to create the corresponding table structure in the database, please refer to [table creation script].

(1)application.yml

The configuration of application.yml can refer to application.example.yml

Nacos Registration Center.

  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. console:
  17. user:
  18. username: seata
  19. password: seata
  20. seata:
  21. config:
  22. # support: nacos, consul, apollo, zk, etcd3
  23. type: nacos
  24. nacos:
  25. server-addr: nacos_ip:nacos_port
  26. namespace: seata-server
  27. group: SEATA_GROUP
  28. username: nacos
  29. password: nacos
  30. data-id: seataServer.properties
  31. registry:
  32. # support: nacos, eureka, redis, zk, consul, etcd3, sofa
  33. type: nacos
  34. nacos:
  35. application: seata-server
  36. server-addr: nacos_ip:nacos_port
  37. group: SEATA_GROUP
  38. namespace: seata-server
  39. # TC cluster name
  40. cluster: default
  41. username: nacos
  42. password: nacos
  43. # server:
  44. # service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  45. security:
  46. secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
  47. tokenValidityInMilliseconds: 1800000
  48. ignore:
  49. urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

(2)Prepare nacos configuration center configuration

For more storage mode support, please refer to More Storage Modes.

You need to create a new configuration in nacos, where the dataId is seataServer.properties

  1. store.mode=db
  2. #-----db-----
  3. store.db.datasource=druid
  4. store.db.dbType=mysql
  5. # Need to adjust driverClassName according to mysql version
  6. # Driver corresponding to mysql8 and above versions is: com.mysql.cj.jdbc.Driver
  7. # Driver for versions below mysql8 is: com.mysql.jdbc.Driver
  8. store.db.driverClassName=com.mysql.cj.jdbc.Driver
  9. store.db.url=jdbc:mysql://127.0.0.1:3306/seata-server?useUnicode=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
  10. store.db.user= "username"
  11. store.db.password= "password"
  12. # Number of initial database connections
  13. store.db.minConn=1
  14. # Maximum number of database connections
  15. store.db.maxConn=20
  16. # Maximum wait time when getting connection. The default value is 5000 milliseconds.
  17. store.db.maxWait=5000
  18. # Global transaction table name. The default value is global_table.
  19. store.db.globalTable=global_table
  20. # Branch transaction table name. The default value is branch_table.
  21. store.db.branchTable=branch_table
  22. # Global lock table name. The default value is lock_table.
  23. store.db.lockTable=lock_table
  24. # Maximum number of global transactions queried at one time. The default value is 100.
  25. store.db.queryLimit=100
  26. # Undo retention days. The default value is 7 days, log_status=1 (Appendix 3) and undo that is not cleaned up properly
  27. server.undo.logSaveDays=7
  28. # Undo cleanup thread interval time. The default value is 86400000 milliseconds.
  29. server.undo.logDeletePeriod=86400000
  30. # Two-stage commit retry timeout. The units are ms, s, m, h, d, corresponding to milliseconds, seconds, minutes, hours, days, default milliseconds. The default value of -1 means unlimited retries.
  31. # Formula: timeout>=now-globalTransactionBeginTime, if it's true means that the timeout will not be retried.
  32. # Note: After the timeout period is reached, no retries will be made. So there is a risk of data inconsistency, unless the business can calibrate the data by itself, otherwise use with caution.
  33. server.maxCommitRetryTimeout=-1
  34. # Two-phase rollback retry timeout
  35. server.maxRollbackRetryTimeout=-1
  36. # Two-phase commit incomplete state Global transaction retry commit thread interval time. The default value is 1000 milliseconds.
  37. server.recovery.committingRetryPeriod=1000
  38. # Two-phase asynchronous commit status retry submission thread interval time. The default value is 1000 milliseconds.
  39. server.recovery.asynCommittingRetryPeriod=1000
  40. # Two-stage rollback state retry rollback thread interval time. The default value is 1000 milliseconds.
  41. server.recovery.rollbackingRetryPeriod=1000
  42. # Timeout Status Detection Retry Thread Interval. The default value is 1000 milliseconds, and if timeout is detected, then it puts the global transaction into the rollback session manager.
  43. server.recovery.timeoutRetryPeriod=1000

(3)Prepare file: docker-compose.yaml

  1. version: "3.1"
  2. services:
  3. seata-server:
  4. image: apache/seata-server:2.1.0
  5. ports:
  6. - "7091:7091"
  7. - "8091:8091"
  8. environment:
  9. - STORE_MODE=db
  10. # Register the seata server with SEATA_IP as the host
  11. - SEATA_IP=seata_ip
  12. - SEATA_PORT=8091
  13. volumes:
  14. - "/usr/share/zoneinfo/Asia/Shanghai:/etc/localtime" # Set the system time zone
  15. - "/usr/share/zoneinfo/Asia/Shanghai:/etc/timezone" # Set the time zone
  16. # Suppose we copy the resource file to the relative path `./seata-server/resources` via the `docker cp` command
  17. # If you have questions, please read [Precautions] and [Using Custom Configuration Files] above
  18. - "./seata-server/resources:/seata-server/resources"

High Available Usage Deployment

Seata high availability usage deployment relies on the registration center and database, but does not depend on the configuration center.
Ensure that multiple Seata Servers use the same registry and the same storage center to form a highly available deployment.
The db mode needs to create the corresponding table structure in the database, please refer to [table creation script].

(1)application.yml

The configuration of application.yml can refer to application.example.yml

For more storage mode support, please refer to More Storage Modes.

  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. console:
  17. user:
  18. username: seata
  19. password: seata
  20. seata:
  21. config:
  22. # support: nacos, consul, apollo, zk, etcd3
  23. type: nacos
  24. nacos:
  25. server-addr: nacos_ip:nacos_port
  26. namespace: seata-server
  27. group: SEATA_GROUP
  28. usernam: nacos
  29. password: nacos
  30. data-id: seataServer.properties
  31. registry:
  32. # support: nacos, eureka, redis, zk, consul, etcd3, sofa
  33. type: nacos
  34. nacos:
  35. application: seata-server
  36. server-addr: nacos_ip:nacos_port
  37. group: SEATA_GROUP
  38. namespace: seata-server
  39. # TC cluster name
  40. cluster: default
  41. username: nacos
  42. password: nacos
  43. # store:
  44. # support: file 、 db 、 redis
  45. # mode: file
  46. # server:
  47. # service-port: 8091 #If not configured, the default is '${server.port} + 1000'
  48. security:
  49. secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
  50. tokenValidityInMilliseconds: 1800000
  51. ignore:
  52. urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login

(2)Prepare nacos configuration center configuration

For more storage mode support, please refer to More Storage Modes.

You need to create a new configuration in nacos, where the dataId is seataServer.properties

  1. store.mode=db
  2. #-----db-----
  3. store.db.datasource=druid
  4. store.db.dbType=mysql
  5. # Need to adjust driverClassName according to mysql version
  6. # Driver corresponding to mysql8 and above versions is: com.mysql.cj.jdbc.Driver
  7. # Driver for versions below mysql8 is: com.mysql.jdbc.Driver
  8. store.db.driverClassName=com.mysql.cj.jdbc.Driver
  9. store.db.url=jdbc:mysql://127.0.0.1:3306/seata-server?useUnicode=true&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
  10. store.db.user= "username"
  11. store.db.password= "password"
  12. # Number of initial database connections
  13. store.db.minConn=1
  14. # Maximum number of database connections
  15. store.db.maxConn=20
  16. # Maximum wait time when getting connection. The default value is 5000 milliseconds.
  17. store.db.maxWait=5000
  18. # Global transaction table name. The default value is global_table.
  19. store.db.globalTable=global_table
  20. # Branch transaction table name. The default value is branch_table.
  21. store.db.branchTable=branch_table
  22. # Global lock table name. The default value is lock_table.
  23. store.db.lockTable=lock_table
  24. # Maximum number of global transactions queried at one time. The default value is 100.
  25. store.db.queryLimit=100
  26. # Undo retention days. The default value is 7 days, log_status=1 (Appendix 3) and undo that is not cleaned up properly
  27. server.undo.logSaveDays=7
  28. # Undo cleanup thread interval time. The default value is 86400000 milliseconds.
  29. server.undo.logDeletePeriod=86400000
  30. # Two-stage commit retry timeout. The units are ms, s, m, h, d, corresponding to milliseconds, seconds, minutes, hours, days, default milliseconds. The default value of -1 means unlimited retries.
  31. # Formula: timeout>=now-globalTransactionBeginTime, if it's true means that the timeout will not be retried.
  32. # Note: After the timeout period is reached, no retries will be made. So there is a risk of data inconsistency, unless the business can calibrate the data by itself, otherwise use with caution.
  33. server.maxCommitRetryTimeout=-1
  34. # Two-phase rollback retry timeout
  35. server.maxRollbackRetryTimeout=-1
  36. # Two-phase commit incomplete state Global transaction retry commit thread interval time. The default value is 1000 milliseconds.
  37. server.recovery.committingRetryPeriod=1000
  38. # Two-phase asynchronous commit status retry submission thread interval time. The default value is 1000 milliseconds.
  39. server.recovery.asynCommittingRetryPeriod=1000
  40. # Two-stage rollback state retry rollback thread interval time. The default value is 1000 milliseconds.
  41. server.recovery.rollbackingRetryPeriod=1000
  42. # Timeout Status Detection Retry Thread Interval. The default value is 1000 milliseconds, and if timeout is detected, then it puts the global transaction into the rollback session manager.
  43. server.recovery.timeoutRetryPeriod=1000

(3)Prepare file: docker-compose.yaml

As long as the configuration is consistent, the seata service can be deployed on multiple instances on one machine or on multiple different hosts at the same time to achieve high service availability.
High Availability Usage Deployment

  1. version: "3.1"
  2. services:
  3. seata-server-1:
  4. image: apache/seata-server:${latest-release-version}
  5. ports:
  6. - "7091:7091"
  7. - "8091:8091"
  8. environment:
  9. - STORE_MODE=db
  10. # Register the seata server with SEATA_IP as the host
  11. - SEATA_IP=seata_ip
  12. - SEATA_PORT=8091
  13. volumes:
  14. - "/usr/share/zoneinfo/Asia/Shanghai:/etc/localtime" # Set the system time zone
  15. - "/usr/share/zoneinfo/Asia/Shanghai:/etc/timezone" # Set the time zone
  16. # Suppose we copy the resource file to the relative path `./seata-server/resources` via the `docker cp` command
  17. # If you have questions, please read [Precautions] and [Using Custom Configuration Files] above
  18. - "./seata-server/resources:/seata-server/resources"
  19. seata-server-2:
  20. image: apache/seata-server:${latest-release-version}
  21. ports:
  22. - "7092:7091"
  23. - "8092:8092"
  24. environment:
  25. - STORE_MODE=db
  26. # Register the seata server with SEATA_IP as the host
  27. - SEATA_IP=seata_ip
  28. - SEATA_PORT=8091
  29. volumes:
  30. - "/usr/share/zoneinfo/Asia/Shanghai:/etc/localtime" # Set the system time zone
  31. - "/usr/share/zoneinfo/Asia/Shanghai:/etc/timezone" # Set the time zone
  32. # Suppose we copy the resource file to the relative path `./seata-server/resources` via the `docker cp` command
  33. # If you have questions, please read [Precautions] and [Using Custom Configuration Files] above
  34. - "./seata-server/resources:/seata-server/resources"
  35. # seata Service 3......seata Service N

Environment variables

seata-server supports the following environment variables:

  • SEATA_IP

Optional. It specifies the IP started by seata-server. This IP is used when registering with the registration center, such as eureka, etc.

  • SEATA_PORT

Optional. It is used to specify the port where seata-server starts. The default port is 8091.

  • STORE_MODE

Optional. It is used to specify the transaction log storage method of seata-server, supports db, file, redis (supported by Seata-Server 1.3 and above). The default value is file.

  • SERVER_NODE

Optional. It is used to specify the seata-server node ID, such as 1,2,3… The default value is generated based on ip.

  • SEATA_ENV

Optional. It is used to specify the seata-server operating environment, such as dev, test, etc. When the service is started, configurations such as registry-dev.conf will be used.

  • SEATA_CONFIG_NAME

Optional. It is used to specify the configuration file location, such as file:/root/registry, which will load /root/registry.conf as the configuration file. If you need to specify the file.conf file at the same time, you need to change the value of config.file.name in registry.conf to something like file:/root/file.conf.