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:



enter image description here



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.










share|improve this question

















This question has an open bounty worth +100
reputation from SexyBeast ending in 6 days.


This question has not received enough attention.




















    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:



    enter image description here



    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.










    share|improve this question

















    This question has an open bounty worth +100
    reputation from SexyBeast ending in 6 days.


    This question has not received enough attention.


















      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:



      enter image description here



      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.










      share|improve this question















      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:



      enter image description here



      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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.


























          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.




          1. Create an Ubuntu 18.04 VM on Azure portal.

          2. Connect the Ubuntu VM via SSH to install the build packages (include build-essential, gcc and make), download & decompress the tar.gz file of redis source code from redis.io, and build & test the redis server with make & make test.

          3. Configure the redis.conf via vim, to change the bind configuration from 127.0.0.1 to 0.0.0.0.

          4. Add a new port rule of 6379 port with TCP into the NSG for the Network Interface shown in the tab Settings -> Networking of my VM on Azure portal, as the figures below.


          enter image description here
          Notes: There are two NSG in my Networking tab, the second one is related to my Network Interface which can be accessed via internet.
          enter image description here
          and
          enter image description here
          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.




          1. For redis.conf, the binding host must be 0.0.0.0. If not, redis server will be running in protected mode to refuse the query.

          2. 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.

          3. The python package redis is lazy evaluation, only connect redis server when first command request happened.


          Hope it helps.






          share|improve this answer





















          • 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











          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',
          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
          });


          }
          });














          draft saved

          draft discarded


















          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








          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.




          1. Create an Ubuntu 18.04 VM on Azure portal.

          2. Connect the Ubuntu VM via SSH to install the build packages (include build-essential, gcc and make), download & decompress the tar.gz file of redis source code from redis.io, and build & test the redis server with make & make test.

          3. Configure the redis.conf via vim, to change the bind configuration from 127.0.0.1 to 0.0.0.0.

          4. Add a new port rule of 6379 port with TCP into the NSG for the Network Interface shown in the tab Settings -> Networking of my VM on Azure portal, as the figures below.


          enter image description here
          Notes: There are two NSG in my Networking tab, the second one is related to my Network Interface which can be accessed via internet.
          enter image description here
          and
          enter image description here
          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.




          1. For redis.conf, the binding host must be 0.0.0.0. If not, redis server will be running in protected mode to refuse the query.

          2. 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.

          3. The python package redis is lazy evaluation, only connect redis server when first command request happened.


          Hope it helps.






          share|improve this answer





















          • 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















          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.




          1. Create an Ubuntu 18.04 VM on Azure portal.

          2. Connect the Ubuntu VM via SSH to install the build packages (include build-essential, gcc and make), download & decompress the tar.gz file of redis source code from redis.io, and build & test the redis server with make & make test.

          3. Configure the redis.conf via vim, to change the bind configuration from 127.0.0.1 to 0.0.0.0.

          4. Add a new port rule of 6379 port with TCP into the NSG for the Network Interface shown in the tab Settings -> Networking of my VM on Azure portal, as the figures below.


          enter image description here
          Notes: There are two NSG in my Networking tab, the second one is related to my Network Interface which can be accessed via internet.
          enter image description here
          and
          enter image description here
          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.




          1. For redis.conf, the binding host must be 0.0.0.0. If not, redis server will be running in protected mode to refuse the query.

          2. 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.

          3. The python package redis is lazy evaluation, only connect redis server when first command request happened.


          Hope it helps.






          share|improve this answer





















          • 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













          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.




          1. Create an Ubuntu 18.04 VM on Azure portal.

          2. Connect the Ubuntu VM via SSH to install the build packages (include build-essential, gcc and make), download & decompress the tar.gz file of redis source code from redis.io, and build & test the redis server with make & make test.

          3. Configure the redis.conf via vim, to change the bind configuration from 127.0.0.1 to 0.0.0.0.

          4. Add a new port rule of 6379 port with TCP into the NSG for the Network Interface shown in the tab Settings -> Networking of my VM on Azure portal, as the figures below.


          enter image description here
          Notes: There are two NSG in my Networking tab, the second one is related to my Network Interface which can be accessed via internet.
          enter image description here
          and
          enter image description here
          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.




          1. For redis.conf, the binding host must be 0.0.0.0. If not, redis server will be running in protected mode to refuse the query.

          2. 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.

          3. The python package redis is lazy evaluation, only connect redis server when first command request happened.


          Hope it helps.






          share|improve this answer












          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.




          1. Create an Ubuntu 18.04 VM on Azure portal.

          2. Connect the Ubuntu VM via SSH to install the build packages (include build-essential, gcc and make), download & decompress the tar.gz file of redis source code from redis.io, and build & test the redis server with make & make test.

          3. Configure the redis.conf via vim, to change the bind configuration from 127.0.0.1 to 0.0.0.0.

          4. Add a new port rule of 6379 port with TCP into the NSG for the Network Interface shown in the tab Settings -> Networking of my VM on Azure portal, as the figures below.


          enter image description here
          Notes: There are two NSG in my Networking tab, the second one is related to my Network Interface which can be accessed via internet.
          enter image description here
          and
          enter image description here
          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.




          1. For redis.conf, the binding host must be 0.0.0.0. If not, redis server will be running in protected mode to refuse the query.

          2. 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.

          3. The python package redis is lazy evaluation, only connect redis server when first command request happened.


          Hope it helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










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


















          • 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
















          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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'