Redis Cluster 原生搭建(四)分配主从

查看集群节点信息

[root@redis3_0_7 scripts]# redis-cli -p 7000 cluster nodes
3b6b364ac99ed6a3225879707362551e83cbce43 127.0.0.1:7004 master - 0 1558180201103 3 connected
53be0c4f0ec1275a7fad49ca74c85623c70201da 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5461
19561da0f7b49fbfae0f4e27b6218588fc9185b3 127.0.0.1:7003 master - 0 1558180203111 4 connected
459fb67d56e2cad30272b0aaef6817d00ba7162f 127.0.0.1:7005 master - 0 1558180200098 5 connected
269839d65c594ec22b5bff64f643112594d60c25 127.0.0.1:7002 master - 0 1558180204115 2 connected 10923-16383
dd56b083303fc636cfc8abf3472b93f6200f3605 127.0.0.1:7001 master - 0 1558180205118 0 connected 5462-10922

7003 认 7000 为主

[root@redis3_0_7 scripts]# redis-cli -p 7003 cluster replicate 53be0c4f0ec1275a7fad49ca74c85623c70201da
OK
[root@redis3_0_7 scripts]# redis-cli -p 7000 cluster nodes
3b6b364ac99ed6a3225879707362551e83cbce43 127.0.0.1:7004 master - 0 1558180313445 3 connected
53be0c4f0ec1275a7fad49ca74c85623c70201da 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5461
19561da0f7b49fbfae0f4e27b6218588fc9185b3 127.0.0.1:7003 slave 53be0c4f0ec1275a7fad49ca74c85623c70201da 0 1558180309937 4 connected
459fb67d56e2cad30272b0aaef6817d00ba7162f 127.0.0.1:7005 master - 0 1558180311441 5 connected
269839d65c594ec22b5bff64f643112594d60c25 127.0.0.1:7002 master - 0 1558180312443 2 connected 10923-16383
dd56b083303fc636cfc8abf3472b93f6200f3605 127.0.0.1:7001 master - 0 1558180310437 0 connected 5462-10922

7004 认 7001 为主

[root@redis3_0_7 scripts]# redis-cli -p 7004 cluster replicate dd56b083303fc636cfc8abf3472b93f6200f3605
OK
[root@redis3_0_7 scripts]# redis-cli -p 7000 cluster nodes
3b6b364ac99ed6a3225879707362551e83cbce43 127.0.0.1:7004 slave dd56b083303fc636cfc8abf3472b93f6200f3605 0 1558180382104 3 connected
53be0c4f0ec1275a7fad49ca74c85623c70201da 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5461
19561da0f7b49fbfae0f4e27b6218588fc9185b3 127.0.0.1:7003 slave 53be0c4f0ec1275a7fad49ca74c85623c70201da 0 1558180381604 4 connected
459fb67d56e2cad30272b0aaef6817d00ba7162f 127.0.0.1:7005 master - 0 1558180379600 5 connected
269839d65c594ec22b5bff64f643112594d60c25 127.0.0.1:7002 master - 0 1558180380602 2 connected 10923-16383
dd56b083303fc636cfc8abf3472b93f6200f3605 127.0.0.1:7001 master - 0 1558180382606 0 connected 5462-10922

7005 认 7002 为主

[root@redis3_0_7 scripts]# redis-cli -p 7005 cluster replicate 269839d65c594ec22b5bff64f643112594d60c25
OK
[root@redis3_0_7 scripts]# redis-cli -p 7000 cluster nodes
3b6b364ac99ed6a3225879707362551e83cbce43 127.0.0.1:7004 slave dd56b083303fc636cfc8abf3472b93f6200f3605 0 1558180413672 3 connected
53be0c4f0ec1275a7fad49ca74c85623c70201da 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5461
19561da0f7b49fbfae0f4e27b6218588fc9185b3 127.0.0.1:7003 slave 53be0c4f0ec1275a7fad49ca74c85623c70201da 0 1558180414675 4 connected
459fb67d56e2cad30272b0aaef6817d00ba7162f 127.0.0.1:7005 slave 269839d65c594ec22b5bff64f643112594d60c25 0 1558180416681 5 connected
269839d65c594ec22b5bff64f643112594d60c25 127.0.0.1:7002 master - 0 1558180415678 2 connected 10923-16383
dd56b083303fc636cfc8abf3472b93f6200f3605 127.0.0.1:7001 master - 0 1558180417684 0 connected 5462-10922

以槽的视角查看集群的情况

[root@redis3_0_7 scripts]# redis-cli -p 7000 cluster slots
1) 1) (integer) 0
   2) (integer) 5461
   3) 1) "127.0.0.1"
      2) (integer) 7000
   4) 1) "127.0.0.1"
      2) (integer) 7003
2) 1) (integer) 10923
   2) (integer) 16383
   3) 1) "127.0.0.1"
      2) (integer) 7002
   4) 1) "127.0.0.1"
      2) (integer) 7005
3) 1) (integer) 5462
   2) (integer) 10922
   3) 1) "127.0.0.1"
      2) (integer) 7001
   4) 1) "127.0.0.1"
      2) (integer) 7004

尝试向一个节点写数据

[root@redis3_0_7 scripts]# redis-cli -c -p 7000
127.0.0.1:7000> set hello world
OK
127.0.0.1:7000> exit

在 3 台机器上部署 6 节点的拓扑

10.0.0.1:7000 10.0.0.2:7003
10.0.0.2:7001 10.0.0.3:7004
10.0.0.3 7002 10.0.0.1:7005

你可能感兴趣的:(Redis Cluster 原生搭建(四)分配主从)