解决服务器Redis无法连接问题

解决服务器Redis无法连接问题

2023.3.21

找到你的redis配置文件,进行以下步骤修改。(本人的在/etc/redis.conf,如果找不到,直接创建一个,然后度娘一个默认的redis配置文件粘贴上去即可,启动时使用命令redis-cli +文件路径,下文会讲)

  1. 修改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
  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
  1. 如果有需求,设置密码(没有需求则跳过),添加一行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
  1. 重启你的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。

 daemonize=yes

最后关闭你的防火墙,或者将redis加入白名单,这里只做关闭处理,这一步操作因linux版本而异

systemctl status firewalld.service  #查看防火墙状态
systemctl stop firewalld.service    #关闭防火墙
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值