Well, this week I organised our first open source conference at Microsoft’s offices. Special thanks to @richorama and @robblackwell for providing some great content and also to @simonevans. The day went off smoothly despite the reliance on projects called snowylondon, hailinglondon, raininglondon etc. @andybareweb started the trend but all other speaker (myself included) flogged it to death.
I did a demo which I’d like to share because I think it’s impacting for non-Windows users and demonstrates how easy it is to set up a highly available web farm. I’ve used Ubuntu but this can equally apply to all flavours of Linux.
To start with you’ll need to download the CLI from http://go.microsoft.com/fwlink/p?LinkID=275464. I’ve referenced the CLI in my blog posts but it’s basically a cross platform command line interface built in node.js which allows us to issue service management commands.
My demo was specifically going to be about deploying Ruby and Rails but it turned out there were no Ruby developers in the room so we’ll save that for another day.
Before following the setup instructions here you’ll need to import your credentials to the CLI. This is well documented on windowsazure.com.
The following will create a cloud service which will be available on http://rubyrubyruby.cloudapp.net in North Europe. It’s important to add the –location flag in the first instance since this will create a new cloud service if one does not exist already. In this case the vm will be small and the image used will be Ubuntu.I’ll be using SSH on port 64562 with an initial username and password as described. Our vm will be called ossazure1.
azure vm create –location “North Europe” –vm-size small –vm-name ossazure1 –ssh 64562 rubyrubyruby b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_04_1-LTS-amd64-server-20121218-en-us-30GB azurecoder P@ssword123
We should get the following feedback from the CLI:
info: Executing command vm create
+ Looking up image
+ Looking up cloud service
+ Creating cloud service
+ Retrieving storage accounts
+ Creating VM
info: vm create command OK
Once this is done we can issue a second command to create another vm instance in the same cloud service like so.
azure vm create –connect –vm-size small –vm-name ossazure2 –ssh 64563 rubyrubyruby b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-12_04_1-LTS-amd64-server-20121218-en-us-30GB azurecoder P@ssword123
We’re calling this one ossazure2. As you can see the SSH port is different. Since the cloud service is effectively “bound” to a single soft network interface it’s important to distinguish ports as the CLI will generate a conflict if we use the same SSH port. Since the cloud service now exists we no longer have to use the –location flag.
We can see here that the endpoint was create and has a different public and private port.
In order to create resilience I want to ensure that a power outage in one area of the data centre doesn’t affect both VMs. This is done through Availability Sets. We’ll do this part through the portal because I like the visual feedback it gives you.
First create a new availability set and save this to ossazure1.
It may take a while because things are being shifted around in Windows Azure to ensure that the machines are on different switches and different areas of the data centre.
You can then add ossazure2 to this and you should see the visual feedback below showing the members of the availability set. I can carry this on ad-infinitum but we’ll stop at two vms for brevity.
Now we’ve got a resilient system we want to create a Load Balancer to allow traffic to be evenly distributed between the two instances. We can do this through the CLI like so:
azure vm endpoint create –lb-set-name tom ossazure1 80 80
azure vm endpoint create –lb-set-name tom ossazure2 80 80
Giving the load balancer a name is not optional but you don’t have to call it Tom! Miraculously we get the following setup for us on a new web endpoint.
Notice the load balance YES in the image. This enables me to define the same port for both vms. By default the load balancer is set to round robin between vms but you can easily setup a probe through the CLI (we can do this in another post) which will allow the load balancer to check for the health of a web page and if it isn’t up not serve from that vm.
In order to complete this we simply use an SSH client with the above credentials and install apache. The following script should help you get started:
sudo apt-get update
sudo apt-get upgrade –show-upgraded
sudo apt-get install apache2 apache2-doc apache2-utils
It will have to be done on both machines.
To check whether this works change the text on one of the Apache index.html pages.
chmod a+rw index.html
sudo vi index.html
Make the changes and then check your service – in my case http://rubyrubyruby.cloudapp.net – it will sort of round robin the requests (it’s a little sticky) but it works.