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


Posted in Redis onJuly 07, 2021

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 相关文章推荐
redis连接被拒绝的解决方案
Apr 12 Redis
为Java项目添加Redis缓存的方法
May 18 Redis
Redis 哨兵集群的实现
Jun 18 Redis
压缩Redis里的字符串大对象操作
Jun 23 Redis
Redis性能监控的实现
Jul 09 Redis
解析redis hash应用场景和常用命令
Aug 04 Redis
Redis Cluster 集群搭建你会吗
Aug 04 Redis
Redis集群节点通信过程/原理流程分析
Mar 18 Redis
redis复制有可能碰到的问题汇总
Apr 03 Redis
Redis 限流器
May 15 Redis
redis protocol通信协议及使用详解
Jul 15 Redis
Redis主从复制操作和配置详情
Sep 23 Redis
redis客户端实现高可用读写分离的方式详解
使用Redis实现实时排行榜功能
Jul 02 #Redis
redis使用不当导致应用卡死bug的过程解析
Redis主从配置和底层实现原理解析(实战记录)
浅谈Redis中的RDB快照
聊一聊Redis与MySQL双写一致性如何保证
k8s部署redis cluster集群的实现
Jun 24 #Redis
You might like
PHP中strlen()和mb_strlen()的区别浅析
2014/06/19 PHP
PHP使用POP3读取邮箱接收邮件的示例代码
2020/07/08 PHP
js 纯数字不重复排列的另类方法
2010/07/17 Javascript
javascript中注册和移除事件的4种方式
2013/03/20 Javascript
当前页禁止复制粘贴截屏代码小集
2013/07/24 Javascript
深入理解JavaScript系列(22):S.O.L.I.D五大原则之依赖倒置原则DIP详解
2015/03/05 Javascript
js实现可输入可选择的select下拉框
2016/12/21 Javascript
jQuery插件ajaxFileUpload使用详解
2017/01/10 Javascript
bootstrap paginator分页前后台用法示例
2017/06/17 Javascript
jQuery实现table中两列CheckBox只能选中一个的示例
2017/09/22 jQuery
微信小程序实现流程进度的图样式功能
2018/01/16 Javascript
nodejs+mongodb aggregate级联查询操作示例
2018/03/17 NodeJs
vue-router beforeEach跳转路由验证用户登录状态
2018/12/26 Javascript
Vue render函数实战之实现tabs选项卡组件
2019/04/22 Javascript
vue+iview框架实现左侧动态菜单功能的示例代码
2020/07/23 Javascript
javascript实现打砖块小游戏(附完整源码)
2020/09/18 Javascript
[01:56]《DOTA2》中文配音CG
2013/04/22 DOTA
python检测服务器是否正常
2014/02/16 Python
Python中实现两个字典(dict)合并的方法
2014/09/23 Python
Python实现的多线程http压力测试代码
2017/02/08 Python
window下eclipse安装python插件教程
2017/04/24 Python
Python装饰器原理与用法分析
2018/04/30 Python
使用Python快乐学数学Github万星神器Manim简介
2019/08/07 Python
Python 异步协程函数原理及实例详解
2019/11/13 Python
python实现大战外星人小游戏实例代码
2019/12/26 Python
python使用Thread的setDaemon启动后台线程教程
2020/04/25 Python
网络安全类面试题
2015/08/01 面试题
医院后勤自我鉴定
2013/10/13 职场文书
实习鉴定评语
2014/01/19 职场文书
庆元旦迎新年广播稿
2014/02/18 职场文书
利群广告词
2014/03/20 职场文书
师德师风自查总结
2014/10/14 职场文书
生日赠语
2015/06/23 职场文书
新教师2015年度工作总结
2015/07/22 职场文书
2016年最美孝心少年事迹材料
2016/02/26 职场文书
行政后勤人员工作计划应该怎么写?
2019/08/16 职场文书