Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 本地尝试连接到ec2实例上运行的redis,但不管所有入站流量都出现错误_Python_Amazon Web Services_Amazon Ec2_Redis - Fatal编程技术网

Python 本地尝试连接到ec2实例上运行的redis,但不管所有入站流量都出现错误

Python 本地尝试连接到ec2实例上运行的redis,但不管所有入站流量都出现错误,python,amazon-web-services,amazon-ec2,redis,Python,Amazon Web Services,Amazon Ec2,Redis,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

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:连接到的错误111 ec2 xx xxx xx.compute-1.amazonaws.com:6379。连接被拒绝


尽管入站网络对所有流量开放,并且redis在ec2实例中运行良好,但什么可能导致此类问题?

您的
redis
没有侦听来自外部的连接,而是只侦听本地连接

tcp        0      0 127.0.0.1:6379 
以下内容适用于
Ubuntu
。编辑
/etc/redis/redis.conf
并将其绑定到
0.0.0

# bind 127.0.0.1
bind 0.0.0.0
然后重新启动服务:

sudo service redis-server restart

警告:安全组中不允许
0.0.0.0
。任何人都可以。相反,只允许特定IP或CIDR。

除了redis配置外,还必须配置系统防火墙以允许通信,以及EC2实例的AWS安全区域以允许来自IP的通信。