具体步骤为:在当前虚拟机上另开启一个命令提示符,进行meet操作
[root@mysql ~]# redis-cli -p 9000 cluster meet 127.0.0.1 9001 # 192.168.81.101:9000端口运行的redis-server向192.168.81.101:9001端口运行的redis-server发送meet请求 OK [root@mysql ~]# redis-cli -p 9000 cluster meet 127.0.0.1 9002 # 192.168.81.101:9000端口运行的redis-server向192.168.81.101:9001端口运行的redis-server发送meet请求 OK [root@mysql ~]# redis-cli -p 9000 cluster meet 192.168.81.100 9002 # 192.168.81.101:9000端口运行的redis-server向192.168.81.100:9002端口运行的redis-server发送meet请求 OK [root@mysql ~]# redis-cli -p 9000 cluster meet 192.168.81.100 9001 # 192.168.81.101:9000端口运行的redis-server向192.168.81.100:9001端口运行的redis-server发送meet请求 OK [root@mysql ~]# redis-cli -p 9000 cluster meet 192.168.81.100 9000 # 192.168.81.101:9000端口运行的redis-server向192.168.81.100:9000端口运行的redis-server发送meet请求 OK [root@mysql ~]# redis-cli -p 9000 cluster info # 查看集群的信息 cluster_state:ok # 状态为ok cluster_slots_assigned:16384 # 标记的slot共有16384个 cluster_slots_ok:16384 # 已分配的slot有16384个 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:6 # 当前集群共有6个节点 cluster_size:3 cluster_current_epoch:6 cluster_my_epoch:1 cluster_stats_messages_sent:1890 cluster_stats_messages_received:1890 [root@mysql ~]# redis-cli -p 9000 cluster nodes # 查看当前集群节点信息 cb8c114d44d289687798508232d31e0a065fdab5 192.168.81.100:9000 master - 0 1539751180759 4 connected 5461-10922 6f369311b0ca4c503f337c4bb23424eed3eeb188 127.0.0.1:9002 slave cb8c114d44d289687798508232d31e0a065fdab5 0 1539751183277 4 connected fceba6001b95e2169ddd6622436b213324fe8f77 127.0.0.1:9001 master - 0 1539751181266 2 connected 10923-16383 ac153a3c1fb10d9d502b153c32dec65c85b2f97c 192.168.81.100:9002 slave fceba6001b95e2169ddd6622436b213324fe8f77 0 1539751182272 6 connected 71f5695dc1f4322c8ea9066d1b3cd8bb0ab7a329 192.168.81.100:9001 slave cf74b2d9570665b74525802462c74cf2e072ef99 0 1539751180255 5 connected cf74b2d9570665b74525802462c74cf2e072ef99 127.0.0.1:9000 myself,master - 0 0 1 connected 0-5460 6.Redis Cluster扩容集群 6.1 在192.168.81.100虚拟机上准备新节点 [root@host1 config]# ls add_slots.sh redis_9000.conf redis_9001.conf redis_9002.conf [root@host1 config]# sed 's/9000/9003/g' redis_9000.conf > redis_9003.conf # 生成配置文件 [root@host1 config]# redis-server /opt/config/redis_9003.conf # 指定配置文件启动redis-server [root@host1 config]# ps aux | grep redis-server # 查看redis-server的进程 root 2553 0.2 0.7 142904 7552 ? Ssl 12:23 0:12 redis-server 0.0.0.0:9000 [cluster] root 2557 0.2 0.7 142904 7548 ? Ssl 12:23 0:13 redis-server 0.0.0.0:9001 [cluster] root 2561 0.2 0.7 142904 7556 ? Ssl 12:23 0:13 redis-server 0.0.0.0:9002 [cluster] root 2596 0.1 0.5 142904 5336 ? Ssl 13:53 0:00 redis-server 0.0.0.0:9003 [cluster] root 2600 0.0 0.0 112648 964 pts/0 R+ 13:53 0:00 grep --color=auto redis-server 6.2 在192.168.81.101虚拟机上生成配置文件,手动扩容集群 [root@mysql config]# redis-cli -p 9000 cluster meet 127.0.0.1 9003 # 对新添加节点执行meet操作 OK [root@mysql config]# redis-cli -p 9000 cluster meet 192.168.81.100 9003 # 对新添加节点执行meet操作 OK [root@mysql config]# redis-cli -p 9000 cluster nodes # 查看集群节点信息 6f369311b0ca4c503f337c4bb23424eed3eeb188 127.0.0.1:9002 slave cb8c114d44d289687798508232d31e0a065fdab5 0 1539755696566 4 connected ac153a3c1fb10d9d502b153c32dec65c85b2f97c 192.168.81.100:9002 slave fceba6001b95e2169ddd6622436b213324fe8f77 0 1539755699589 6 connected 71f5695dc1f4322c8ea9066d1b3cd8bb0ab7a329 192.168.81.100:9001 slave cf74b2d9570665b74525802462c74cf2e072ef99 0 1539755694553 5 connected 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 192.168.81.100:9003 master - 0 1539755697570 7 connected cb8c114d44d289687798508232d31e0a065fdab5 192.168.81.100:9000 master - 0 1539755694553 4 connected 5461-10922 fceba6001b95e2169ddd6622436b213324fe8f77 127.0.0.1:9001 master - 0 1539755698572 2 connected 10923-16383 cf74b2d9570665b74525802462c74cf2e072ef99 192.168.81.101:9000 myself,master - 0 0 1 connected 0-5460 2ff22acb1e006b9881abc80238e15b4e3fcefbef 127.0.0.1:9003 master - 0 1539755695560 0 connected [root@mysql config]# redis-cli -p 9000 cluster info # 查看集群信息 cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:8 cluster_size:3 cluster_current_epoch:7 cluster_my_epoch:1 cluster_stats_messages_sent:11829 cluster_stats_messages_received:11829 [root@mysql config]# redis-cli -p 9003 cluster replicate 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 # 新添加节点设置主从关系 OK [root@mysql config]# redis-cli -p 9003 cluster nodes # 查看集群中节点信息 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 192.168.81.100:9003 master - 0 1539756040013 7 connected 2ff22acb1e006b9881abc80238e15b4e3fcefbef 192.168.81.101:9003 myself,slave 27266dcfd098dfe2a42361d6ab59edf8fb9f5413 0 0 0 connected cb8c114d44d289687798508232d31e0a065fdab5 192.168.81.100:9000 master - 0 1539756035980 4 connected 5461-10922 ac153a3c1fb10d9d502b153c32dec65c85b2f97c 192.168.81.100:9002 slave fceba6001b95e2169ddd6622436b213324fe8f77 0 1539756037488 2 connected cf74b2d9570665b74525802462c74cf2e072ef99 127.0.0.1:9000 master - 0 1539756040516 1 connected 0-5460 6f369311b0ca4c503f337c4bb23424eed3eeb188 127.0.0.1:9002 slave cb8c114d44d289687798508232d31e0a065fdab5 0 1539756038998 4 connected fceba6001b95e2169ddd6622436b213324fe8f77 127.0.0.1:9001 master - 0 1539756041017 2 connected 10923-16383 71f5695dc1f4322c8ea9066d1b3cd8bb0ab7a329 192.168.81.100:9001 slave cf74b2d9570665b74525802462c74cf2e072ef99 1539756042024 1539756037992 1 connected 6.3 在192.168.81.101虚拟机上生成配置文件,使用redis-trib.rb工具扩容集群说明:
向集群中添加192.168.81.100:9003和192.168.81.101:9003节点