解决服务器Redis无法连接问题
2023.3.21
找到你的redis配置文件,进行以下步骤修改。(本人的在/etc/redis.conf
,如果找不到,直接创建一个,然后度娘一个默认的redis配置文件粘贴上去即可,启动时使用命令redis-cli +文件路径
,下文会讲)
- 修改bind,默认为
bind 127.0.0.1
,将其注释(前面加个#
),如果没有找到bind 127.0.0.1
或已经注释,跳过此步。
# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
# bind 127.0.0.1
- 关闭保护模式,默认为
protected-mode yes
,将yes
修改为no
,如果没有找到protected-mode yes
,可以随意另起一行添加protected-mode no
;或已经修改为protected-mode no
,跳过此步。
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
# "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no
- 如果有需求,设置密码(没有需求则跳过),添加一行
requirepass 123456
,作用是设置连接密码为123456,如有需求可以修改密码
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass 123456
- 重启你的redis,在安装redis的位置使用命令
redis-cli shutdown
,然后再使用命令./redis-server /etc/redis.conf
启动redis,请注意,如果你修改的配置文件在其他地方:例如/opt/redis/redis.conf
,请你使用./redis-server /opt/redis/redis.conf
启动redis。
如果启动后无法进行其他操作,请使用Ctrl+C
结束该进程后,找到刚刚修改的配置文件,找到并修改为或者添加 daemonize=yes
(稍微提一嘴,windows版本不支持),然后再启动redis。文章来源:https://www.toymoban.com/news/detail-466023.html
daemonize=yes
最后关闭你的防火墙,或者将redis加入白名单,这里只做关闭处理,这一步操作因linux版本而异文章来源地址https://www.toymoban.com/news/detail-466023.html
systemctl status firewalld.service #查看防火墙状态
systemctl stop firewalld.service #关闭防火墙
到了这里,关于解决服务器Redis无法连接问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!