1. 查看报错
应用日志关键报错:
CLUSTERDOWN Hash slot not served
set key
127.0.0.1:6379> set cike 567
(error) CLUSTERDOWN Hash slot not served
get key
127.0.0.1:6379> get cike
(error) CLUSTERDOWN The cluster is down
cluster info
127.0.0.1:6379> cluster info
cluster_state:fail
cluster slots
127.0.0.1:6379> cluster slots
1) 1) (integer) 726
2) (integer) 726
3) 1) ""
2) (integer) 6379
3) "5b77786e05107ef67e64ed2bdd32267ffa38812f"
2) 1) (integer) 12595
2) (integer) 12595
3) 1) ""
2) (integer) 6379
3) "5b77786e05107ef67e64ed2bdd32267ffa38812f"
3) 1) (integer) 15461
2) (integer) 15461
3) 1) ""
2) (integer) 6379
3) "5b77786e05107ef67e64ed2bdd32267ffa38812f"
2. 冷静分析
去百度,千篇一律的修复、移除等集群操作,但我时单机的。终于找到一篇博客得到解决之法, 原理很简单,查看redis的槽位,缺啥补啥。
3. 着手解决
其实这个方法是鄙人发明的,那我们来看看这个博主当时是怎么从我这学的。
首先,使用命令执行槽位恢复
redis-cli -h 127.0.0.1 -p 6379 cluster addslots 0
redis-cli -h 127.0.0.1 -p 6379 cluster addslots 1
redis-cli -h 127.0.0.1 -p 6379 cluster addslots 2
redis-cli -h 127.0.0.1 -p 6379 cluster addslots 16383
这样写16384条,写完晚上的烤羊腿都吃不到了。
急中生智:写脚本生成16384条命令:
for ((i=0;i<=16383;i++));
do
echo "redis-cli -h 127.0.0.1 -p 6379 cluster addslots "${i} >> /tmp/repai_redis.sh;
done
执行脚本
sh repai_redis
查看集群槽位:
127.0.0.1:6379> cluster addslots 0
OK
127.0.0.1:6379> cluster slots
1) 1) (integer) 0
2) (integer) 16383
3) 1) ""
2) (integer) 6379
3) "5b77786e05107ef67e64ed2bdd32267ffa38812f"
这才是正确的槽位分配
查看集群状态:
127.0.0.1:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:1
cluster_current_epoch:0
cluster_my_epoch:0
cluster_stats_messages_sent:0
cluster_stats_messages_received:0
127.0.0.1:6379> set ww 22
OK
127.0.0.1:6379> get ww
"22"
https://blog.csdn.net/mfanoffice2012/article/details/105148134