0 votes
1 view
in AWS by (19.2k points)

The redis is running in the ec2 instance via daemon

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 *

Temporarily I have set network inbound to all traffic so it is likely not a problem of network security.

Type         Protocol Port Range   Source      Description

All traffic  All           All                 0.0.0.0/0

But when I try to access from the python side:

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')


I get the following error:

ConnectionError: Error 111 connecting to ec2-xx-xxx-xx-xx.compute-1.amazonaws.com:6379. Connection refused.

What may cause such issue despite network inbound is open to all traffic and redis running fine in the ec2 instance?

1 Answer

0 votes
by (44.6k points)

First, your redis is listening to connections only locally because of the IP address which is provided. So, you will have to make your bind-address to 0.0.0.0.

tcp        0      0 127.0.0.1:6379 

Now, you will have to change your redis.conf file. The path to the file is /etc/redis/redis.conf. After opening the file, do the below part

bind 127.0.0.1 - change this to the one below

bind 0.0.0.0

After you have changed it, save the file and restart the service using the below command

sudo service redis-server restart

Now, try running the same and it should work.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...