redis搭建集群 - 增加节点

客官°小女子只卖身不卖艺 2022-02-17 03:01 374阅读 0赞

集群扩容- 增加节点

  1. 新增redis服务:(:1,$s/6381/8382/g 替换)
  2. 192.168.2.111:6381
  3. 192.168.2.111:6382
  4. 增加节点必须是一对,一个主节点一个从节点(手动分配63826381的从服务),注意对外开放对应的端口和监控端口(10000+端口)
  5. 一:主节点
  6. 1:把节点添加到集群中
  7. [root@192 redis6382]$ redis-cli --cluster add-node 192.168.2.111:6381 192.168.2.111:6379
  8. >>> Adding node 192.168.2.111:6381 to cluster 192.168.2.111:6379
  9. >>> Performing Cluster Check (using node 192.168.2.111:6379)
  10. M: 63cfbaf1e7d7d9fce095d0f485776ba15404bf8a 192.168.2.111:6379
  11. slots:[0-5460] (5461 slots) master
  12. 1 additional replica(s)
  13. M: 75b477ef4967c1bf50502cb834df3fd5660cfa22 192.168.2.112:6379
  14. slots:[5461-10922] (5462 slots) master
  15. 1 additional replica(s)
  16. M: ebc80d8dcabe30645b96fdfe08de84f52a42cbff 192.168.2.113:6379
  17. slots:[10923-16383] (5461 slots) master
  18. 1 additional replica(s)
  19. S: e6d09dcaa252336190e4e8747a60d067572d5156 192.168.2.112:6380
  20. slots: (0 slots) slave
  21. replicates ebc80d8dcabe30645b96fdfe08de84f52a42cbff
  22. S: f3dbdddc6c2dc23e1dde2e6e6662c6c5ebf167e9 192.168.2.111:6380
  23. slots: (0 slots) slave
  24. replicates 75b477ef4967c1bf50502cb834df3fd5660cfa22
  25. S: 5da5d0d7f7036c971926a821b33764fb2c78ea50 192.168.2.113:6380
  26. slots: (0 slots) slave
  27. replicates 63cfbaf1e7d7d9fce095d0f485776ba15404bf8a
  28. [OK] All nodes agree about slots configuration.
  29. >>> Check for open slots...
  30. >>> Check slots coverage...
  31. [OK] All 16384 slots covered.
  32. >>> Send CLUSTER MEET to node 192.168.2.111:6381 to make it join the cluster.
  33. [OK] New node added correctly.
  34. 命令解释:
  35. redis-cli --cluster add-node new_host:new_port existing_host:existing_port
  36. -> new_host:new_port: 新的ip 新添加的端口号
  37. -> existing_host:existing_port 集群中任意ip和对应端口号
  38. 2:查看添加的节点在集群中的状态
  39. [root@192 redis]$ redis-cli -h 192.168.2.111 -p 6381 -c
  40. 192.168.2.111:6381> cluster nodes
  41. 4ca16d842ea07379be11371aa2381529a9b5d7bc 192.168.2.111:6381@16381 myself,master - 0 1555496064000 0 connected
  42. 结果解释:6381节点是一个master节点, connected为空说明没有分配哈希槽,不能存储数据
  43. 3:为新增的master节点分配哈希槽 - 分片操作
  44. redis-cli --cluster reshard 需要增加哈希槽的ip加端口
  45. [root@192 redis6382]# redis-cli --cluster reshard 192.168.2.111:6381
  46. >>> Performing Cluster Check (using node 192.168.2.111:6381)
  47. M: 4ca16d842ea07379be11371aa2381529a9b5d7bc 192.168.2.111:6381
  48. slots: (0 slots) master
  49. S: f3dbdddc6c2dc23e1dde2e6e6662c6c5ebf167e9 192.168.2.111:6380
  50. slots: (0 slots) slave
  51. replicates 75b477ef4967c1bf50502cb834df3fd5660cfa22
  52. M: ebc80d8dcabe30645b96fdfe08de84f52a42cbff 192.168.2.113:6379
  53. slots:[10923-16383] (5461 slots) master
  54. 1 additional replica(s)
  55. M: 75b477ef4967c1bf50502cb834df3fd5660cfa22 192.168.2.112:6379
  56. slots:[5461-10922] (5462 slots) master
  57. 1 additional replica(s)
  58. M: 63cfbaf1e7d7d9fce095d0f485776ba15404bf8a 192.168.2.111:6379
  59. slots:[0-5460] (5461 slots) master
  60. 1 additional replica(s)
  61. S: e6d09dcaa252336190e4e8747a60d067572d5156 192.168.2.112:6380
  62. slots: (0 slots) slave
  63. replicates ebc80d8dcabe30645b96fdfe08de84f52a42cbff
  64. S: 5da5d0d7f7036c971926a821b33764fb2c78ea50 192.168.2.113:6380
  65. slots: (0 slots) slave
  66. replicates 63cfbaf1e7d7d9fce095d0f485776ba15404bf8a
  67. [OK] All nodes agree about slots configuration.
  68. >>> Check for open slots...
  69. >>> Check slots coverage...
  70. [OK] All 16384 slots covered
  71. How many slots do you want to move (from 1 to 16384)? 500
  72. -> 解释:希望分配多少个哈希槽,这里分配了500个哈希槽
  73. What is the receiving node ID? 4ca16d842ea07379be11371aa2381529a9b5d7bc
  74. -> 解释:希望哪个节点接收这500个哈希槽(感觉废话),id从上面取(4ca16d842ea07379be11371aa2381529a9b5d7bc)
  75. Please enter all the source node IDs.
  76. Type 'all' to use all the nodes as source nodes for the hash slots.
  77. Type 'done' once you entered all the source nodes IDs.
  78. -> 解释:清楚如all或者done all:从16384个哈希槽中随机分配500个槽,done:指定节点id从中分配500
  79. Source node #1: all
  80. -> 解释:列出500个哈希槽,分别从哪些节点分配的
  81. Ready to move 500 slots.
  82. Source nodes:
  83. M: ebc80d8dcabe30645b96fdfe08de84f52a42cbff 192.168.2.113:6379
  84. slots:[10923-16383] (5461 slots) master
  85. 1 additional replica(s)
  86. M: 75b477ef4967c1bf50502cb834df3fd5660cfa22 192.168.2.112:6379
  87. slots:[5461-10922] (5462 slots) master
  88. 1 additional replica(s)
  89. M: 63cfbaf1e7d7d9fce095d0f485776ba15404bf8a 192.168.2.111:6379
  90. slots:[0-5460] (5461 slots) master
  91. 1 additional replica(s)
  92. Destination node:
  93. M: 4ca16d842ea07379be11371aa2381529a9b5d7bc 192.168.2.111:6381
  94. slots: (0 slots) master
  95. Resharding plan:
  96. -> 展示具体分配的是哪些哈希槽
  97. Moving slot 5461 from 75b477ef4967c1bf50502cb834df3fd5660cfa22
  98. .....
  99. Do you want to proceed with the proposed reshard plan (yes/no)? yes
  100. ->解释:是否同意分配的哈希槽
  101. -> 展示具体分配的是哪些哈希槽
  102. Moving slot 5461 from 192.168.2.112:6379 to 192.168.2.111:6381:
  103. .....
  104. 4: 查看分配结果
  105. 192.168.2.111:6381> cluster nodes
  106. 4ca16d842ea07379be11371aa2381529a9b5d7bc 192.168.2.111:6381@16381 myself,master - 0 1555557769000 7 connected 0-165 5461-5627 10923-11088
  107. 二:从节点
  108. [root@192 ~]# redis-cli --cluster add-node 192.168.2.111:6382 192.168.2.111:6379 --cluster-slave --cluster-master-id 4ca16d842ea07379be11371aa2381529a9b5d7bc
  109. 结果:
  110. >>> Adding node 192.168.2.111:6382 to cluster 192.168.2.111:6379
  111. >>> Performing Cluster Check (using node 192.168.2.111:6379)
  112. M: 63cfbaf1e7d7d9fce095d0f485776ba15404bf8a 192.168.2.111:6379
  113. slots:[166-5460] (5295 slots) master
  114. 1 additional replica(s)
  115. M: 75b477ef4967c1bf50502cb834df3fd5660cfa22 192.168.2.112:6379
  116. slots:[5628-10922] (5295 slots) master
  117. 1 additional replica(s)
  118. M: 4ca16d842ea07379be11371aa2381529a9b5d7bc 192.168.2.111:6381
  119. slots:[0-165],[5461-5627],[10923-11088] (499 slots) master
  120. M: ebc80d8dcabe30645b96fdfe08de84f52a42cbff 192.168.2.113:6379
  121. slots:[11089-16383] (5295 slots) master
  122. 1 additional replica(s)
  123. S: e6d09dcaa252336190e4e8747a60d067572d5156 192.168.2.112:6380
  124. slots: (0 slots) slave
  125. replicates ebc80d8dcabe30645b96fdfe08de84f52a42cbff
  126. S: f3dbdddc6c2dc23e1dde2e6e6662c6c5ebf167e9 192.168.2.111:6380
  127. slots: (0 slots) slave
  128. replicates 75b477ef4967c1bf50502cb834df3fd5660cfa22
  129. S: 5da5d0d7f7036c971926a821b33764fb2c78ea50 192.168.2.113:6380
  130. slots: (0 slots) slave
  131. replicates 63cfbaf1e7d7d9fce095d0f485776ba15404bf8a
  132. [OK] All nodes agree about slots configuration.
  133. >>> Check for open slots...
  134. >>> Check slots coverage...
  135. [OK] All 16384 slots covered.
  136. >>> Send CLUSTER MEET to node 192.168.2.111:6382 to make it join the cluster.
  137. Waiting for the cluster to join
  138. ..
  139. >>> Configure node as replica of 192.168.2.111:6381.
  140. [OK] New node added correctly.
  141. 命令解释:
  142. redis-cli --cluster add-node new_host:new_port existing_host:existing_port
  143. --cluster-slave --cluster-master-id <arg>
  144. 2:查看节点信息
  145. [root@192 ~]# redis-cli --cluster check 192.168.2.111:6382
  146. 结果:
  147. 192.168.2.111:6379 (63cfbaf1...) -> 1 keys | 5295 slots | 1 slaves.
  148. 192.168.2.112:6379 (75b477ef...) -> 1 keys | 5295 slots | 1 slaves.
  149. 192.168.2.113:6379 (ebc80d8d...) -> 0 keys | 5295 slots | 1 slaves.
  150. 192.168.2.111:6381 (4ca16d84...) -> 0 keys | 499 slots | 1 slaves.
  151. [OK] 2 keys in 4 masters.
  152. 0.00 keys per slot on average.
  153. >>> Performing Cluster Check (using node 192.168.2.111:6382)
  154. S: cc3cfe29129ff7a5bcb2c5f803e8f4614b291373 192.168.2.111:6382
  155. slots: (0 slots) slave
  156. replicates 4ca16d842ea07379be11371aa2381529a9b5d7bc
  157. M: 4ca16d842ea07379be11371aa2381529a9b5d7bc 192.168.2.111:6381
  158. slots:[0-165],[5461-5627],[10923-11088] (499 slots) master
  159. 1 additional replica(s)
  160. 显示已经变成192.168.2.111:6381 slave

发表评论

表情:
评论列表 (有 0 条评论,374人围观)

还没有评论,来说两句吧...

相关阅读