解决Redis无法使用ip访问(127.0.0.1可以访问)的情况
遇到主机redis使用localhost和127.0.0.1都可以访问,但是使用主机ip(192.168.1.103)访问就连接不上
·

遇到主机redis使用localhost和127.0.0.1都可以访问,但是使用主机ip(192.168.1.103)访问就连接不上
windows版解决:
1. 打开redis.windows.config文件将 NETWORK 下 bind 127.0.0.1 注释掉;或者更改为 bind 192.168.1.103 0.0.0.0
并将protected-mode yes 改为 protected-mode no;
2. 同理修改redis.windows.server.config文件中相应内容;
3. 重启Redis服务,即可使用IP访问 Redis了;
linux解决:
找到Redis的配置文件,通常在/etc/redis/redis.conf或/usr/local/redis/redis-6.2.6/redis.conf
路径下,使用编辑器打开该文件,
把 bind 127.0.0.1 注释掉;或者更改为 bind 192.168.1.103 0.0.0.0
并将protected-mode yes 改为 protected-mode no
保存文件并重启redis 使配置生效
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 192.168.1.103
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# 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
注意:如果在生产环境中,只有主机访问redis,则不需要修改,保证redis数据安全,使用localhost或127.0.0.1访问即可!
更多推荐



所有评论(0)