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 四(集群配置)
查看 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]#
查看 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]#
检查 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]#
新建:redis-6007.conf 与 redis-6008.conf,参见:CentOS 1908 配置 Redis 5.0.7 四(集群配置)。
打开:redis-6007.conf 与 redis-6008.conf 对应的端口(这里使用 6007 与 6008),参见:CentOS 1908 配置 Redis 5.0.7 四(集群配置)。
运行:redis-6007.conf 与 redis-6008.conf,参见:CentOS 1908 配置 Redis 5.0.7 四(集群配置)。
在集群中添加一个节点:
../src/redis-cli --cluster add-node 192.168.8.129:6007 192.168.8.129:6001
检查 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]#
给 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
检查 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]#
向 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
至此已完成 哈希槽 的分配。检查 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]#
- 如有疑问,请留言。
还没有评论,来说两句吧...