添加主从节点 一、查看集群信息redis-cli -p 6379 cluster nodes
[[email protected] redis]# redis-cli -h 192.168.1.3 -p 6379 cluster nodes
dbc41c1e1a3c0c51c1e2a8216dace0f8883cf51f 192.168.1.3:6385 master - 0 1434048814711 0 connected
85ad96dbdb49fd901de6f9f1431662c7ab58a208 192.168.1.4:6383 master - 0 1434048816227 5 connected 10923-16383
b37d1d090fdfffdeaeccc09f7978eeedc36b342a 192.168.1.4:6384 master - 0 1434048815218 7 connected 5461-10922
d9a852afad1669adf3561a57dbfa77b250ae32bb 192.168.1.4:6382 master - 0 1434048815722 4 connected 0-5460
76ea836e326fbd4b2a242f5da01b9005c131eb46 192.168.1.3:6380 slave d9a852afad1669adf3561a57dbfa77b250ae32bb 0 1434048816740 4 connected
4e54918bfc57e0895d68ad0f6bea1d104b18e0f6 192.168.1.3:6381 slave 85ad96dbdb49fd901de6f9f1431662c7ab58a208 0 1434048816740 5 connected
178b951fd08ae3250d06719509ea45258c6cef73 192.168.1.3:6379 myself,slave b37d1d090fdfffdeaeccc09f7978eeedc36b342a 0 0 1 connected
- 节点ID
- IP:端口
- 标志: master, slave, myself, fail, ...
- 如果是个从节点, 这里是它的主节点的NODE ID
- 集群最近一次向节点发送 PING 命令之后, 过去了多长时间还没接到回复。.
- 节点最近一次返回 PONG 回复的时间。
- 节点的配置纪元(configuration epoch):详细信息请参考 Redis 集群规范 。
- 本节点的网络连接情况:例如 connected 。
- 节点目前包含的槽:例如 127.0.0.1:7001 目前包含号码为 5960 至 10921 的哈希槽。
6385已经是主节点了,现在为他配置一个一从节点6387,另外在4这台主机上,如果从其他配置文件下复制redis-6387.conf时,注意有两处地方要改,一是端口号6367,另外一个是 cluster-config-file nodes-6387.conf,不然执行redis-server redis-6387.conf会无法把进程端口启动起来,查看日志会出现如下报错
[[email protected] redis]# cat /var/log/redis/redis-6387
12992:M 12 Jun 02:49:53.280 * Increased maximum number of open files to 10032 (it was originally set to 1024).
12992:M 12 Jun 02:49:53.281 # Sorry, the cluster configuration file nodes-6384.conf is already used by a different Redis Cluster node. Please make sure that different nodes use different cluster configuration files.
二、添加6387从节点
[[email protected] redis]# redis-cli -p 6387 cluster meet 192.168.1.3 6379
OK //执行这条命令默认是添主节点的,
[[email protected] redis]# redis-cli -h 192.168.1.3 -p 6379 cluster nodes
dbc41c1e1a3c0c51c1e2a8216dace0f8883cf51f 192.168.1.3:6385 master - 0 1434048912150 0 connected
85ad96dbdb49fd901de6f9f1431662c7ab58a208 192.168.1.4:6383 master - 0 1434048911648 5 connected 10923-16383
b37d1d090fdfffdeaeccc09f7978eeedc36b342a 192.168.1.4:6384 master - 0 1434048911143 7 connected 5461-10922
a1f35e42feba83fa12ee87fe366266095598e431 192.168.1.4:6387 master - 0 1434048912554 8 connected
d9a852afad1669adf3561a57dbfa77b250ae32bb 192.168.1.4:6382 master - 0 1434048911648 4 connected 0-5460
76ea836e326fbd4b2a242f5da01b9005c131eb46 192.168.1.3:6380 slave d9a852afad1669adf3561a57dbfa77b250ae32bb 0 1434048910634 4 connected
4e54918bfc57e0895d68ad0f6bea1d104b18e0f6 192.168.1.3:6381 slave 85ad96dbdb49fd901de6f9f1431662c7ab58a208 0 1434048912652 5 connected
178b951fd08ae3250d06719509ea45258c6cef73 192.168.1.3:6379 myself,slave b37d1d090fdfffdeaeccc09f7978eeedc36b342a 0 0 1 connected
[[email protected] redis]# redis-cli -p 6387 cluster replicate dbc41c1e1a3c0c51c1e2a8216dace0f8883cf51f
OK //CLUSTER REPLICATE
命令添加.这个命令也可以改变一个从节点的主节点。
三在查看
[[email protected] redis]# redis-cli -h 192.168.1.3 -p 6379 cluster nodes
dbc41c1e1a3c0c51c1e2a8216dace0f8883cf51f 192.168.1.3:6385 master - 0 1434048953498 0 connected
85ad96dbdb49fd901de6f9f1431662c7ab58a208 192.168.1.4:6383 master - 0 1434048952996 5 connected 10923-16383
b37d1d090fdfffdeaeccc09f7978eeedc36b342a 192.168.1.4:6384 master - 0 1434048952492 7 connected 5461-10922
a1f35e42feba83fa12ee87fe366266095598e431 192.168.1.4:6387 slave dbc41c1e1a3c0c51c1e2a8216dace0f8883cf51f 0 1434048951990 8 connected //变成从节点了
d9a852afad1669adf3561a57dbfa77b250ae32bb 192.168.1.4:6382 master - 0 1434048951484 4 connected 0-5460
76ea836e326fbd4b2a242f5da01b9005c131eb46 192.168.1.3:6380 slave d9a852afad1669adf3561a57dbfa77b250ae32bb 0 1434048952492 4 connected
4e54918bfc57e0895d68ad0f6bea1d104b18e0f6 192.168.1.3:6381 slave 85ad96dbdb49fd901de6f9f1431662c7ab58a208 0 1434048951988 5 connected
178b951fd08ae3250d06719509ea45258c6cef73 192.168.1.3:6379 myself,slave b37d1d090fdfffdeaeccc09f7978eeedc36b342a 0 0 1 connected