Redis在VMware虚拟机中本地连接调试错误解决

10,052次阅读
33 条评论

共计 1700 个字符,预计需要花费 5 分钟才能阅读完成。

前言

在今天使用 Redis 的时候,在 VMware 虚拟机里面安装的 centos 6.5 系统,在其之上安装了 redis 3.2.9,之后使用 java 进行链接操作的时候就出现了一些连接问题,下面就罗列出遇到的问题以及解决办法。

正文

问题一

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out

出现以上错误,根据提示可以知道是连接超时,是因为 linux 系统没有将 redis 默认端口 6379 进行开放,那么我们只需要打开对应端口即可:

cd /etc
vim sysconfig/iptables

然后在其中插入以下一行内容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

然后保存,再将服务重启一下即可:

service iptables restart

问题二

redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to ‘no’, and then restarting the server. 3) If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

根据上方的内容阐述大概就是 Redis 运行在保护模式,只允许在本地回路访问,那么我们只需要将保护模式关闭再重启即可:

# 打开 redis.conf
vim redis.conf
#找到 protected-mode yes,将它改为:protected-mode no
#然后保存,退出 vim
#关闭 redis
./bin/redis-cli shutdown
#开启 redis
./bin/redis-server ./redis.conf

后记

在写项目的时候,遇到的奇葩问题千千万,也许是一个很不起眼的错误就让整个系统崩溃,不过只要静下心了,一切都是过眼云烟~ Redis 在 VMware 虚拟机中本地连接调试错误解决

正文完
使用官方微信小程序体验更多功能
post-qrcode
 8
憧憬Licoy
版权声明:本站原创文章,由 憧憬Licoy 于2017-06-03发表,共计1700字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(33 条评论)
两法衔接 评论达人 LV.1
2017-06-30 14:56:23 回复

感觉好难啊

 Windows  Chrome  中国河南省郑州市联通
免费福利 评论达人 LV.1
2017-06-26 20:27:59 回复

好复杂啊!!!!!

 Windows  Chrome  中国上海上海市电信
boke112导航 评论达人 LV.1
2017-06-23 09:03:17 回复

看起来好复杂,所以我一直都不敢折腾系统和服务器,主题倒是偶尔可以折腾一下

 Windows  Chrome  中国广西南宁市电信
橘子书 评论达人 LV.1
2017-06-22 10:03:55 回复

高能,懂不起。 :lol:

 Windows  Chrome  中国福建省漳州市电信
明月登楼 评论达人 LV.2
2017-06-17 09:48:23 回复

过来look一下,博主好久没有更新了!

 Windows  Chrome  中国河南省南阳市电信
闲鱼 评论达人 LV.2
2017-06-16 14:44:03 回复

:sad: 上班太忙了,都没什么机会折腾

 iPad  Safari  中国湖南省常德市联通
冷知识 评论达人 LV.1
2017-06-15 07:14:08 回复

这看都看不懂

 Windows  Firefox  中国北京北京市联通
邻水楼盘网 评论达人 LV.1
2017-06-07 10:06:17 回复

虚拟主机以前经常用,后来工作需要就没用了。测试软件什么的绝对是最方便的。以前记得1G内存都转一个虚拟主机,现在的电脑配置高绝对更爽

 Windows  Chrome  中国重庆重庆市联通
毕业论文 评论达人 LV.1
2017-06-06 19:20:01 回复

感谢楼主的分享

 Windows  Firefox  伊朗
明月登楼 评论达人 LV.2
2017-06-05 18:57:18 回复

不得不说Redis真的好吃内存呀!

 Windows  Chrome  中国河南省南阳市电信