高可用

背景信息

通过 YAML 格式,ShardingSphere 会根据 YAML 配置,自动完成 ShardingSphereDataSource 对象的创建,减少用户不必要的编码工作。

参数解释

  1. rules:
  2. - !READWRITE_SPLITTING
  3. dataSources:
  4. replica_ds:
  5. dynamicStrategy: Dynamic # 动态读写分离
  6. autoAwareDataSourceName: # 高可用规则逻辑数据源名称
  7. - !DB_DISCOVERY
  8. dataSources:
  9. <data_source_name> (+): # 逻辑数据源名称
  10. dataSourceNames: # 数据源名称列表
  11. - <data_source>
  12. - <data_source>
  13. discoveryHeartbeatName: # 检测心跳名称
  14. discoveryTypeName: # 数据库发现类型名称
  15. # 心跳检测配置
  16. discoveryHeartbeats:
  17. <discovery_heartbeat_name> (+): # 心跳名称
  18. props:
  19. keep-alive-cron: # cron 表达式,如:'0/5 * * * * ?'
  20. # 数据库发现类型配置
  21. discoveryTypes:
  22. <discovery_type_name> (+): # 数据库发现类型名称
  23. type: # 数据库发现类型,如:MySQL.MGR,MySQL.NORMAL_REPLICATION,openGauss.NORMAL_REPLICATION
  24. props (?):
  25. group-name: 92504d5b-6dec-11e8-91ea-246e9612aaf1 # 数据库发现类型必要参数,如 MGR 的 group-name

配置示例

  1. databaseName: database_discovery_db
  2. dataSources:
  3. ds_0:
  4. url: jdbc:mysql://127.0.0.1:33306/primary_demo_ds?serverTimezone=UTC&useSSL=false
  5. username: root
  6. password:
  7. connectionTimeoutMilliseconds: 3000
  8. idleTimeoutMilliseconds: 60000
  9. maxLifetimeMilliseconds: 1800000
  10. maxPoolSize: 50
  11. minPoolSize: 1
  12. ds_1:
  13. url: jdbc:mysql://127.0.0.1:33307/primary_demo_ds?serverTimezone=UTC&useSSL=false
  14. username: root
  15. password:
  16. connectionTimeoutMilliseconds: 3000
  17. idleTimeoutMilliseconds: 60000
  18. maxLifetimeMilliseconds: 1800000
  19. maxPoolSize: 50
  20. minPoolSize: 1
  21. ds_2:
  22. url: jdbc:mysql://127.0.0.1:33308/primary_demo_ds?serverTimezone=UTC&useSSL=false
  23. username: root
  24. password:
  25. connectionTimeoutMilliseconds: 3000
  26. idleTimeoutMilliseconds: 60000
  27. maxLifetimeMilliseconds: 1800000
  28. maxPoolSize: 50
  29. minPoolSize: 1
  30. rules:
  31. - !READWRITE_SPLITTING
  32. dataSources:
  33. replica_ds:
  34. dynamicStrategy:
  35. autoAwareDataSourceName: readwrite_ds
  36. - !DB_DISCOVERY
  37. dataSources:
  38. readwrite_ds:
  39. dataSourceNames:
  40. - ds_0
  41. - ds_1
  42. - ds_2
  43. discoveryHeartbeatName: mgr_heartbeat
  44. discoveryTypeName: mgr
  45. discoveryHeartbeats:
  46. mgr_heartbeat:
  47. props:
  48. keep-alive-cron: '0/5 * * * * ?'
  49. discoveryTypes:
  50. mgr:
  51. type: MySQL.MGR
  52. props:
  53. group-name: 558edd3c-02ec-11ea-9bb3-080027e39bd2

相关参考