CentOS 1908 配置 Redis 5.0.7 五(集羣新增 主從節點)

CentOS 下載:http://mirrors.aliyun.com/centos/

Redis:http://download.redis.io/releases/

CentOS 1908 配置 Redis 5.0.7 一(單節點)

CentOS 1908 配置 Redis 5.0.7 二(主從複製)

CentOS 1908 配置 Redis 5.0.7 三(哨兵模式)

CentOS 1908 配置 Redis 5.0.7 四(集羣配置)


  1. 查看 Redis 集羣狀態:
    ../src/redis-cli --cluster info 192.168.8.129:6001
    顯示:
    [root@192 cluster]# ../src/redis-cli --cluster info 192.168.8.129:6001
    192.168.8.129:6001 (a9e25213...) -> 0 keys | 5461 slots | 1 slaves.
    192.168.8.129:6002 (579d2e92...) -> 0 keys | 5462 slots | 1 slaves.
    192.168.8.129:6003 (78b51db2...) -> 0 keys | 5461 slots | 1 slaves.
    [OK] 0 keys in 3 masters.
    0.00 keys per slot on average.
    [root@192 cluster]# 
    
  2. 查看 Redis 運行:
    ps -ef | grep redis
    顯示:
    [root@192 cluster]# ps -ef | grep redis
    root       2462      1  0 22:25 ?        00:00:00 ../src/redis-server *:6001 [cluster]
    root       2467      1  0 22:25 ?        00:00:00 ../src/redis-server *:6002 [cluster]
    root       2472      1  0 22:25 ?        00:00:00 ../src/redis-server *:6003 [cluster]
    root       2477      1  0 22:25 ?        00:00:00 ../src/redis-server *:6004 [cluster]
    root       2482      1  0 22:25 ?        00:00:00 ../src/redis-server *:6005 [cluster]
    root       2487      1  0 22:25 ?        00:00:00 ../src/redis-server *:6006 [cluster]
    root       2606   2384  0 22:27 pts/0    00:00:00 grep --color=auto redis
    [root@192 cluster]# 
    
  3. 檢查 Redis 集羣:
    ../src/redis-cli --cluster check 192.168.8.129:6001
    顯示:
    從下面的信息可以看出:
    1、6001、6002、6003爲主節點,哈希槽分別爲:0-5460、5464-10922、10923-16380(2的14次方平均分)。
    [root@192 cluster]# ../src/redis-cli --cluster check 192.168.8.129:6001
    192.168.8.129:6001 (a9e25213...) -> 0 keys | 5461 slots | 1 slaves.
    192.168.8.129:6002 (579d2e92...) -> 0 keys | 5462 slots | 1 slaves.
    192.168.8.129:6003 (78b51db2...) -> 0 keys | 5461 slots | 1 slaves.
    [OK] 0 keys in 3 masters.
    0.00 keys per slot on average.
    >>> Performing Cluster Check (using node 192.168.8.129:6001)
    M: a9e25213d46b7d19bc46931b0e2490a93c8237ac 192.168.8.129:6001
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    S: 9e266605685ab453eccdb6042327a7e187cee7c3 192.168.8.129:6004
       slots: (0 slots) slave
       replicates 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8
    M: 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8 192.168.8.129:6002
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    S: 1780235a26ce1ed943fcdff24c509ebb27c2d03e 192.168.8.129:6005
       slots: (0 slots) slave
       replicates 78b51db2871be7fa265db054dd79cded9e97c4ff
    S: b6f7f1df8c16039c764d4c259182515139263e84 192.168.8.129:6006
       slots: (0 slots) slave
       replicates a9e25213d46b7d19bc46931b0e2490a93c8237ac
    M: 78b51db2871be7fa265db054dd79cded9e97c4ff 192.168.8.129:6003
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    [root@192 cluster]# 
    
  4. 新建:redis-6007.conf 與 redis-6008.conf,參見:CentOS 1908 配置 Redis 5.0.7 四(集羣配置)
     
  5. 打開:redis-6007.conf 與 redis-6008.conf 對應的端口(這裏使用 6007 與 6008),參見:CentOS 1908 配置 Redis 5.0.7 四(集羣配置)
     
  6. 運行:redis-6007.conf 與 redis-6008.conf,參見:CentOS 1908 配置 Redis 5.0.7 四(集羣配置)
     
  7. 在集羣中添加一個節點:
    ../src/redis-cli --cluster add-node 192.168.8.129:6007 192.168.8.129:6001
  8. 檢查 Redis 集羣:
    ../src/redis-cli --cluster check 192.168.8.129:6001
    顯示:
    從下面的信息可以看出:
    1、6007 無 哈希槽,無 子節點。
    [root@192 cluster]# ../src/redis-cli --cluster check 192.168.8.129:6001
    192.168.8.129:6001 (a9e25213...) -> 0 keys | 5461 slots | 1 slaves.
    192.168.8.129:6002 (579d2e92...) -> 0 keys | 5462 slots | 1 slaves.
    192.168.8.129:6003 (78b51db2...) -> 0 keys | 5461 slots | 1 slaves.
    192.168.8.129:6007 (3067f715...) -> 0 keys | 0 slots | 0 slaves.
    [OK] 0 keys in 4 masters.
    0.00 keys per slot on average.
    >>> Performing Cluster Check (using node 192.168.8.129:6001)
    M: a9e25213d46b7d19bc46931b0e2490a93c8237ac 192.168.8.129:6001
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    S: 9e266605685ab453eccdb6042327a7e187cee7c3 192.168.8.129:6004
       slots: (0 slots) slave
       replicates 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8
    M: 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8 192.168.8.129:6002
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    S: 1780235a26ce1ed943fcdff24c509ebb27c2d03e 192.168.8.129:6005
       slots: (0 slots) slave
       replicates 78b51db2871be7fa265db054dd79cded9e97c4ff
    S: b6f7f1df8c16039c764d4c259182515139263e84 192.168.8.129:6006
       slots: (0 slots) slave
       replicates a9e25213d46b7d19bc46931b0e2490a93c8237ac
    M: 78b51db2871be7fa265db054dd79cded9e97c4ff 192.168.8.129:6003
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
    M: 3067f715eaa5c88c260fb2e7f21edc06112208d3 192.168.8.129:6007
       slots: (0 slots) master
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    [root@192 cluster]# 
    
  9. 給 6007 添加子加點:
    其中:
    1、--cluster-master-id 後面顯示的 3067f715eaa5c88c260fb2e7f21edc06112208d3 爲 6007 的標識,可從上一步獲取。
    ../src/redis-cli --cluster add-node --cluster-slave --cluster-master-id 3067f715eaa5c88c260fb2e7f21edc06112208d3 192.168.8.129:6008 192.168.8.129:6001
  10. 檢查 Redis 集羣:
    ../src/redis-cli --cluster check 192.168.8.129:6001
    顯示:
    從下面的信息可以看出:
    1、6007 無 哈希槽,有一個 子節點。
    [root@192 cluster]# ../src/redis-cli --cluster check 192.168.8.129:6001
    192.168.8.129:6001 (a9e25213...) -> 0 keys | 5461 slots | 1 slaves.
    192.168.8.129:6002 (579d2e92...) -> 0 keys | 5462 slots | 1 slaves.
    192.168.8.129:6003 (78b51db2...) -> 0 keys | 5461 slots | 1 slaves.
    192.168.8.129:6007 (3067f715...) -> 0 keys | 0 slots | 1 slaves.
    [OK] 0 keys in 4 masters.
    0.00 keys per slot on average.
    >>> Performing Cluster Check (using node 192.168.8.129:6001)
    M: a9e25213d46b7d19bc46931b0e2490a93c8237ac 192.168.8.129:6001
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    S: 9e266605685ab453eccdb6042327a7e187cee7c3 192.168.8.129:6004
       slots: (0 slots) slave
       replicates 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8
    M: 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8 192.168.8.129:6002
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    S: 1780235a26ce1ed943fcdff24c509ebb27c2d03e 192.168.8.129:6005
       slots: (0 slots) slave
       replicates 78b51db2871be7fa265db054dd79cded9e97c4ff
    S: 5ef427a8a8c752301826e3f88e3a7282ff75a537 192.168.8.129:6008
       slots: (0 slots) slave
       replicates 3067f715eaa5c88c260fb2e7f21edc06112208d3
    S: b6f7f1df8c16039c764d4c259182515139263e84 192.168.8.129:6006
       slots: (0 slots) slave
       replicates a9e25213d46b7d19bc46931b0e2490a93c8237ac
    M: 78b51db2871be7fa265db054dd79cded9e97c4ff 192.168.8.129:6003
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
    M: 3067f715eaa5c88c260fb2e7f21edc06112208d3 192.168.8.129:6007
       slots: (0 slots) master
       1 additional replica(s)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    [root@192 cluster]# 
    
  11. 向 6007 分配 哈希槽:
    ../src/redis-cli --cluster reshard 192.168.8.129:6007
    顯示:
    [root@192 cluster]# ../src/redis-cli --cluster reshard 192.168.8.129:6007
    >>> Performing Cluster Check (using node 192.168.8.129:6007)
    M: 3067f715eaa5c88c260fb2e7f21edc06112208d3 192.168.8.129:6007
       slots: (0 slots) master
       1 additional replica(s)
    M: 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8 192.168.8.129:6002
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    S: 9e266605685ab453eccdb6042327a7e187cee7c3 192.168.8.129:6004
       slots: (0 slots) slave
       replicates 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8
    S: 1780235a26ce1ed943fcdff24c509ebb27c2d03e 192.168.8.129:6005
       slots: (0 slots) slave
       replicates 78b51db2871be7fa265db054dd79cded9e97c4ff
    S: b6f7f1df8c16039c764d4c259182515139263e84 192.168.8.129:6006
       slots: (0 slots) slave
       replicates a9e25213d46b7d19bc46931b0e2490a93c8237ac
    S: 5ef427a8a8c752301826e3f88e3a7282ff75a537 192.168.8.129:6008
       slots: (0 slots) slave
       replicates 3067f715eaa5c88c260fb2e7f21edc06112208d3
    M: 78b51db2871be7fa265db054dd79cded9e97c4ff 192.168.8.129:6003
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
    M: a9e25213d46b7d19bc46931b0e2490a93c8237ac 192.168.8.129:6001
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    How many slots do you want to move (from 1 to 16384)? 
    
    輸入(4個主節點,共16384個哈希槽,平均每個主節點爲:4096):4096
    顯示:
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    How many slots do you want to move (from 1 to 16384)? 4096
    What is the receiving node ID? 
    輸入(6007的標識):3067f715eaa5c88c260fb2e7f21edc06112208d3
    顯示:
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    How many slots do you want to move (from 1 to 16384)? 4096
    What is the receiving node ID? 3067f715eaa5c88c260fb2e7f21edc06112208d3
    Please enter all the source node IDs.
      Type 'all' to use all the nodes as source nodes for the hash slots.
      Type 'done' once you entered all the source nodes IDs.
    Source node #1: 
    
    輸入(將從哪些節點分配至6007):all
    顯示:
        ***
        Moving slot 1359 from a9e25213d46b7d19bc46931b0e2490a93c8237ac
        Moving slot 1360 from a9e25213d46b7d19bc46931b0e2490a93c8237ac
        Moving slot 1361 from a9e25213d46b7d19bc46931b0e2490a93c8237ac
        Moving slot 1362 from a9e25213d46b7d19bc46931b0e2490a93c8237ac
        Moving slot 1363 from a9e25213d46b7d19bc46931b0e2490a93c8237ac
        Moving slot 1364 from a9e25213d46b7d19bc46931b0e2490a93c8237ac
    Do you want to proceed with the proposed reshard plan (yes/no)?
    輸入:yes
    至此已完成 哈希槽 的分配。
     
  12. 檢查 Redis 集羣:
    ../src/redis-cli --cluster check 192.168.8.129:6001
    顯示:
    1、6007 有4096個哈希槽,有一個 子節點。
    [root@192 cluster]# ../src/redis-cli --cluster check 192.168.8.129:6001
    192.168.8.129:6001 (a9e25213...) -> 0 keys | 4096 slots | 1 slaves.
    192.168.8.129:6002 (579d2e92...) -> 0 keys | 4096 slots | 1 slaves.
    192.168.8.129:6003 (78b51db2...) -> 0 keys | 4096 slots | 1 slaves.
    192.168.8.129:6007 (3067f715...) -> 0 keys | 4096 slots | 1 slaves.
    [OK] 0 keys in 4 masters.
    0.00 keys per slot on average.
    >>> Performing Cluster Check (using node 192.168.8.129:6001)
    M: a9e25213d46b7d19bc46931b0e2490a93c8237ac 192.168.8.129:6001
       slots:[1365-5460] (4096 slots) master
       1 additional replica(s)
    S: 9e266605685ab453eccdb6042327a7e187cee7c3 192.168.8.129:6004
       slots: (0 slots) slave
       replicates 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8
    M: 579d2e9233faa12d6e13dfba8fe37f7e1c9983f8 192.168.8.129:6002
       slots:[6827-10922] (4096 slots) master
       1 additional replica(s)
    S: 1780235a26ce1ed943fcdff24c509ebb27c2d03e 192.168.8.129:6005
       slots: (0 slots) slave
       replicates 78b51db2871be7fa265db054dd79cded9e97c4ff
    S: 5ef427a8a8c752301826e3f88e3a7282ff75a537 192.168.8.129:6008
       slots: (0 slots) slave
       replicates 3067f715eaa5c88c260fb2e7f21edc06112208d3
    S: b6f7f1df8c16039c764d4c259182515139263e84 192.168.8.129:6006
       slots: (0 slots) slave
       replicates a9e25213d46b7d19bc46931b0e2490a93c8237ac
    M: 78b51db2871be7fa265db054dd79cded9e97c4ff 192.168.8.129:6003
       slots:[12288-16383] (4096 slots) master
       1 additional replica(s)
    M: 3067f715eaa5c88c260fb2e7f21edc06112208d3 192.168.8.129:6007
       slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
       1 additional replica(s)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    [root@192 cluster]# 
    

     

  13. 如有疑問,請留言。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章