• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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,重启服务即可。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持极客世界。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MySQL详细汇总常用函数发布时间:2022-02-08
下一篇:
MySQL中CURRENT_TIMESTAMP的使用方式发布时间:2022-02-08
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap