集群配置

  1. {
  2. "clusterType":"MASTER_SLAVE",
  3. "heartbeat":{
  4. "heartbeatTimeout":1000,
  5. "maxRetryCount":3,//2021-6-4前是maxRetry,后更正为maxRetryCount
  6. "minSwitchTimeInterval":300,
  7. "slaveThreshold":0
  8. },
  9. "masters":[ //配置多个主节点,在主挂的时候会选一个检测存活的数据源作为主节点
  10. "prototypeDs"
  11. ],
  12. "replicas":[//配置多个从节点
  13. "xxxx"
  14. ],
  15. "maxCon":200,
  16. "name":"prototype",
  17. "readBalanceType":"BALANCE_ALL",
  18. "switchType":"SWITCH"
  19. ////////////////////////////////////可选//////////////////////////////////
  20. ,
  21. "timer":{ //MySQL集群心跳周期,配置则开启集群心跳,Mycat主动检测主从延迟以及高可用主从切换
  22. "initialDelay": 30,
  23. "period":5,
  24. "timeUnit":"SECONDS"
  25. },
  26. //readBalanceName:"BalanceRoundRobin",
  27. //writeBalanceName:"BalanceRoundRobin",
  28. }

c0.cluster.json
{集群名字}.cluster.json 保存在clusters文件夹

clusterType

SINGLE_NODE:单一节点
MASTER_SLAVE:普通主从
GARELA_CLUSTER:garela cluster/PXC集群
MHA:1.21-2022年1月完善
MGR:1.21-2022年1月完善,MIC集群可以使用此配置

MHA与MGR集群会在心跳过程中根据READ_ONLY状态判断当前节点是否从节点(READ_ONLY=ON),主节点(READ_ONLY=OFF)动态更新主从节点信息,这样可以支持多主,单主.但是实际上生产上建议暂时使用单主模式,或者多主作为单主使用

readBalanceType
查询负载均衡策略

可选值:
BALANCE_ALL(默认值)
获取集群中所有数据源
BALANCE_ALL_READ
获取集群中允许读的数据源
BALANCE_READ_WRITE
获取集群中允许读写的数据源,但允许读的数据源优先
BALANCE_NONE
获取集群中允许写数据源,即主节点中选择

switchType

NOT_SWITCH:不进行主从切换
SWITCH:进行主从切换

readBalanceName与writeBalanceName
配置负载均衡策略,默认值是BalanceRandom

BalanceLeastActive_最少正在使用的连接数的mysql数据源被选中,如果连接数相同,则从连接数相同的数据源中的随机,使慢的机器收到更少。

BalanceRandom_利用随机算法产生随机数,然后从活跃的mysql数据源中进行选取。

BalanceRoundRobin_加权轮训算法,记录轮训的权值,每次访问加一,得到n,然后对mysql数据源进行轮训,如果权值已经为零,则跳过,如果非零则减一,n减1,直n为零则选中的节点就是需要访问的mysql数据源节点。

BalanceRunOnReplica_io.mycat.plug.loadBalance.BalanceRunOnReplica
把请求尽量发往从节点,不会把请求发到不可读(根据延迟值判断)与不可用的从节点

读写分离(一主一从,无备)(m是主,s是从)

  1. {
  2. "clusterType":"MASTER_SLAVE",
  3. "heartbeat":{
  4. "heartbeatTimeout":1000,
  5. "maxRetryCount":3,
  6. "minSwitchTimeInterval":300,
  7. "slaveThreshold":0
  8. },
  9. "masters":[
  10. "m"
  11. ],
  12. "replicas":[
  13. "s"
  14. ],
  15. "maxCon":200,
  16. "name":"prototype",
  17. "readBalanceType":"BALANCE_ALL",
  18. "switchType":"SWITCH" ,
  19. "timer":{
  20. "initialDelay": 30,
  21. "period":5,
  22. "timeUnit":"SECONDS"
  23. }
  24. }

