您现在的位置是:首页>文章详情

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

泛逸舟

局域网内访问另外一台服务器上的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]> 

评论

评论插件