ping 远程 redis 主机时,“没有到主机的路由”

ping 远程 redis 主机时,“没有到主机的路由”

我正在设置 Resque 服务器,并且必须首次设置 Redis。使用 redis-cli ping 远程服务器时,我收到“无路由到主机”错误,但是当我直接 ping 远程服务器时,它返回正常。由于我从未与 redis 打过交道,或者在服务器上幕后处理过很多事情,所以我真的不太确定下一步该做什么。

[root@ss03-dev-worker bin]# redis-cli -h 10.176.x.yyy ping
Could not connect to Redis at 10.176.x.yyy:6379: No route to host

[root@ss03-dev-worker bin]# ping 10.176.x.yyy
PING 10.176.x.yyy (10.176.x.yyy) 56(84) bytes of data.
64 bytes from 10.176.x.yyy: icmp_seq=1 ttl=61 time=2.09 ms
64 bytes from 10.176.x.yyy: icmp_seq=2 ttl=61 time=0.812 ms
64 bytes from 10.176.x.yyy: icmp_seq=3 ttl=61 time=0.508 ms
^C
--- 10.176.x.yyy ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2785ms
rtt min/avg/max/mdev = 0.508/1.139/2.099/0.690 ms

我已确保两个服务器上的 iptable 规则都允许来自每个服务器的连接。

[root@ss03-dev-worker bin]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
...snip....
ACCEPT     tcp  --  10.176.x.yyy         anywhere            tcp dpt:6379

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain fail2ban-SSH (0 references)
target     prot opt source               destination       

但仍然无法连接 redis。我还需要实现什么吗?

如果有所不同,这是在 Rackspace Cloud 上。

编辑:

redis conf bind参数被注释掉。

答案1

似乎 iptables 过滤掉了所有内容。解决方案是创建一个 REDIS 链。

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

http://www.golja.org/blog/monitoring-traffic-with-iptables/

答案2

对我来说,我只是使用防火墙 GUI 工具来打开端口 6379 TCP(正在由 redis-server 使用)。

之后,我可以使用 redis-cli 命令行进行连接:

redis-cli -h <server IP> -p 6379

相关内容