I can ping pong redis on server
# redis-cli ping
PONG
But remotely got problems:
$ src/redis-cli -h REMOTE.IP ping
Could not connect to Redis at REMOTE.IP:6379: Connection refused
In config I got standart port:
# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
So maybe I should open port 6379 on remote ubuntu machine? How to do it?
Did you set the bind option to allow remote access on the redis server?
Before (file
/etc/redis/redis.conf
)After
and run
sudo service redis-server restart
to restart the server. If that's not the problem, you might want to check any firewalls that might block the access.Important: If you don't use a firewall (iptables, ufw..) to control who connects to the port in use, ANYONE can connect to this Redis instance. Without using Redis'
AUTH
that means anyone can access/change/delete your data. Be safe!Step 1: Go to Location : /etc/redis.conf
Step 2: Command out bind 127.0.0.1
Step 3: Restart Redis:- sudo systemctl start redis.service
Step 4: Disable Firewalld systemctl disable firewalld
Step 5: Stop Firewalld systemctl stop firewalld
Then Try.
redis-cli -h 192.168.0.2(ip) -a redis(username)
1- Comment out bind 127.0.0.1
2- set requirepass yourpassword
then check if the firewall blocked your port
iptables -L -n
service iptables stop
Open $REDIS_HOME/redis.conf and uncomment
requirepass -YOUR-PASSWORD-HERE-
and write down your password in the specified lines.Login to redis using redis-cli and verify your password in the database using
auth -YOUR-PASSWORD-HERE-
command.Disable protected mode by changing its string in $REDIS_HOME/redis.conf to
protected-mode no
.Search for all bind ports values and comment all of them. Just add
bind 0.0.0.0
to $REDIS_HOME/redis.conf file.Disable your firewall or open redis port.
Start redis using
./redis-server $REDIS_HOME/redis.conf
.Check the configuration via
./redis-cli -h -YOUR-IP- -a -YOUR-PASSWORD-HERE-
../redis-cli -h -YOUR-IP- ping
.For me, I needed to do the following:
1- Comment out
bind 127.0.0.1
2- Change
protected-mode
tono
3- Protect my server with
iptables
(https://www.digitalocean.com/community/tutorials/how-to-implement-a-basic-firewall-template-with-iptables-on-ubuntu-14-04)A quick note that doing this without further securing your Redis server is not a good idea as it can leave you open to attack. Be sure to also implement AUTH or otherwise secure that. See http://redis.io/topics/security for details.