建议使用redis-trib.rb工具,避免新节点已经加入了其他集群,造成故障
[root@mysql config]# ls dump.rdb redis_9000.conf redis_9001.conf redis_9002.conf [root@mysql config]# sed 's/9000/9003/g' redis_9000.conf > redis_9003.conf # 生成配置文件 [root@mysql config]# ls dump.rdb redis_9000.conf redis_9001.conf redis_9002.conf redis_9003.conf [root@mysql config]# redis-server /opt/config/redis_9003.conf # 指定配置文件运行redis-server [root@mysql config]# ps aux | grep redis-server # 查看redis-server的进程信息 root 1948 0.2 0.3 142916 7560 ? Ssl 12:21 0:13 redis-server 0.0.0.0:9002 [cluster] root 1952 0.2 0.3 142916 7560 ? Ssl 12:21 0:12 redis-server 0.0.0.0:9001 [cluster] root 1964 0.2 0.3 142916 7356 ? Ssl 12:21 0:12 redis-server 0.0.0.0:9000 [cluster] root 7348 0.0 0.2 142916 5352 ? Ssl 13:53 0:00 redis-server 0.0.0.0:9003 [cluster] root 7352 0.0 0.0 112664 972 pts/0 R+ 13:53 0:00 grep --color=auto redis-server [root@mysql config]# redis-trib.rb add-node 127.0.0.1:9003 192.168.81.100:9003 # 向集群添加节点 [root@mysql config]# redis-cli -p 9000 cluster nodes # 查看集群的节点信息 2ff22acb1e006b9881abc80238e15b4e3fcefbef 127.0.0.1:9003 slave 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 0 1539826328082 7 connected 6f369311b0ca4c503f337c4bb23424eed3eeb188 127.0.0.1:9002 master - 0 1539826326067 9 connected 5461-10922 fceba6001b95e2169ddd6622436b213324fe8f77 127.0.0.1:9001 master - 0 1539826330601 2 connected 10923-16383 ac153a3c1fb10d9d502b153c32dec65c85b2f97c 192.168.81.100:9002 slave fceba6001b95e2169ddd6622436b213324fe8f77 0 1539826331108 6 connected cb8c114d44d289687798508232d31e0a065fdab5 192.168.81.100:9000 slave 6f369311b0ca4c503f337c4bb23424eed3eeb188 0 1539826332115 9 connected 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 192.168.81.100:9003 master - 0 1539826329091 7 connected cf74b2d9570665b74525802462c74cf2e072ef99 192.168.81.101:9000 myself,master - 0 0 1 connected 0-5460 71f5695dc1f4322c8ea9066d1b3cd8bb0ab7a329 192.168.81.100:9001 slave cf74b2d9570665b74525802462c74cf2e072ef99 0 1539826330098 5 connected [root@mysql config]# redis-trib.rb reshard 127.0.0.1:9000 # 迁移槽 >>> Performing Cluster Check (using node 127.0.0.1:9000) M: cf74b2d9570665b74525802462c74cf2e072ef99 127.0.0.1:9000 slots:0-5460 (5461 slots) master 1 additional replica(s) S: 2ff22acb1e006b9881abc80238e15b4e3fcefbef 127.0.0.1:9003 slots: (0 slots) slave replicates 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 M: 6f369311b0ca4c503f337c4bb23424eed3eeb188 127.0.0.1:9002 slots:5461-10922 (5462 slots) master 1 additional replica(s) M: fceba6001b95e2169ddd6622436b213324fe8f77 127.0.0.1:9001 slots:10923-16383 (5461 slots) master 1 additional replica(s) S: ac153a3c1fb10d9d502b153c32dec65c85b2f97c 192.168.81.100:9002 slots: (0 slots) slave replicates fceba6001b95e2169ddd6622436b213324fe8f77 S: cb8c114d44d289687798508232d31e0a065fdab5 192.168.81.100:9000 slots: (0 slots) slave replicates 6f369311b0ca4c503f337c4bb23424eed3eeb188 M: 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 192.168.81.100:9003 slots: (0 slots) master 1 additional replica(s) S: 71f5695dc1f4322c8ea9066d1b3cd8bb0ab7a329 192.168.81.100:9001 slots: (0 slots) slave replicates cf74b2d9570665b74525802462c74cf2e072ef99 [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? 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 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 Ready to move 4096 slots. Source nodes: M: cf74b2d9570665b74525802462c74cf2e072ef99 127.0.0.1:9000 slots:0-5460 (5461 slots) master 1 additional replica(s) M: 6f369311b0ca4c503f337c4bb23424eed3eeb188 127.0.0.1:9002 slots:5461-10922 (5462 slots) master 1 additional replica(s) M: fceba6001b95e2169ddd6622436b213324fe8f77 127.0.0.1:9001 slots:10923-16383 (5461 slots) master 1 additional replica(s) Destination node: M: 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 192.168.81.100:9003 slots: (0 slots) master 1 additional replica(s) Resharding plan: Moving slot 5461 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5462 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5463 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5464 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5465 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5466 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5467 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5468 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5469 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5470 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5471 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5472 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5473 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5474 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5475 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5476 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5477 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5478 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5479 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5480 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5481 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5482 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5483 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5484 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5485 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5486 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5487 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5488 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5489 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 5490 from 6f369311b0ca4c503f337c4bb23424eed3eeb188 Moving slot 12283 from 127.0.0.1:9001 to 192.168.81.100:9003: Moving slot 12284 from 127.0.0.1:9001 to 192.168.81.100:9003: Moving slot 12285 from 127.0.0.1:9001 to 192.168.81.100:9003: Moving slot 12286 from 127.0.0.1:9001 to 192.168.81.100:9003: Moving slot 12287 from 127.0.0.1:9001 to 192.168.81.100:9003: [root@mysql config]# redis-cli -p 9000 cluster slots # 查看集群中槽的信息 1) 1) (integer) 6827 2) (integer) 10922 3) 1) "127.0.0.1" 2) (integer) 9002 3) "6f369311b0ca4c503f337c4bb23424eed3eeb188" 4) 1) "192.168.81.100" 2) (integer) 9000 3) "cb8c114d44d289687798508232d31e0a065fdab5" 2) 1) (integer) 12288 2) (integer) 16383 3) 1) "127.0.0.1" 2) (integer) 9001 3) "fceba6001b95e2169ddd6622436b213324fe8f77" 4) 1) "192.168.81.100" 2) (integer) 9002 3) "ac153a3c1fb10d9d502b153c32dec65c85b2f97c" 3) 1) (integer) 0 2) (integer) 1364 3) 1) "192.168.81.100" 2) (integer) 9003 3) "27266dcfd098dfe2a42361d6ab59edf8fb9f5413" 4) 1) "127.0.0.1" 2) (integer) 9003 3) "2ff22acb1e006b9881abc80238e15b4e3fcefbef" 4) 1) (integer) 5461 2) (integer) 6826 3) 1) "192.168.81.100" 2) (integer) 9003 3) "27266dcfd098dfe2a42361d6ab59edf8fb9f5413" 4) 1) "127.0.0.1" 2) (integer) 9003 3) "2ff22acb1e006b9881abc80238e15b4e3fcefbef" 5) 1) (integer) 10923 2) (integer) 12287 3) 1) "192.168.81.100" 2) (integer) 9003 3) "27266dcfd098dfe2a42361d6ab59edf8fb9f5413" 4) 1) "127.0.0.1" 2) (integer) 9003 3) "2ff22acb1e006b9881abc80238e15b4e3fcefbef" 6) 1) (integer) 1365 2) (integer) 5460 3) 1) "192.168.81.101" 2) (integer) 9000 3) "cf74b2d9570665b74525802462c74cf2e072ef99" 4) 1) "192.168.81.100" 2) (integer) 9001 3) "71f5695dc1f4322c8ea9066d1b3cd8bb0ab7a329" [root@mysql config]# redis-cli -p 9000 cluster nodes # 查看集群中节点的信息 2ff22acb1e006b9881abc80238e15b4e3fcefbef 127.0.0.1:9003 slave 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 0 1539826689921 12 connected 6f369311b0ca4c503f337c4bb23424eed3eeb188 127.0.0.1:9002 master - 0 1539826692961 9 connected 6827-10922 fceba6001b95e2169ddd6622436b213324fe8f77 127.0.0.1:9001 master - 0 1539826693970 2 connected 12288-16383 ac153a3c1fb10d9d502b153c32dec65c85b2f97c 192.168.81.100:9002 slave fceba6001b95e2169ddd6622436b213324fe8f77 0 1539826688916 6 connected cb8c114d44d289687798508232d31e0a065fdab5 192.168.81.100:9000 slave 6f369311b0ca4c503f337c4bb23424eed3eeb188 0 1539826693475 9 connected 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 192.168.81.100:9003 master - 0 1539826690944 12 connected 0-1364 5461-6826 10923-12287 cf74b2d9570665b74525802462c74cf2e072ef99 192.168.81.101:9000 myself,master - 0 0 1 connected 1365-5460 71f5695dc1f4322c8ea9066d1b3cd8bb0ab7a329 192.168.81.100:9001 slave cf74b2d9570665b74525802462c74cf2e072ef99 0 1539826691953 5 connected [root@mysql config]# redis-cli -p 9000 cluster nodes | grep master # 只查看master的节点信息 6f369311b0ca4c503f337c4bb23424eed3eeb188 127.0.0.1:9002 master - 0 1539826726695 9 connected 6827-10922 fceba6001b95e2169ddd6622436b213324fe8f77 127.0.0.1:9001 master - 0 1539826728205 2 connected 12288-16383 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 192.168.81.100:9003 master - 0 1539826726192 12 connected 0-1364 5461-6826 10923-12287 cf74b2d9570665b74525802462c74cf2e072ef99 192.168.81.101:9000 myself,master - 0 0 1 connected 1365-5460 7.Redis Cluster集群收缩高可用Redis(十一):使用redis-trib.rb工具搭建集群 (3)
内容版权声明:除非注明,否则皆为本站原创文章。