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)?
顯示:[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?
顯示:[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:
顯示:*** 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)?
至此已完成 哈希槽 的分配。
- 檢查 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]#
- 如有疑問,請留言。