java用jedis连接redis碰到的问题

 

小白的我今天初学redis在用jedis连接自己虚拟机上面的redis碰到了几个问题

通过这串代码测试

java用jedis连接redis碰到的问题

异常

 Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out 


网上说把防火墙6379端口打开就可以解决       vi iptables    在文件里加上   -A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT          

重启了防火墙后继续执行原来的代码


碰到异常:

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect 

java用jedis连接redis碰到的问题

网上说修改redis.conf配置文件中bind的内容注释掉就好了

我照着做了之后还是没有解决这个问题

后来接着找解决的办法后来看到用人使用telent 命令测试所以我也照着做

结果没有找到telnet这个命令  需要通过  yum  install telnet  安装

安装好后我 执行 telnet  192.168.154.128:6379应为我的ip是192.168.154.128

结果得到

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.conf参数protected-mode no


弄完 重启redis后  就成功连接上了以上是我碰到的问题。

希望碰到和我一样问题的朋友可以得到点帮助。



更多关于更多远程连接redis的问题可以访问http://blog.csdn.net/feeltouch/article/details/53875280我也是看了他列举的内容才成功的