[英]Locally trying to connect to redis running on ec2 instance but getting error despite all traffic inbound
Redis通過守護程序在ec2實例中運行
ps aux | grep redis-server
redis 1182 0.0 0.8 38856 8740 ? Ssl 21:40 0:00 /usr/bin/redis-server 127.0.0.1:6379
netstat -nlpt | grep 6379
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN -
tcp6 0 0 :::6379 :::* LISTEN 1388/redis-server *
我暫時將網絡入站設置為所有流量,因此這可能不是網絡安全問題。
Type Protocol Port Range Source Description
All traffic All All 0.0.0.0/0
但是當我嘗試從python端訪問時:
import redis
r = redis.StrictRedis(host='ec2-xx-xxx-xx-xx.compute-1.amazonaws.com', port=6379, db=0)
r.set('foo', 'bar')
r.get('foo')
我收到以下錯誤:
ConnectionError:連接到ec2-xx-xxx-xx-xx.compute-1.amazonaws.com:6379的錯誤111。 拒絕連接。
盡管入站網絡對所有流量開放,並且redis在ec2實例中運行良好,但可能導致此類問題的原因是什么?
您的redis
不會監聽來自外部的連接,而只會監聽本地連接。
tcp 0 0 127.0.0.1:6379
以下作品適用於Ubuntu
。 編輯/etc/redis/redis.conf
並將其bind
到0.0.0.0
:
# bind 127.0.0.1
bind 0.0.0.0
然后重新啟動服務:
sudo service redis-server restart
警告 :不允許在安全組中使用0.0.0.0
。 任何人都可以。 而是僅允許特定的IP或CIDR。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.