前言
在今天使用 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进程总是无缘无故的被干掉!无语了!
@明月学习笔记Blog 可能是内存满了吧
很棒~~~·
不错,感谢博主分享!!
朋友 交换链接吗
@bandwagonhost指南 不好意思,贵站暂不符合本站友链对象。
不错的代码!!!!
@网赚
« 1 2
Chatroulette-全世界随机视频聊天网站
SpringCloud使用Zuul出现“Forwarding error”错误解决方法
Puock主题常见问题汇总
IntelliJ IDEA下将JavaWeb打包成war包并发布到tomcat步骤说明
LiRecord留言板系统V2.0正式版发布
Puock主题常见问题汇总
由开源项目gogo-protobuf寻找新组织接手引发的思考
Sa-Token实现注解模式的匿名访问
在浏览器端离线给证件照加水印
岛屿数量计算中的DFS和BFS的应用