redis:各种错误

1、Could not connect to Redis at 127.0.0.1:6379: Connection refused not connected>

几种情况:

1)原因:redis服务没启动

解决方案:

redis-server /usr/local/redis/redis-6.2.13/redis.conf &

2)出现于:redis-cli shutdown时

现场图:

原因:当前的登录者为192.168.10.20,就只能从192这个IP关闭

解决方案:用192.168的用户关闭连接

redis-cli -h 192.168.10.20 -a Wrt65536 shutdown

3)原因:在redis.conf文件中,通过bind指定了只能由哪个IP登录本redis服务器,此时如果用其他IP登录就会报该错误

解决方案(3种):把redis.conf中,

#1、把bind注释掉
#2、bind你想要登录的那个IP
#3、bind * 允许所有IP登录

2、Error: Connection reset by peer

3、redis Error: Broken pipe

4、(error) DENIED Redis is running in protected mode because protected mode is enabled (关闭保护模式没生效)

5、无法连接到192.168.xx.xx

问题2345最后的原因和解决方案相同:

原因:检查配置文件和通过redis-cli CONFIG GET获取到的配置项不一致(特别是protected-mode)

 

因为我在启动redis时是用以下指令

./redis-server & ../redis.config

实际上应该用

./redis-server ../redis.config &

因为把&放在中间时,后边的redis.config不会一起加入到后台进程中执行,这导致redis.conf文件中的设置项和通过redis-cli CONFIG GET获取到的不一致

 

6、AUTH failed: ERR AUTH called without any password configured for the default user. Are you sure your configuration is correct?

出现于:redis-cli -h 192.168.10.11 -a Wrt65536

现场图:

原因:1)conf文件中没设置密码项requirepass;2)设置了密码项requirepass但是这里输错了;3)设置了requirepass(本机登录密码),但是却输成了masterauth(主机登录密码)

 

7、sentinel directive while not in sentinel mode

解决方案来源:sentinel directive while not in sentinel mode问题解决方案_牛奋lch的博客-CSDN博客

*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 2
>>> 'sentinel monitor mymaster 127.0.0.1 6379 2'
sentinel directive while not in sentinel mode

原因:没写最后的--sentinel

解决方案:启动sentinel的指令写为:

redis-server sentinel.conf --sentinel
或
redis-sentinel sentinel.conf

 

8、哨兵模式下,一启动sentinel和redis就报+sdown master mymaster 192.168.x.x

+sdown:主观下线

解决方案来源:redis哨兵启动出现 +sdown master mymaster 192.168.x.x-其他-IT技术

解决方案:三个哨兵配置文件sentinel.conf中都要添加auth-pass项,因为redis.conf中有masterpass项

sentinel auth-pass mymaster xxxx

9、Failed listening on port 26379

原因:多次重复启动(未关闭)redis-server

10、按照8的方式解决之后,master上的哨兵可以检测到master正常启动,不会立刻报+sdown,但是slave上的哨兵却无法检测到master,slave上还在报+sdown master

解决方案参考(按照对解决问题的贡献排序):

redis多台独立虚拟机作为哨兵时,尽管配置正确,但还是出现哨兵三十秒后自动下线的原因,也就是+sdown sentinel的原因_Kaltsit____的博客-CSDN博客

Redis哨兵模式启动30秒后日志出现+sdown slave和+sdown master或+sdown sentinel_redis sdown_Ken_1115的博客-CSDN博客

【redis哨兵模式】解决redis哨兵模式无法切换的问题 - 知乎

原因:①端口26379外界无法访问;②防火墙没关;③sentinel.conf配置文件中没设置announce-ip和announce-port

解决方案:

①端口26379外界无法访问:

使用firedwalld服务开启26379端口

#防火墙开放26379端口
firewall-cmd --add-port=26379/tcp --permanent

②防火墙没关

没想到在用防火墙解决了方案1之后,还要把防火墙关上

systemctl stop firewalld

③sentinel.conf配置文件中没设置announce-ip和announce-port

关于annouce-ip和annouce-port,在sentinel.conf中可以看到这样一段说明:

在NAT网络中,外界会通过一个非本机地址访问Sentinel,此时这两项就会起作用。

当指定了announce-ipannounce-port时,Sentinel就会采用设定的IP和port非自动检测的。如果只指定了其中之一,那么剩下那个就会用自动配置。

我的虚拟机配置了双网卡,外界要通过NAT网络访问虚拟机,因此这一项必须指定,ip就是sentinel所在的机器的ip,192开头的那个,port就是26379(应该也可以配成别的port,但我没有尝试)。

sentinel annouce-ip 192.168.10.20
sentinel annouce-port 26379

 

以上配置完毕后重启redis-server和redis-sentinel,就可以正常切换了。

 

11、集群模式下报错*** FATAL CONFIG FILE ERROR (Redis 6.2.13) ***Reading the configuration file, at line 2062>>> 'replicaof 192.168.10.12 6379'

原因及解决方案:这是哨兵模式下,在conf文件末尾自动生成的项,在集群模式中需要删去

12、[ERR] Node 127.0.0.1:6001 NOAUTH Authentication required.

在conf文件中,通过选项requirepass和masterauth指定了密码,因此登录节点时需要指定密码,把这两项注释掉重启服务即可。

 

posted @ 2023-08-15 10:24  ShineLe  阅读(1656)  评论(0编辑  收藏  举报