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

2022-05-07 14:28:54 浏览数 (1)

最近一台电脑突然系统崩溃了,想做个新增节点的实验。由于之前装的都是ubuntu操作系统,于是想选个异构的REDHAT试试。

在试验第一步,装了个REDIS进行看看,才发现远程无法访问,以前由于都装了有SSH,能轻松访问。而这回出现的错误是:Could not connect to Redis at 192.168.2.195:6379: No route to host

这个问题以前还真没遇到过。网上一查,才发现是新装系统设置的iptables问题。

于是设置

代码语言:javascript复制
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

或者

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]>

0 人点赞