利用Jedis远程链接Redis出错解决方案

环境:redis

Redis 4.0.1tcp

CentOS 6.9oop

jdk1.8ui

dependencies:commons-pool2-2.4.2;jedis-2.9.0    this

 

今天搞了将近一个小时的时间用于排查错误,现将排查步骤记录下来:rest

1、通常状况下。redis默认端口号6379是不容许进行远程链接的,因此在防火墙中设置6379开启远程服务:server

/sbin/iptables -I  INPUT -p tcp  -dport  6379  -j ACCEPTip

/etc/rc.d/init.d/iptables saveci

2、重启redis it

    到安装目录(前提是bin下面有redis.conf,没有就到解压缩出来的包中复制一个)

./redis-cli shutdown

./redis-server redis.conf

3、若是还不行,修改redis.conf文件中的bind 127.0.0.1,将其注释掉 ,并restart redis

4、若是出现

  1.  DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified,   
  2. 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:   。。。

    那么通常状况下有两种解决方案:

    在redis.conf中:

    1)设置 protected-mode no

    2)设置密码 requirepass  xxxxxx(或者到redis客户端set requirepass xxxxxx);

 

到这里基本上均可以使用了。

相关文章
相关标签/搜索