您的位置:首页 > 数据库 > Redis

Could not connect to Redis No route to host问题解决

2017-02-06 11:13 791 查看
局域网内访问另外一台服务器上的redis 报错 Could not connect to Redis No route to host问题解决 ;
发现是防火墙问题。
于是设置

iptables -N REDIS
iptables -A REDIS -s 192.168.10.1 -j ACCEPT
iptables -A REDIS -s 192.168.10.2 -j ACCEPT
iptables -A REDIS -j LOG --log-prefix "unauth-redis-access"
iptables -A REDIS -j REJECT --reject-with icmp-port-unreachable
iptables -I INPUT -p tcp --dport 6379 -j REDIS

192.168.10.1  192.168.10.2  为需要访问的ip (包括redis服务器本身ip,不放本机访问不了)


或者
sudo iptables -F #删除过滤规则,不建议

轻松解决。

如下测试
ndscbigdata@ubuntu-bigdata-3:/usr/local/bin$ redis-cli -h "192.168.2.195" -p 6379

Could not connect to Redis at 192.168.2.195:6379: No route to host

not connected> quit

ndscbigdata@ubuntu-bigdata-3:/usr/local/bin$ redis-cli -h "192.168.2.195" -p 6379

Could not connect to Redis at 192.168.2.195:6379: No route to host

not connected> quit

ndscbigdata@ubuntu-bigdata-3:/usr/local/bin$ redis-cli -h "192.168.2.195" -p 6379

192.168.2.195:6379> select 10

(error) NOAUTH Authentication required.

192.168.2.195:6379> quit

ndscbigdata@ubuntu-bigdata-3:/usr/local/bin$ redis-cli -h 192.168.2.195 -p 6379 -a ndscndscndsc

192.168.2.195:6379> select 10

OK

192.168.2.195:6379[10]> keys *

1) "189234234"

2) "123"

192.168.2.195:6379[10]> 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  redis 局域网 服务器
相关文章推荐