Freigeben über


Running Redis on a CentOS Linux VM in Windows Azure

With the new version of the Windows Azure platform we announced on June 7th, it is now possible to create and run persistent virtual machines, with an extended choice of operating systems, including now several Linux distributions (Ubuntu, CentOS and SUSE). These virtual machines (Linux or Windows) start on a durable disk, stored as a VHD in the Windows Azure Blob Storage service, which makes them highly available and persistent.

In this blog post I would like to show you how simple it is to create a new Linux VM and use it to run a component that is not officially supported on Windows: the Redis key-value store.

Redis is a popular component in high performance architectures, and is part of publicly document highly scalable architectures like StackOverflow’s, which is entirely built on the Microsoft platform (Windows and ASP.NET) but which uses some specialized components like Redis (or HAProxy) on Linux machines.

So, let’s see how we can really easily start a Linux VM to start using Redis on Windows Azure.

Create the VM from the management portal

The new Windows Azure management portal has been rebuilt in HTML5 to make it more fluid and more universally accessible. The welcome screen will show you by default all your Windows Azure resources (Virtual Machines, Virtual Networks, Storage Accounts…)

To create a new VM, use the “NEW” menu at the bottom left, select “virtual machine” and then “from gallery”.

image_thumb9

This will open the new VM wizard, with a number of base OS options, where we can select one of the available Linux distributions.

image_thumb7

In this article, I want to create a CentOS VM, so I will select this distribution and click on “next”.

image_thumb11

The next screen allows us to start configuring the virtual machine:

  • The virtual machine name
  • The name of the user to connect to the machine (this user will also have root access through sudo)
  • The password for that account
  • The virtual machine size (XS, S, M, L or XL)

You can also opt to upload an SSH key that will be automatically installed on the user account, allowing you to connect via an SSH client configured with the corresponding private key.

image_thumb13

The next screen contains mostly network-related settings.

  • We will select “standalone” for now, to obtain a VM that will work in isolation. You can also connect VM together so that they can see each other through the private network; otherwise, the only way to reach it is through its public IP or host name.
  • The external (public) DNS name for the machine (this is what you will use to connect using SSH).
  • The Storage Account where the VHD will be saved.
  • The last option will allow you to select a Region (datacenter) or an affinity group / virtual network.

image_thumb15

Finally, the last screen lets you create an “availability set” for cluster-type configurations, and finally validate all the settings for the new virtual machine.

image_thumb17

Down in the page footer, a panel will let you track the creation/startup of the VM. Once started, it will appear in the VM list.

image_thumb19

If you select the virtual machine (click on its name), and then click on the “endpoints” tab, you will see that the SSH port has automatically been configured and opened to the outside. You now have all the information to connect to the VM via SSH!

You can now run “ssh account@xxx.cloudapp.net” or, if you are on Windows, start your favorite SSH client, i.e. PuTTY, and configure the cloudapp.net address :

image_thumb22

And here we are !

image_thumb24

Installing Redis

The rest is just the usual installation routine. You are now the proud owner of a vanilla CentOS virtual machine and you can use any of the hundreds of tutorials available on the Interwebs to install components on it. Here is a quick way to install Redis from source:

Let’s first start by installing the development tools:

 sudo yum groupinstall "Development tools"

(when sudo asks you for a password, enter the one you created for the user account)

Now download and compile Redis:

 wget https://redis.googlecode.com/files/redis-2.4.11.tar.gz
tar xzf redis-2.4.11.tar.gz

cd redis-2.4.11

make

Install it:

 sudo make install

Then run it:

 sudo /usr/local/bin/redis-server

Expose Redis to the outside

The last thing we need to do is use the portal to open the Redis port to the outside in order to access it! Here, I am going to do the simplest thing possible in order to do a quick test, but in a real life deployment, you would of course create several connected virtual machines, and you would communicate with Redis directly through the internal network, without going through a public port!

In the “endpoints” tab for the virtual machine, down in the toolbar, select “add endpoint”.

image_thumb1

We only have one virtual machine, so we can’t configure load-balancing; let’s click on “next”.

image_thumb3

Here I configured the standard Redis port (TCP 6379), mapped it to the same port on the VM, and you can see in the “protocol” menu that you could now expose UDP ports!

Let’s click OK. The Redis port is now available to the outside world.

How about a quick test? If you are on Windows, grab the unofficial Windows Redis binary package on Github, you will find a small redis-benchmark.exe tool in there that will allow you to test your server:

 redis-benchmark.exe -h xxx.cloudapp.net

That’s it. Have fun!

Comments

  • Anonymous
    December 06, 2012
    The comment has been removed

  • Anonymous
    February 03, 2013
    Could you elaborate more on "you would of course create several connected virtual machines, and you would communicate with Redis directly through the internal network, without going through a public port!" Any recs on how this would be done?

  • Anonymous
    August 16, 2013
    I second Micah's question. I'd like to hear more about securing access to Redis on Azure

  • Anonymous
    March 25, 2015
    Sometimes you need disable firewall to open alternative ports