环境:
Redis 4.0.1
CentOS 6.9
jdk1.8
dependencies:commons-pool2-2.4.2;jedis-2.9.0
今天搞了将近一个小时的时间用于排查错误,现将排查步骤记录下来:
一、一般情况下。redis默认端口号6379是不允许进行远程连接的,所以在防火墙中设置6379开启远程服务:
/sbin/iptables -I INPUT -p tcp -dport 6379 -j ACCEPT
/etc/rc.d/init.d/iptables save
二、重启redis
到安装目录(前提是bin下面有redis.conf,没有就到解压缩出来的包中复制一个)
./redis-cli shutdown
./redis-server redis.conf
三、如果还不行,修改redis.conf文件中的bind 127.0.0.1,将其注释掉 ,并restart redis
四、如果出现
- 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: 。。。
那么一般情况下有两种解决方案:
在redis.conf中:
1)设置 protected-mode no
2)设置密码 requirepass xxxxxx(或者到redis客户端set requirepass xxxxxx);
到这里基本上都可以使用了。