open redis port for remote connections

2019-01-16 07:24发布

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?

标签: ubuntu redis
6条回答
▲ chillily
2楼-- · 2019-01-16 07:25

Did you set the bind option to allow remote access on the redis server?

Before (file /etc/redis/redis.conf)

bind 127.0.0.1

After

bind 0.0.0.0

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!

查看更多
Explosion°爆炸
3楼-- · 2019-01-16 07:31

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)

查看更多
狗以群分
4楼-- · 2019-01-16 07:37

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

查看更多
爷的心禁止访问
5楼-- · 2019-01-16 07:45
  1. Open $REDIS_HOME/redis.conf and uncomment requirepass -YOUR-PASSWORD-HERE- and write down your password in the specified lines.

  2. Login to redis using redis-cli and verify your password in the database using auth -YOUR-PASSWORD-HERE- command.

  3. Disable protected mode by changing its string in $REDIS_HOME/redis.conf to protected-mode no.

  4. Search for all bind ports values and comment all of them. Just add bind 0.0.0.0 to $REDIS_HOME/redis.conf file.

  5. Disable your firewall or open redis port.

  6. Start redis using ./redis-server $REDIS_HOME/redis.conf.

  7. Check the configuration via ./redis-cli -h -YOUR-IP- -a -YOUR-PASSWORD-HERE-.

  8. Check the configuration via ./redis-cli -h -YOUR-IP- ping.
查看更多
Deceive 欺骗
6楼-- · 2019-01-16 07:47

For me, I needed to do the following:

1- Comment out bind 127.0.0.1

2- Change protected-mode to no

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)

查看更多
家丑人穷心不美
7楼-- · 2019-01-16 07:50

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.

查看更多
登录 后发表回答