读写分离(一主一从,一备)(m是主,s是从备)

  1. {
  2. "clusterType":"MASTER_SLAVE",
  3. "heartbeat":{
  4. "heartbeatTimeout":1000,
  5. "maxRetryCount":3,
  6. "minSwitchTimeInterval":300,
  7. "slaveThreshold":0
  8. },
  9. "masters":[
  10. "m","s"
  11. ],
  12. "replicas":[
  13. "s"
  14. ],
  15. "maxCon":200,
  16. "name":"prototype",
  17. "readBalanceType":"BALANCE_ALL",
  18. "switchType":"SWITCH" ,
  19. "timer":{
  20. "initialDelay": 30,
  21. "period":5,
  22. "timeUnit":"SECONDS"
  23. }
  24. }

读写分离(一主一从,一备)(m是主,s是从,b是备)

  1. {
  2. "clusterType":"MASTER_SLAVE",
  3. "heartbeat":{
  4. "heartbeatTimeout":1000,
  5. "maxRetryCount":3,
  6. "minSwitchTimeInterval":300,
  7. "slaveThreshold":0
  8. },
  9. "masters":[
  10. "m","b"
  11. ],
  12. "replicas":[
  13. "s"
  14. ],
  15. "maxCon":200,
  16. "name":"prototype",
  17. "readBalanceType":"BALANCE_ALL",
  18. "switchType":"SWITCH" ,
  19. "timer":{
  20. "initialDelay": 30,
  21. "period":5,
  22. "timeUnit":"SECONDS"
  23. }
  24. }


MHA(一主一从,一备)(m是主,s是从,b是备,READ_ONLY判断主)

  1. {
  2. "clusterType":"MHA",
  3. "heartbeat":{
  4. "heartbeatTimeout":1000,
  5. "maxRetryCount":3,
  6. "minSwitchTimeInterval":300,
  7. "slaveThreshold":0
  8. },
  9. "masters":[
  10. "m","b"
  11. ],
  12. "replicas":[
  13. "s"
  14. ],
  15. "maxCon":200,
  16. "name":"prototype",
  17. "readBalanceType":"BALANCE_ALL",
  18. "switchType":"SWITCH" ,
  19. "timer":{
  20. "initialDelay": 30,
  21. "period":5,
  22. "timeUnit":"SECONDS"
  23. }
  24. }

MGR(一主一从,一备)(m是主,s是从,b是备,READ_ONLY判断主)

  1. {
  2. "clusterType":"MGR",
  3. "heartbeat":{
  4. "heartbeatTimeout":1000,
  5. "maxRetryCount":3,
  6. "minSwitchTimeInterval":300,
  7. "slaveThreshold":0
  8. },
  9. "masters":[
  10. "m","b"
  11. ],
  12. "replicas":[
  13. "s"
  14. ],
  15. "maxCon":200,
  16. "name":"prototype",
  17. "readBalanceType":"BALANCE_ALL",
  18. "switchType":"SWITCH" ,
  19. "timer":{
  20. "initialDelay": 30,
  21. "period":5,
  22. "timeUnit":"SECONDS"
  23. }
  24. }

GARELA_CLUSTER(一主一从,一备)(m是主,s是从,b多主)

  1. {
  2. "clusterType":"GARELA_CLUSTER",
  3. "heartbeat":{
  4. "heartbeatTimeout":1000,
  5. "maxRetryCount":3,
  6. "minSwitchTimeInterval":300,
  7. "slaveThreshold":0
  8. },
  9. "masters":[
  10. "m","b"
  11. ],
  12. "replicas":[
  13. "s"
  14. ],
  15. "maxCon":200,
  16. "name":"prototype",
  17. "readBalanceType":"BALANCE_ALL",
  18. "switchType":"SWITCH" ,
  19. "timer":{
  20. "initialDelay": 30,
  21. "period":5,
  22. "timeUnit":"SECONDS"
  23. }
  24. }