主页 > 知识库 > redis不能访问本机真实ip地址的解决方案

redis不能访问本机真实ip地址的解决方案

热门标签:网站排名优化 百度竞价排名 呼叫中心市场需求 铁路电话系统 AI电销 服务外包 地方门户网站 Linux服务器

redis无法访问本机真实ip地址

1.我在进行用jedis来连接redis时出现了问题:

我用Jedis jedis = new Jedis("127.0.0.1",6379);可以成功连接,但是我如果把127.0.0.1换成的本机地址如192.168.1.103发现会报错.

2.解决这个问题

要修改redis.windows.conf的配置文件(说明一下我的redis是在windows版的)

这里要改两个地方:

  • 1.修改bind的ip
  • 2.修改protected-mode yes为protected-mode no

我的修改如下

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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

上面的代码可以看到我的修改了哪些东西,之后再尝试连接一下。

无法通过ip访问redis服务

尝试在本机以及其他主机通过ip来访问redis服务时,一直出现错误,无法通过IP访问redis服务。

究其原因:

redis.conf文件中配置了访问限制,通过bind来限制了ip访问,默认为127.0.0.1

注释掉bind之后,本地可以通过ip访问,但是其他主机无法访问,在redis3之后,有一个protected-mode 参数,默认开启 yes,改成no,重启服务即可。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
  • Redis IP地址的绑定的实现
  • 解决webpack无法通过IP地址访问localhost的问题
  • 详解java 客户端链接不上redis解决方案

标签:衡水 黄山 崇左 湘潭 仙桃 铜川 兰州 湖南

巨人网络通讯声明:本文标题《redis不能访问本机真实ip地址的解决方案》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266