服务器部署redis后访问遇到的问题及解决
前言
服务器部署redis后续问题记录
问题一:init redis failure:dial tcp xx.xxx.xx.xx:6379: connect: connection refused
问题
接口连接返回错误,连接拒绝
解决
原因是我的redis.conf中的bind 127.0.0.1在配置文件中没有注释掉,奇怪,昨天安装的时候查看还是注释掉的,可能手滑??,反正重新注释就可以访问了
问题二:DENIED Redis is running in protected mode
问题
如下所示,程序连接redis报错,根据错误信息,init redis失败:拒绝的redis正在保护模式下运行,因为已启用保护模式,未指定绑定地址,未向客户端请求身份验证密码。在此模式下,只能从环回接口接受连接。如果要从外部计算机连接到Redis,可以采用以下解决方案之一:1)通过从服务器运行的同一主机连接到Redis,从环回接口发送命令“CONFIG SET protected mode no”,即可禁用受保护模式,然而,若你们这样做的话,请确保Redis不能从互联网上公开访问。使用“配置重写”将此更改永久化。2) 或者,您可以通过编辑Redis配置文件,将受保护模式选项设置为“否”,然后重新启动服务器来禁用受保护模式。3) 如果只是为了测试而手动启动服务器,请使用“–protectedmodeno”选项重新启动服务器。4) 设置绑定地址或身份验证密码。注意:您只需要执行上述操作之一,服务器就可以开始接受来自外部的连接。
init redis failure:DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command CONFIG SET protected-mode no from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to no, and then restarting the server. 3) If you started the server manually just for testing, restart it with the --protected-mode no option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
解决
redis运行在受保护模式,需要redis命令行下作设置:config set protected-mode no 进入redis-cli中设置protected-mode为no即可
问题三:init redis failure:ERR Client sent AUTH, but no password is set
问题
接口访问返回错误,但是我在配置文件中分明写好了密码,在后端接口也配置了相关访问参数
解决
可能是我启动的方式不对,我开始选择./redis-server &启动,由错误二可知是由于我没有带配置文件启动,redis没有读取到我的配置信息,所以解决方式如下同。
问题四:Warning: no config file specified, using the default config
问题
因redis启动方式有多种,我开始选择./redis-server &启动,没有带配置文件,所以出现了该问题(警告:没有指定配置文件,使用默认配置。要指定配置文件)。
解决
./redis-server 配置文件路径启动即可
./redis-server /usr/local/redis/redis-5.0.7/etc/redis.conf