redis5手动原生搭建cluster

redis 5.0

安装并设置cluster

dnf -y install redis

sed -i.bak -e 's/bind 127.0.0.1/bind 0.0.0.0/' -e '/masterauth/a masterauth 123456' -e '/# requirepass/a requirepass 123456' -e '/# cluster-enabled yes/a cluster-enabled yes' -e '/# cluster-config-file nodes6379.conf/a cluster-config-file nodes-6379.conf' -e '/cluster-require-fullcoverage yes/c cluster-require-full-coverage no' /etc/redis.conf

执行meet 互相通信

redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.18 6379
OK
redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.38 6379
OK
redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.48 6379
OK
redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.58 6379
OK
redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster meet 10.0.0.68 6379
OK

此时信息

redis-cli -h 10.0.0.8 -a 123456 --no-auth-warning cluster info

cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:0
cluster_current_epoch:5
cluster_my_epoch:3
cluster_stats_messages_ping_sent:297
cluster_stats_messages_pong_sent:288
cluster_stats_messages_meet_sent:5
cluster_stats_messages_sent:590
cluster_stats_messages_ping_received:288
cluster_stats_messages_pong_received:302
cluster_stats_messages_received:590

分配slot槽位

cat addslot.sh
#!/bin/bash

host=$1
port=$2
start=$3
end=$4
pass=123456

for slot in `seq ${start} ${end}`;do
   echo slot:$slot
  redis-cli -h ${host} -p ${port} -a ${pass} --no-auth-warning cluster addslots ${slot}
done
bash addslot.sh 10.0.0.8 6379 0 5461
bash addslot.sh 10.0.0.18 6379 5462 10922
bash addslot.sh 10.0.0.38 6379 10923 16383

查看节点信息

redis-cli -a 123456 --no-auth-warning cluster nodes

 

重新分配slot,与添加节点相同

redis-cli -a 123456 --cluster reshard 10.0.0.8:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 10.0.0.8:6379)
M: cbb819651fb976f73e457ec5ec3fce64690e0c27 10.0.0.8:6379
   slots:[0-5461] (5462 slots) master
M: c3b28695d583f81f57a7c1514fdedeac6ac10272 10.0.0.58:6379
   slots: (0 slots) master
M: 8b0f101486207110497e9b4c4bbef498ac83e2ef 10.0.0.18:6379
   slots:[10924-16383] (5460 slots) master
M: df4648d7bab348b8974e7be3f2df30bb34506dc9 10.0.0.48:6379
   slots: (0 slots) master
M: 013ece39f1c05d6fa5bdb3f3355b26996fa27f11 10.0.0.68:6379
   slots: (0 slots) master
M: 0d56eb175164316da69da3e0f46c88e33cf763bd 10.0.0.38:6379
   slots:[5462-10923] (5462 slots) master
[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)? 5462    #移动多少
What is the receiving node ID? 0d56eb175164316da69da3e0f46c88e33cf763bd    #输入接收ID
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: 8b0f101486207110497e9b4c4bbef498ac83e2ef        #all为从所有节点
Source node #2: done

Do you want to proceed with the proposed reshard plan (yes/no)?yes

 

 

 

设置主从

redis-cli -h 10.0.0.48 -a 123456 --no-auth-warning cluster replicate cbb819651fb976f73e457ec5ec3fce64690e0c27

redis-cli -h 10.0.0.58 -a 123456 --no-auth-warning cluster replicate 8b0f101486207110497e9b4c4bbef498ac83e2ef

redis-cli -h 10.0.0.68 -a 123456 --no-auth-warning cluster replicate 0d56eb175164316da69da3e0f46c88e33cf763bd

 

 

posted @ 2020-10-25 14:23  天际之上可有蓝天  阅读(190)  评论(0编辑  收藏  举报