Seata 高可用部署

Seata 的高可用依赖于注册中心、配置中心和数据库来实现

Seata-Server

Seata-Server 需要使用注册中心,并把事务数据保存到数据库中,以 Nacos 为例

  • 修改registry.conf的注册中心配置
  1. registry {
  2. type = "nacos"
  3. nacos {
  4. application = "seata-server"
  5. serverAddr = "192.168.199.2"
  6. namespace = ""
  7. cluster = "default"
  8. username = ""
  9. password = ""
  10. }
  11. }
  12. config {
  13. type = "nacos"
  14. nacos {
  15. serverAddr = "192.168.199.2"
  16. namespace = ""
  17. group = "SEATA_GROUP"
  18. username = ""
  19. password = ""
  20. }
  21. }
  • 需要修改配置中心的以下几个配置(含db与redis,二者选其一 注:redis需seata-server 1.3版本及以上)
  1. service.vgroupMapping.my_test_tx_group=default
  2. store.mode=db|redis
  3. -----db-----
  4. store.db.datasource=druid
  5. store.db.dbType=mysql
  6. store.db.driverClassName=com.mysql.jdbc.Driver
  7. store.db.url=jdbc:mysql://127.0.0.1:3306/seata?useUnicode=true
  8. store.db.user=root
  9. store.db.password=123456
  10. ----redis----
  11. store.redis.host=127.0.0.1
  12. store.redis.port=6379
  13. store.redis.maxConn=10
  14. store.redis.minConn=1
  15. store.redis.database=0
  16. store.redis.password=null
  17. store.redis.queryLimit=100
  • db模式需要在数据库创建 global_table, branch_table, lock_table

相应的脚本在GitHub 的 /script/server/db/ 目录下

这样,启动多个seata-server,即可实现其高可用


以 Kubernetes 为例,部署文件参考:

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: seata-ha-server
  5. namespace: default
  6. labels:
  7. app.kubernetes.io/name: seata-ha-server
  8. spec:
  9. type: ClusterIP
  10. ports:
  11. - port: 8091
  12. protocol: TCP
  13. name: http
  14. selector:
  15. app.kubernetes.io/name: seata-ha-server
  16. ---
  17. apiVersion: apps/v1
  18. kind: Deployment
  19. metadata:
  20. name: seata-ha-server
  21. namespace: default
  22. labels:
  23. app.kubernetes.io/name: seata-ha-server
  24. spec:
  25. replicas: 3
  26. selector:
  27. matchLabels:
  28. app.kubernetes.io/name: seata-ha-server
  29. template:
  30. metadata:
  31. labels:
  32. app.kubernetes.io/name: seata-ha-server
  33. spec:
  34. containers:
  35. - name: seata-ha-server
  36. image: docker.io/seataio/seata-server:latest
  37. imagePullPolicy: IfNotPresent
  38. env:
  39. - name: SEATA_CONFIG_NAME
  40. value: file:/root/seata-config/registry
  41. ports:
  42. - name: http
  43. containerPort: 8091
  44. protocol: TCP
  45. volumeMounts:
  46. - name: seata-config
  47. mountPath: /root/seata-config
  48. volumes:
  49. - name: seata-config
  50. configMap:
  51. name: seata-ha-server-config
  52. ---
  53. apiVersion: v1
  54. kind: ConfigMap
  55. metadata:
  56. name: seata-ha-server-config
  57. data:
  58. registry.conf: |
  59. registry {
  60. type = "nacos"
  61. nacos {
  62. application = "seata-server"
  63. serverAddr = "192.168.199.2"
  64. }
  65. }
  66. config {
  67. type = "nacos"
  68. nacos {
  69. serverAddr = "192.168.199.2"
  70. group = "SEATA_GROUP"
  71. }
  72. }