1 Before Connect Remote Redis Server

You should install redis on your linux machine. Run the following commands and install it.

1
2
3
4
5
$ sudo yum install epel-release
$ sudo yum install redis
//verify your installtion
$ redis-cli ping
PONG //If you get this prompt, it means the isntalltion was successful.

2 command

1
2
3
$ redis-cli -h {host_ip} -p {port} -a {passowrd}
//example
$ redis-cli -h 127.0.0.1 -p 6379 -a '123456'

3 ERROR: Could not connect to Redis at 192.168.1.17:6379: No route to host

1
2
3
4
5
6
7
8
iptables -N REDIS
iptables -A REDIS -s 192.168.10.1 -j ACCEPT //ACCEPT YOUR IP_ADDRESS
iptables -A REDIS -s 192.168.10.2 -j ACCEPT //ACCEPT YOUR IP_ADDRESS
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

iptables -L //view routes

4 Could not connect to Redis at 10.18.243.168:6379: Connection refused

change the conf file:

1
bind 127.0.0.1   ---->    bind 0.0.0.0

and restart redis server.

Reference

Redis 服務端配置——Could not connect to Redis at 127.0.0.1:6379: Connection refused

Redis系列~(十七)Could not connect to Redis No route to host問題解決

写在最后

欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。
微信公众号