Unable to connect to Redis instance running on Azure Linux VM from Python
up vote
0
down vote
favorite
I created an Ubuntu VM on Azure. In its inbound networking filters, I added ports 22 (for SSHing) and 6379 (for Redis). Following this, I SSHed into an instance from my bash shell, downloaded, built and installed Redis from source. The resultant redis.conf
file is located in /tmp/redis-stable
, so I edited that to comment out the bind 127.0.0.1
rule.
Then I started redis-server redis.conf
from the /tmp/redis-stable
directory, and it started normally, following which I SSHed into another instance of the VM, started redis-cli
and set some keys. Retrieved them, working correctly.
Now in Python I am running this command:
r = redis.Redis(host='same_which_I_use_for_SSHing', port=6379, password='pwd')
It connects immediately (looks weird). But then when I try a simple command like r.get("foo")
, I get this error:
>>> r.get("foo")
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
sock = self._connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 511, in _connect
socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/client.py", line 667, in execute_command
connection.send_command(*args)
File "/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting to username@ip_address. nodename nor servname provided, or not known.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
sock = self._connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 511, in _connect
socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python3.5/site-packages/redis/client.py", line 976, in get
return self.execute_command('GET', name)
File "/lib/python3.5/site-packages/redis/client.py", line 673, in execute_command
connection.send_command(*args)
File "/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting to username@ip_address. nodename nor servname provided, or not known.
Any idea how to fix this? FYI, the username@ip_address
in the error message is the same I use for SSH from bash and connecting to Redis from Python respectively:
ssh username@ip_address
r = redis.Redis(host='username@ip_address', port=6379, password='pwd')
I also tried adding bind 0.0.0.0
in the redis.conf
file after commenting out the bind 127.0.0.1
line. Same result.
Update: I tried setting protected mode to no in the config file, followed by running sudo ufw allow 6379
in the VM. Still same result. But now I get a weird error when I run redis-server redis.conf
. I don't get the typical redis cube which shows up as a figure Instead I get this:
After this, if I enter redis-cli
and issue a simple command like set foo boo
, I get this error message:
127.0.0.1:6379> set foo 1
(error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
Even shutdown fails after this. I have to run grep
to find the process if of redis-server and kill it manually, following which redis-server
command needs to be run to start it normally. But of course, I still cannot connect from remote Mac.
python azure redis redis-py
This question has an open bounty worth +100
reputation from SexyBeast ending in 6 days.
This question has not received enough attention.
add a comment |
up vote
0
down vote
favorite
I created an Ubuntu VM on Azure. In its inbound networking filters, I added ports 22 (for SSHing) and 6379 (for Redis). Following this, I SSHed into an instance from my bash shell, downloaded, built and installed Redis from source. The resultant redis.conf
file is located in /tmp/redis-stable
, so I edited that to comment out the bind 127.0.0.1
rule.
Then I started redis-server redis.conf
from the /tmp/redis-stable
directory, and it started normally, following which I SSHed into another instance of the VM, started redis-cli
and set some keys. Retrieved them, working correctly.
Now in Python I am running this command:
r = redis.Redis(host='same_which_I_use_for_SSHing', port=6379, password='pwd')
It connects immediately (looks weird). But then when I try a simple command like r.get("foo")
, I get this error:
>>> r.get("foo")
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
sock = self._connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 511, in _connect
socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/client.py", line 667, in execute_command
connection.send_command(*args)
File "/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting to username@ip_address. nodename nor servname provided, or not known.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
sock = self._connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 511, in _connect
socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python3.5/site-packages/redis/client.py", line 976, in get
return self.execute_command('GET', name)
File "/lib/python3.5/site-packages/redis/client.py", line 673, in execute_command
connection.send_command(*args)
File "/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting to username@ip_address. nodename nor servname provided, or not known.
Any idea how to fix this? FYI, the username@ip_address
in the error message is the same I use for SSH from bash and connecting to Redis from Python respectively:
ssh username@ip_address
r = redis.Redis(host='username@ip_address', port=6379, password='pwd')
I also tried adding bind 0.0.0.0
in the redis.conf
file after commenting out the bind 127.0.0.1
line. Same result.
Update: I tried setting protected mode to no in the config file, followed by running sudo ufw allow 6379
in the VM. Still same result. But now I get a weird error when I run redis-server redis.conf
. I don't get the typical redis cube which shows up as a figure Instead I get this:
After this, if I enter redis-cli
and issue a simple command like set foo boo
, I get this error message:
127.0.0.1:6379> set foo 1
(error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
Even shutdown fails after this. I have to run grep
to find the process if of redis-server and kill it manually, following which redis-server
command needs to be run to start it normally. But of course, I still cannot connect from remote Mac.
python azure redis redis-py
This question has an open bounty worth +100
reputation from SexyBeast ending in 6 days.
This question has not received enough attention.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I created an Ubuntu VM on Azure. In its inbound networking filters, I added ports 22 (for SSHing) and 6379 (for Redis). Following this, I SSHed into an instance from my bash shell, downloaded, built and installed Redis from source. The resultant redis.conf
file is located in /tmp/redis-stable
, so I edited that to comment out the bind 127.0.0.1
rule.
Then I started redis-server redis.conf
from the /tmp/redis-stable
directory, and it started normally, following which I SSHed into another instance of the VM, started redis-cli
and set some keys. Retrieved them, working correctly.
Now in Python I am running this command:
r = redis.Redis(host='same_which_I_use_for_SSHing', port=6379, password='pwd')
It connects immediately (looks weird). But then when I try a simple command like r.get("foo")
, I get this error:
>>> r.get("foo")
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
sock = self._connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 511, in _connect
socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/client.py", line 667, in execute_command
connection.send_command(*args)
File "/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting to username@ip_address. nodename nor servname provided, or not known.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
sock = self._connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 511, in _connect
socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python3.5/site-packages/redis/client.py", line 976, in get
return self.execute_command('GET', name)
File "/lib/python3.5/site-packages/redis/client.py", line 673, in execute_command
connection.send_command(*args)
File "/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting to username@ip_address. nodename nor servname provided, or not known.
Any idea how to fix this? FYI, the username@ip_address
in the error message is the same I use for SSH from bash and connecting to Redis from Python respectively:
ssh username@ip_address
r = redis.Redis(host='username@ip_address', port=6379, password='pwd')
I also tried adding bind 0.0.0.0
in the redis.conf
file after commenting out the bind 127.0.0.1
line. Same result.
Update: I tried setting protected mode to no in the config file, followed by running sudo ufw allow 6379
in the VM. Still same result. But now I get a weird error when I run redis-server redis.conf
. I don't get the typical redis cube which shows up as a figure Instead I get this:
After this, if I enter redis-cli
and issue a simple command like set foo boo
, I get this error message:
127.0.0.1:6379> set foo 1
(error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
Even shutdown fails after this. I have to run grep
to find the process if of redis-server and kill it manually, following which redis-server
command needs to be run to start it normally. But of course, I still cannot connect from remote Mac.
python azure redis redis-py
I created an Ubuntu VM on Azure. In its inbound networking filters, I added ports 22 (for SSHing) and 6379 (for Redis). Following this, I SSHed into an instance from my bash shell, downloaded, built and installed Redis from source. The resultant redis.conf
file is located in /tmp/redis-stable
, so I edited that to comment out the bind 127.0.0.1
rule.
Then I started redis-server redis.conf
from the /tmp/redis-stable
directory, and it started normally, following which I SSHed into another instance of the VM, started redis-cli
and set some keys. Retrieved them, working correctly.
Now in Python I am running this command:
r = redis.Redis(host='same_which_I_use_for_SSHing', port=6379, password='pwd')
It connects immediately (looks weird). But then when I try a simple command like r.get("foo")
, I get this error:
>>> r.get("foo")
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
sock = self._connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 511, in _connect
socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/client.py", line 667, in execute_command
connection.send_command(*args)
File "/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting to username@ip_address. nodename nor servname provided, or not known.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/lib/python3.5/site-packages/redis/connection.py", line 484, in connect
sock = self._connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 511, in _connect
socket.SOCK_STREAM):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python3.5/site-packages/redis/client.py", line 976, in get
return self.execute_command('GET', name)
File "/lib/python3.5/site-packages/redis/client.py", line 673, in execute_command
connection.send_command(*args)
File "/lib/python3.5/site-packages/redis/connection.py", line 610, in send_command
self.send_packed_command(self.pack_command(*args))
File "/lib/python3.5/site-packages/redis/connection.py", line 585, in send_packed_command
self.connect()
File "/lib/python3.5/site-packages/redis/connection.py", line 489, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting to username@ip_address. nodename nor servname provided, or not known.
Any idea how to fix this? FYI, the username@ip_address
in the error message is the same I use for SSH from bash and connecting to Redis from Python respectively:
ssh username@ip_address
r = redis.Redis(host='username@ip_address', port=6379, password='pwd')
I also tried adding bind 0.0.0.0
in the redis.conf
file after commenting out the bind 127.0.0.1
line. Same result.
Update: I tried setting protected mode to no in the config file, followed by running sudo ufw allow 6379
in the VM. Still same result. But now I get a weird error when I run redis-server redis.conf
. I don't get the typical redis cube which shows up as a figure Instead I get this:
After this, if I enter redis-cli
and issue a simple command like set foo boo
, I get this error message:
127.0.0.1:6379> set foo 1
(error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
Even shutdown fails after this. I have to run grep
to find the process if of redis-server and kill it manually, following which redis-server
command needs to be run to start it normally. But of course, I still cannot connect from remote Mac.
python azure redis redis-py
python azure redis redis-py
edited yesterday
asked Nov 19 at 22:10
SexyBeast
2,4011974147
2,4011974147
This question has an open bounty worth +100
reputation from SexyBeast ending in 6 days.
This question has not received enough attention.
This question has an open bounty worth +100
reputation from SexyBeast ending in 6 days.
This question has not received enough attention.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
I tried to create an Ubuntu VM on Azure, build & configure redis server from source code, and add a port rule for my VM NSG on Azure portal, then I connected the redis server via the same code with python redis package successfully.
Here is my steps as below.
- Create an Ubuntu 18.04 VM on Azure portal.
- Connect the Ubuntu VM via SSH to install the build packages (include
build-essential
,gcc
andmake
), download & decompress thetar.gz
file of redis source code fromredis.io
, and build & test the redis server withmake
&make test
. - Configure the
redis.conf
viavim
, to change thebind
configuration from127.0.0.1
to0.0.0.0
. - Add a new port rule of
6379
port with TCP into the NSG for theNetwork Interface
shown in the tabSettings -> Networking
of my VM on Azure portal, as the figures below.
Notes: There are two NSG in my Networking
tab, the second one is related to my Network Interface
which can be accessed via internet.
and
5. Install redis
via pip install redis
on my local machine.
6. Open a termial to type python
to try to connect the redis server hosted on my Azure Ubuntu VM and get the value of the foo
key successfully.
>>> import redis
>>> r = redis.Redis(host='xxx.xx.xx.xxx')
>>> r.get('foo')
b'bar'
There are two key issues I found within my testing.
- For
redis.conf
, the binding host must be0.0.0.0
. If not, redis server will be running in protected mode to refuse the query. - For the NSG port rules, make sure the new port rule added in the NSG attached to the current network interface, not the default subnet.
- The python package
redis
is lazy evaluation, only connect redis server when first command request happened.
Hope it helps.
Thanks Peter. I found that I already had the exact same rule created. For me, the protocol was set toAny
instead of the more restrictiveTCP
. However, unlike your configuration, mine does not impact any subnet. Any idea how to make it similar to yours? Here is my configuration: imgur.com/a/SyxJyzF. Note that your says "Impacts 1 subnet" in one place.
– SexyBeast
11 hours ago
Wow. In fact it does seem to work! But I can't figure out what I did! When I just changed the protocol toTCP
fromAny
and tried it again, I first got a different error, that it is running in protected mode, I need to turn that off. As I had mentioned at the end of my answer, I had earlier tried that, and after that, evenredis-cli
was failing locally. However, I did that again, and this time it is working correctly!
– SexyBeast
11 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I tried to create an Ubuntu VM on Azure, build & configure redis server from source code, and add a port rule for my VM NSG on Azure portal, then I connected the redis server via the same code with python redis package successfully.
Here is my steps as below.
- Create an Ubuntu 18.04 VM on Azure portal.
- Connect the Ubuntu VM via SSH to install the build packages (include
build-essential
,gcc
andmake
), download & decompress thetar.gz
file of redis source code fromredis.io
, and build & test the redis server withmake
&make test
. - Configure the
redis.conf
viavim
, to change thebind
configuration from127.0.0.1
to0.0.0.0
. - Add a new port rule of
6379
port with TCP into the NSG for theNetwork Interface
shown in the tabSettings -> Networking
of my VM on Azure portal, as the figures below.
Notes: There are two NSG in my Networking
tab, the second one is related to my Network Interface
which can be accessed via internet.
and
5. Install redis
via pip install redis
on my local machine.
6. Open a termial to type python
to try to connect the redis server hosted on my Azure Ubuntu VM and get the value of the foo
key successfully.
>>> import redis
>>> r = redis.Redis(host='xxx.xx.xx.xxx')
>>> r.get('foo')
b'bar'
There are two key issues I found within my testing.
- For
redis.conf
, the binding host must be0.0.0.0
. If not, redis server will be running in protected mode to refuse the query. - For the NSG port rules, make sure the new port rule added in the NSG attached to the current network interface, not the default subnet.
- The python package
redis
is lazy evaluation, only connect redis server when first command request happened.
Hope it helps.
Thanks Peter. I found that I already had the exact same rule created. For me, the protocol was set toAny
instead of the more restrictiveTCP
. However, unlike your configuration, mine does not impact any subnet. Any idea how to make it similar to yours? Here is my configuration: imgur.com/a/SyxJyzF. Note that your says "Impacts 1 subnet" in one place.
– SexyBeast
11 hours ago
Wow. In fact it does seem to work! But I can't figure out what I did! When I just changed the protocol toTCP
fromAny
and tried it again, I first got a different error, that it is running in protected mode, I need to turn that off. As I had mentioned at the end of my answer, I had earlier tried that, and after that, evenredis-cli
was failing locally. However, I did that again, and this time it is working correctly!
– SexyBeast
11 hours ago
add a comment |
up vote
1
down vote
I tried to create an Ubuntu VM on Azure, build & configure redis server from source code, and add a port rule for my VM NSG on Azure portal, then I connected the redis server via the same code with python redis package successfully.
Here is my steps as below.
- Create an Ubuntu 18.04 VM on Azure portal.
- Connect the Ubuntu VM via SSH to install the build packages (include
build-essential
,gcc
andmake
), download & decompress thetar.gz
file of redis source code fromredis.io
, and build & test the redis server withmake
&make test
. - Configure the
redis.conf
viavim
, to change thebind
configuration from127.0.0.1
to0.0.0.0
. - Add a new port rule of
6379
port with TCP into the NSG for theNetwork Interface
shown in the tabSettings -> Networking
of my VM on Azure portal, as the figures below.
Notes: There are two NSG in my Networking
tab, the second one is related to my Network Interface
which can be accessed via internet.
and
5. Install redis
via pip install redis
on my local machine.
6. Open a termial to type python
to try to connect the redis server hosted on my Azure Ubuntu VM and get the value of the foo
key successfully.
>>> import redis
>>> r = redis.Redis(host='xxx.xx.xx.xxx')
>>> r.get('foo')
b'bar'
There are two key issues I found within my testing.
- For
redis.conf
, the binding host must be0.0.0.0
. If not, redis server will be running in protected mode to refuse the query. - For the NSG port rules, make sure the new port rule added in the NSG attached to the current network interface, not the default subnet.
- The python package
redis
is lazy evaluation, only connect redis server when first command request happened.
Hope it helps.
Thanks Peter. I found that I already had the exact same rule created. For me, the protocol was set toAny
instead of the more restrictiveTCP
. However, unlike your configuration, mine does not impact any subnet. Any idea how to make it similar to yours? Here is my configuration: imgur.com/a/SyxJyzF. Note that your says "Impacts 1 subnet" in one place.
– SexyBeast
11 hours ago
Wow. In fact it does seem to work! But I can't figure out what I did! When I just changed the protocol toTCP
fromAny
and tried it again, I first got a different error, that it is running in protected mode, I need to turn that off. As I had mentioned at the end of my answer, I had earlier tried that, and after that, evenredis-cli
was failing locally. However, I did that again, and this time it is working correctly!
– SexyBeast
11 hours ago
add a comment |
up vote
1
down vote
up vote
1
down vote
I tried to create an Ubuntu VM on Azure, build & configure redis server from source code, and add a port rule for my VM NSG on Azure portal, then I connected the redis server via the same code with python redis package successfully.
Here is my steps as below.
- Create an Ubuntu 18.04 VM on Azure portal.
- Connect the Ubuntu VM via SSH to install the build packages (include
build-essential
,gcc
andmake
), download & decompress thetar.gz
file of redis source code fromredis.io
, and build & test the redis server withmake
&make test
. - Configure the
redis.conf
viavim
, to change thebind
configuration from127.0.0.1
to0.0.0.0
. - Add a new port rule of
6379
port with TCP into the NSG for theNetwork Interface
shown in the tabSettings -> Networking
of my VM on Azure portal, as the figures below.
Notes: There are two NSG in my Networking
tab, the second one is related to my Network Interface
which can be accessed via internet.
and
5. Install redis
via pip install redis
on my local machine.
6. Open a termial to type python
to try to connect the redis server hosted on my Azure Ubuntu VM and get the value of the foo
key successfully.
>>> import redis
>>> r = redis.Redis(host='xxx.xx.xx.xxx')
>>> r.get('foo')
b'bar'
There are two key issues I found within my testing.
- For
redis.conf
, the binding host must be0.0.0.0
. If not, redis server will be running in protected mode to refuse the query. - For the NSG port rules, make sure the new port rule added in the NSG attached to the current network interface, not the default subnet.
- The python package
redis
is lazy evaluation, only connect redis server when first command request happened.
Hope it helps.
I tried to create an Ubuntu VM on Azure, build & configure redis server from source code, and add a port rule for my VM NSG on Azure portal, then I connected the redis server via the same code with python redis package successfully.
Here is my steps as below.
- Create an Ubuntu 18.04 VM on Azure portal.
- Connect the Ubuntu VM via SSH to install the build packages (include
build-essential
,gcc
andmake
), download & decompress thetar.gz
file of redis source code fromredis.io
, and build & test the redis server withmake
&make test
. - Configure the
redis.conf
viavim
, to change thebind
configuration from127.0.0.1
to0.0.0.0
. - Add a new port rule of
6379
port with TCP into the NSG for theNetwork Interface
shown in the tabSettings -> Networking
of my VM on Azure portal, as the figures below.
Notes: There are two NSG in my Networking
tab, the second one is related to my Network Interface
which can be accessed via internet.
and
5. Install redis
via pip install redis
on my local machine.
6. Open a termial to type python
to try to connect the redis server hosted on my Azure Ubuntu VM and get the value of the foo
key successfully.
>>> import redis
>>> r = redis.Redis(host='xxx.xx.xx.xxx')
>>> r.get('foo')
b'bar'
There are two key issues I found within my testing.
- For
redis.conf
, the binding host must be0.0.0.0
. If not, redis server will be running in protected mode to refuse the query. - For the NSG port rules, make sure the new port rule added in the NSG attached to the current network interface, not the default subnet.
- The python package
redis
is lazy evaluation, only connect redis server when first command request happened.
Hope it helps.
answered 16 hours ago
Peter Pan
10.2k2823
10.2k2823
Thanks Peter. I found that I already had the exact same rule created. For me, the protocol was set toAny
instead of the more restrictiveTCP
. However, unlike your configuration, mine does not impact any subnet. Any idea how to make it similar to yours? Here is my configuration: imgur.com/a/SyxJyzF. Note that your says "Impacts 1 subnet" in one place.
– SexyBeast
11 hours ago
Wow. In fact it does seem to work! But I can't figure out what I did! When I just changed the protocol toTCP
fromAny
and tried it again, I first got a different error, that it is running in protected mode, I need to turn that off. As I had mentioned at the end of my answer, I had earlier tried that, and after that, evenredis-cli
was failing locally. However, I did that again, and this time it is working correctly!
– SexyBeast
11 hours ago
add a comment |
Thanks Peter. I found that I already had the exact same rule created. For me, the protocol was set toAny
instead of the more restrictiveTCP
. However, unlike your configuration, mine does not impact any subnet. Any idea how to make it similar to yours? Here is my configuration: imgur.com/a/SyxJyzF. Note that your says "Impacts 1 subnet" in one place.
– SexyBeast
11 hours ago
Wow. In fact it does seem to work! But I can't figure out what I did! When I just changed the protocol toTCP
fromAny
and tried it again, I first got a different error, that it is running in protected mode, I need to turn that off. As I had mentioned at the end of my answer, I had earlier tried that, and after that, evenredis-cli
was failing locally. However, I did that again, and this time it is working correctly!
– SexyBeast
11 hours ago
Thanks Peter. I found that I already had the exact same rule created. For me, the protocol was set to
Any
instead of the more restrictive TCP
. However, unlike your configuration, mine does not impact any subnet. Any idea how to make it similar to yours? Here is my configuration: imgur.com/a/SyxJyzF. Note that your says "Impacts 1 subnet" in one place.– SexyBeast
11 hours ago
Thanks Peter. I found that I already had the exact same rule created. For me, the protocol was set to
Any
instead of the more restrictive TCP
. However, unlike your configuration, mine does not impact any subnet. Any idea how to make it similar to yours? Here is my configuration: imgur.com/a/SyxJyzF. Note that your says "Impacts 1 subnet" in one place.– SexyBeast
11 hours ago
Wow. In fact it does seem to work! But I can't figure out what I did! When I just changed the protocol to
TCP
from Any
and tried it again, I first got a different error, that it is running in protected mode, I need to turn that off. As I had mentioned at the end of my answer, I had earlier tried that, and after that, even redis-cli
was failing locally. However, I did that again, and this time it is working correctly!– SexyBeast
11 hours ago
Wow. In fact it does seem to work! But I can't figure out what I did! When I just changed the protocol to
TCP
from Any
and tried it again, I first got a different error, that it is running in protected mode, I need to turn that off. As I had mentioned at the end of my answer, I had earlier tried that, and after that, even redis-cli
was failing locally. However, I did that again, and this time it is working correctly!– SexyBeast
11 hours ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383367%2funable-to-connect-to-redis-instance-running-on-azure-linux-vm-from-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown