Unable to connect to Redis instance running on Azure Linux VM from Python
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
add a comment |
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
add a comment |
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 Dec 2 '18 at 21:44
SexyBeast
asked Nov 19 '18 at 22:10
SexyBeastSexyBeast
2,6501976154
2,6501976154
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
Dec 3 '18 at 14:51
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
Dec 3 '18 at 15:05
@SexyBeast So now, any issues or any concern?
– Peter Pan
Dec 4 '18 at 2:35
One, though unrelated (I will award you the bounty), the connection often dies. For example, I typedr.get('foo')
, I got 123. If I type the command again after 5 minutes (without having queried Redis in the mean time), this time it takes lot of time to print the value. Once it does, subsequent queries again start returning quickly. And sometimes, it does not even return after long time, it just returnsNone
, and I have tossh
to my remote VM and refresh the redis server, then refresh the connection in my Python client, and then it starts working again. Any idea how to fix this?
– SexyBeast
Dec 4 '18 at 10:11
@SexyBeast It seems to be caused by your VM size or VM Family, because Azure may consider for performance balance to make the idle VM sleep which will cause the connection dies. So you can try to upgrade your VM size or keep your VM alive via SSH ping or Redis ping.
– Peter Pan
Dec 5 '18 at 8:52
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
Dec 3 '18 at 14:51
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
Dec 3 '18 at 15:05
@SexyBeast So now, any issues or any concern?
– Peter Pan
Dec 4 '18 at 2:35
One, though unrelated (I will award you the bounty), the connection often dies. For example, I typedr.get('foo')
, I got 123. If I type the command again after 5 minutes (without having queried Redis in the mean time), this time it takes lot of time to print the value. Once it does, subsequent queries again start returning quickly. And sometimes, it does not even return after long time, it just returnsNone
, and I have tossh
to my remote VM and refresh the redis server, then refresh the connection in my Python client, and then it starts working again. Any idea how to fix this?
– SexyBeast
Dec 4 '18 at 10:11
@SexyBeast It seems to be caused by your VM size or VM Family, because Azure may consider for performance balance to make the idle VM sleep which will cause the connection dies. So you can try to upgrade your VM size or keep your VM alive via SSH ping or Redis ping.
– Peter Pan
Dec 5 '18 at 8:52
|
show 1 more comment
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
Dec 3 '18 at 14:51
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
Dec 3 '18 at 15:05
@SexyBeast So now, any issues or any concern?
– Peter Pan
Dec 4 '18 at 2:35
One, though unrelated (I will award you the bounty), the connection often dies. For example, I typedr.get('foo')
, I got 123. If I type the command again after 5 minutes (without having queried Redis in the mean time), this time it takes lot of time to print the value. Once it does, subsequent queries again start returning quickly. And sometimes, it does not even return after long time, it just returnsNone
, and I have tossh
to my remote VM and refresh the redis server, then refresh the connection in my Python client, and then it starts working again. Any idea how to fix this?
– SexyBeast
Dec 4 '18 at 10:11
@SexyBeast It seems to be caused by your VM size or VM Family, because Azure may consider for performance balance to make the idle VM sleep which will cause the connection dies. So you can try to upgrade your VM size or keep your VM alive via SSH ping or Redis ping.
– Peter Pan
Dec 5 '18 at 8:52
|
show 1 more comment
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 Dec 3 '18 at 9:55
Peter PanPeter Pan
11.5k3823
11.5k3823
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
Dec 3 '18 at 14:51
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
Dec 3 '18 at 15:05
@SexyBeast So now, any issues or any concern?
– Peter Pan
Dec 4 '18 at 2:35
One, though unrelated (I will award you the bounty), the connection often dies. For example, I typedr.get('foo')
, I got 123. If I type the command again after 5 minutes (without having queried Redis in the mean time), this time it takes lot of time to print the value. Once it does, subsequent queries again start returning quickly. And sometimes, it does not even return after long time, it just returnsNone
, and I have tossh
to my remote VM and refresh the redis server, then refresh the connection in my Python client, and then it starts working again. Any idea how to fix this?
– SexyBeast
Dec 4 '18 at 10:11
@SexyBeast It seems to be caused by your VM size or VM Family, because Azure may consider for performance balance to make the idle VM sleep which will cause the connection dies. So you can try to upgrade your VM size or keep your VM alive via SSH ping or Redis ping.
– Peter Pan
Dec 5 '18 at 8:52
|
show 1 more 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
Dec 3 '18 at 14:51
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
Dec 3 '18 at 15:05
@SexyBeast So now, any issues or any concern?
– Peter Pan
Dec 4 '18 at 2:35
One, though unrelated (I will award you the bounty), the connection often dies. For example, I typedr.get('foo')
, I got 123. If I type the command again after 5 minutes (without having queried Redis in the mean time), this time it takes lot of time to print the value. Once it does, subsequent queries again start returning quickly. And sometimes, it does not even return after long time, it just returnsNone
, and I have tossh
to my remote VM and refresh the redis server, then refresh the connection in my Python client, and then it starts working again. Any idea how to fix this?
– SexyBeast
Dec 4 '18 at 10:11
@SexyBeast It seems to be caused by your VM size or VM Family, because Azure may consider for performance balance to make the idle VM sleep which will cause the connection dies. So you can try to upgrade your VM size or keep your VM alive via SSH ping or Redis ping.
– Peter Pan
Dec 5 '18 at 8:52
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
Dec 3 '18 at 14:51
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
Dec 3 '18 at 14:51
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
Dec 3 '18 at 15:05
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
Dec 3 '18 at 15:05
@SexyBeast So now, any issues or any concern?
– Peter Pan
Dec 4 '18 at 2:35
@SexyBeast So now, any issues or any concern?
– Peter Pan
Dec 4 '18 at 2:35
One, though unrelated (I will award you the bounty), the connection often dies. For example, I typed
r.get('foo')
, I got 123. If I type the command again after 5 minutes (without having queried Redis in the mean time), this time it takes lot of time to print the value. Once it does, subsequent queries again start returning quickly. And sometimes, it does not even return after long time, it just returns None
, and I have to ssh
to my remote VM and refresh the redis server, then refresh the connection in my Python client, and then it starts working again. Any idea how to fix this?– SexyBeast
Dec 4 '18 at 10:11
One, though unrelated (I will award you the bounty), the connection often dies. For example, I typed
r.get('foo')
, I got 123. If I type the command again after 5 minutes (without having queried Redis in the mean time), this time it takes lot of time to print the value. Once it does, subsequent queries again start returning quickly. And sometimes, it does not even return after long time, it just returns None
, and I have to ssh
to my remote VM and refresh the redis server, then refresh the connection in my Python client, and then it starts working again. Any idea how to fix this?– SexyBeast
Dec 4 '18 at 10:11
@SexyBeast It seems to be caused by your VM size or VM Family, because Azure may consider for performance balance to make the idle VM sleep which will cause the connection dies. So you can try to upgrade your VM size or keep your VM alive via SSH ping or Redis ping.
– Peter Pan
Dec 5 '18 at 8:52
@SexyBeast It seems to be caused by your VM size or VM Family, because Azure may consider for performance balance to make the idle VM sleep which will cause the connection dies. So you can try to upgrade your VM size or keep your VM alive via SSH ping or Redis ping.
– Peter Pan
Dec 5 '18 at 8:52
|
show 1 more 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.
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