redis工具扩容
一,在db01中新增加一个节点
1创建配置文件日志文件和pid文件的存放目录,创建redis数据的存放目录:
[root@db01 ~]# mkdir -p /opt/redis_cluster/redis_{6390,6391}/{conf,logs,pid}
[root@db01 ~]# mkdir -p /data/redis_cluster/redis_{6390,6391}
[root@db01 ~]# cd /opt/redis_cluster/
[root@db01 redis_cluster]# cp redis_6380/conf/redis_6380.conf redis_6390/conf/redis_6390.conf
[root@db01 redis_cluster]# cp redis_6380/conf/redis_6380.conf redis_6391/conf/redis_6391.conf
[root@db01 redis_cluster]# sed -i 's#6380#6390#g' redis_6390/conf/redis_6390.conf
[root@db01 redis_cluster]# sed -i 's#6380#6391#g' redis_6391/conf/redis_6391.conf
[root@db01 redis_cluster]#
[root@db01 ~]# sh redis_shell.sh start 6390
root 776 1 0 19:27 ? 00:00:01 /usr/local/bin/redis-server 127.0.0.1:6379
root 990 951 6 19:41 pts/0 00:00:00 sh redis_shell.sh start 6390
root 998 1 2 19:41 ? 00:00:00 redis-server 10.0.0.201:6390 [cluster]
root 1000 990 0 19:41 pts/0 00:00:00 grep redis
[root@db01 ~]# sh redis_shell.sh start 6391
root 776 1 0 19:27 ? 00:00:02 /usr/local/bin/redis-server 127.0.0.1:6379
root 998 1 0 19:41 ? 00:00:00 redis-server 10.0.0.201:6390 [cluster]
root 1003 951 0 19:41 pts/0 00:00:00 sh redis_shell.sh start 6391
root 1011 1 0 19:41 ? 00:00:00 redis-server /opt/redis_cluster/redis_6391/conf/redis_6391.conf
root 1013 1003 0 19:41 pts/0 00:00:00 grep redis
[root@db01 ~]# sh redis_shell.sh ps
root 776 1 0 19:27 ? 00:00:02 /usr/local/bin/redis-server 127.0.0.1:6379
root 998 1 0 19:41 ? 00:00:00 redis-server 10.0.0.201:6390 [cluster]
root 1011 1 0 19:41 ? 00:00:00 redis-server 10.0.0.201:6391 [cluster]
root 1030 1 2 19:42 ? 00:00:00 redis-server 10.0.0.201:6380 [cluster]
root 1043 1 2 19:42 ? 00:00:00 redis-server 10.0.0.201:6381 [cluster]
root 1048 951 0 19:43 pts/0 00:00:00 sh redis_shell.sh ps
root 1053 1048 0 19:43 pts/0 00:00:00 grep redis
[root@db01 ~]#
2将新节点添加到集群
[root@db01 ~]# cd /opt/redis_cluster/redis/src
[root@db01 src]# ./redis-trib.rb add-node 10.0.0.201:6390 10.0.0.201:6380
[root@db01 src]# ./redis-trib.rb add-node 10.0.0.201:6391 10.0.0.201:6380
3从新分配槽位
[root@db01 src]# pwd
/opt/redis_cluster/redis/src
[root@db01 src]# ./redis-trib.rb reshard 10.0.0.201:6380
>>> Performing Cluster Check (using node 10.0.0.201:6380)
S: 3a9aeeeb4ac0c76a5ba3c66bb917161348582c01 10.0.0.201:6380
slots: (0 slots) slave
replicates a31deef0baf970cef6c798f1e320fb4ba5543daf
M: ae183c4181d953d1ef052e7db473951390ff9d05 10.0.0.201:6390
slots: (0 slots) master
0 additional replica(s)
M: a31deef0baf970cef6c798f1e320fb4ba5543daf 10.0.0.203:6381
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 6c4c0f7417dfc14468a73ac94a66634181546721 10.0.0.201:6391
slots: (0 slots) master
0 additional replica(s)
M: e92cd97d2c06d2cc02547bcd7ac64b9f6fb44fb5 10.0.0.203:6380
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 8cea03a478990dc7e6d21f1b671c70dd921fcdb2 10.0.0.201:6381
slots: (0 slots) slave
replicates 9e6565d8f0a8ed0d6d56437dcf4b58cbb17a3c0f
M: 9e6565d8f0a8ed0d6d56437dcf4b58cbb17a3c0f 10.0.0.202:6380
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: c37e5f309b2d07012f2efb11053c517b5f51eba0 10.0.0.202:6381
slots: (0 slots) slave
replicates e92cd97d2c06d2cc02547bcd7ac64b9f6fb44fb5
[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? ae183c4181d953d1ef052e7db473951390ff9d05
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:all
4检查
[root@db01 src]# ./redis-trib.rb check 10.0.0.201:6380
5调整指针:
[root@db01 ~]# redis-cli -h db03 -p 6381
db03:6381> cluster replicate ae183c4181d953d1ef052e7db473951390ff9d05
(error) ERR To set a master the node must be empty and without assigned slots.
db03:6381>
[root@db01 ~]# redis-cli -h db01 -p 6391
db01:6391> cluster replice 3a9aeeeb4ac0c76a5ba3c66bb917161348582c01