创建redis-cluster节点
修改redis.conf将有关cluster的配置放出来即可通过redis-server (配置文件)以动redis-cluster节点,但是一个一个启动蛮累的 所以直接使用shell脚本(一劳永益)注意启动不同的节点,注意修改不同的端口信息
代码语言:javascript复制for port in {8000..8005};do redis-cli -c -p $port shutdown;done;
rm -rf dump*;
rm -rf appendonly*;
rm -rf nodes*;
for port in {8000..8005};do redis-server $port/redis-cluster.conf;done;
meet碰撞
以集群方式启动redis之后,可以通过cluster nodes 指令发现,redis之间并无联系,所以要手动对集群进行
代码语言:javascript复制[root@10-42-63-188 redis-3.2.11]# redis-cli -h 10.42.63.188 -p 8000 -c
10.42.63.188:8000> cluster meet 10.42.63.188 8005
分配槽道
以集群方式启动redis之后,可以通过cluster nodes 指令发现,redis之间并无联系,所以要手动对集群进行 搭建并分配槽道
代码语言:javascript复制执行cluster info 发现并未分配槽道
10.42.63.188:8002> cluster info
cluster_state:fail
cluster_slots_assigned:0 以分配槽道0
cluster_slots_ok:0 状态ok的槽道0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:0
cluster_current_epoch:5
cluster_my_epoch:0
cluster_stats_messages_sent:380
cluster_stats_messages_received:380
10.42.63.188:8002>
进去主节点执行cluster addslots 槽道号…(16384个槽道号岂不是要累死) so 执行shell脚本
代码语言:javascript复制for slot in {2..5460};do redis-cli -c -h 10.42.63.188 -p 8000 cluster addslots $slot;done;
for slot in {5461..10922};do redis-cli -c -h 10.42.63.188 -p 8001 cluster addslots $slot;done;
for slot in {10923..16383};do redis-cli -c -h 10.42.63.188 -p 8002 cluster addslots $slot;done;
主从复制
进去任意一个集群中的节点执行cluster nodes发现6个节点都是master主节点,没有主从复制,不满足高可用。进入没有分配槽道号的节点直接cluster replicate 挂载的主节点ID 即可成为从节点
代码语言:javascript复制登陆从节点执行 cluster replicate 主节点ID 实现主从复制
[root@10-42-63-188 redis-3.2.11]# redis-cli -h 10.42.63.188 -p 8005 -c
10.42.63.188:8005> CLUSTER REPLICATE ee41f2381e0c4a974ef1f68dde74d1c51ac0270e
OK
10.42.63.188:8005> cluster nodes
61472a03d643ec482add31ce5e8669dd4bb91ee3 10.42.63.188:8000 master - 0 1573091212855 1 connected
91a9359b404e5d735e6b436a7ce03f3fb35b4cb0 10.42.63.188:8001 master - 0 1573091212354 2 connected
91f1ec63749be513426456cc4d6d0af31b6efa23 10.42.63.188:8003 slave 61472a03d643ec482add31ce5e8669dd4bb91ee3 0 1573091213356 3 connected
ee41f2381e0c4a974ef1f68dde74d1c51ac0270e 10.42.63.188:8002 master - 0 1573091211352 0 connected
8665be297593e5b7d003b780d5e75d523bc4db73 10.42.63.188:8004 slave 91a9359b404e5d735e6b436a7ce03f3fb35b4cb0 0 1573091209347 4 connected
ca942951f064679fed59d2ebafc48910005acb89 10.42.63.188:8005 myself,slave ee41f2381e0c4a974ef1f68dde74d1c51ac0270e 0 0 5 connected
10.42.63.188:8005>
三主三从的高可用分布式redis集群搭建完毕