{"id":151,"date":"2015-06-15T12:08:00","date_gmt":"2015-06-15T12:08:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/azuregov\/2015\/06\/15\/configuring-high-availability-for-iaas-virtual-machines\/"},"modified":"2019-03-28T22:32:58","modified_gmt":"2019-03-29T05:32:58","slug":"configuring-high-availability-for-iaas-virtual-machines","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/azuregov\/configuring-high-availability-for-iaas-virtual-machines\/","title":{"rendered":"Configuring High Availability for IaaS Virtual Machines"},"content":{"rendered":"<p>NOTE: I implemented the below example using the Azure Government cloud, however this technique will work exactly the same using the public Azure cloud.<\/p>\n<p>To ensure a highly available service you want to run at least two IaaS virtual machines in a load balanced set. In this post we will build a basic stateless ASP.NET workload, distribute it across two virtual machines in Azure running IIS, and then demonstrate the benefits of running in a load balanced set.<\/p>\n<p>Let\u2019s start by building our application. We will create a simple ASP.NET MVC application, with a single controller and action that will just return the machine name that the application is running on.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/shawnweisfeld\/adadef02c09e911ce86f.js\" type=\"text\/javascript\"><\/script><\/p>\n<p>Now that we have an application, lets write a simple console application to exercise the application.<\/p>\n<p><script src=\"https:\/\/gist.github.com\/shawnweisfeld\/148b4c64d7d5e9dbc0da.js\" type=\"text\/javascript\"><\/script><\/p>\n<p>Let\u2019s now create a virtual machine in Azure to deploy our application to, let\u2019s do this using the wizard in the management portal. Select New, then computer, then Virtual Machine, then from Gallery.<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3438.image001.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3438.image001.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>We are going to pick Windows Server 2012 R2 Datacenter, and press next.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/0184.image002.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/0184.image002.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Let\u2019s give our VM a name, select a size, and enter the admin credentials, and press next. Note the VM name with the 01 at the end. I use that as my convention so that all the VMs in my load balanced set appear next to each other in the management portal when sorted alphabetically.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3060.image003.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3060.image003.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>I am going to place the VM in a new cloud service. Few things to note:<\/p>\n<p>First I removed the numbers from the end of the DNS name as I don\u2019t want that to be in the URL for my website.<\/p>\n<p>Secondly we are also going to place the VM inside of an availability set. Availability sets ensure that if the Azure fabric needs to do maintenance it will perform that maintenance in such a way that not all of the VMs in the availability set are impacted. More details here: <a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/virtual-machines-manage-availability\/\">https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/virtual-machines-manage-availability\/<\/a><\/p>\n<p>Third I added an endpoint for HTTP on port 80 since we are going to host an ASP.NET MVC workload in IIS.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/6131.image004.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/6131.image004.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>On the next step we can just accept the defaults and press the finish button, and the fabric will spin up a VM for us.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8015.image005.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8015.image005.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>With our VM created, we now can remote into it to setup the VM for IIS and ASP.NET.<\/p>\n<p>Let\u2019s run through the Add Roles and Features Wizard in our VM to add IIS and ASP.NET.<\/p>\n<p>Select \u201cRole-based or feature-based installation\u201d, press next.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/0358.image006.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/0358.image006.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Select the local machine, press next.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3034.image007.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3034.image007.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Select Web Server (IIS), and press next. (it will prompt you for some dependent features, accept the defaults)<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3757.image008.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3757.image008.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Leave the defaults, press next.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/0363.image009.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/0363.image009.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Select ASP.NET 4.5 under Application Development (it will prompt you for some dependent features, accept the defaults)<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2476.image010.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2476.image010.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Press, Install, and wait a few minutes for everything to install, then close the installer.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2235.image011.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2235.image011.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now let\u2019s deploy our application. Copy it out to wherever you want it to live on the hard drive of the web server.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/7612.image012.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/7612.image012.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now let\u2019s map the default website in IIS to the place on the hard drive where we placed the application.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/1205.image013.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/1205.image013.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now if we press the browse button on the web server, it will pop open IE and we will see our machine name.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/1031.image014.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/1031.image014.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>We should now see our service live on the web. You can get the DNS Name by looking at the dashboard tab of your cloud service.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2500.image015.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2500.image015.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2318.image016.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2318.image016.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now, update your console application to point at the endpoint, and run it. You will see that all the requests are served by the same VM, well we only have one, so that is expected.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8206.image017.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8206.image017.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now that we have our application working, let\u2019s convert this VM into a template so we can make multiple copies of it. I am not going to rehash that procedure here, just follow the steps outlined in this article<\/p>\n<p><a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/virtual-machines-capture-image-windows-server\/\">https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/virtual-machines-capture-image-windows-server\/<\/a>.<\/p>\n<p>With our template created, lets create our first instance. Let\u2019s create the new VM from the gallery, you will see the image we created in the last step under my images.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8004.image018.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8004.image018.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Let\u2019s give it a name and press next<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/4405.image019.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/4405.image019.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>We can reuse the cloud service we created earlier, but we will have to recreate our availability set and don\u2019t forget the http endpoint on port 80.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8304.image020.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8304.image020.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>And, next to install the VM Agent.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/7455.image021.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/7455.image021.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now let\u2019s create a second instance. Follow the same procedure as before, let\u2019s call this VM 02<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3872.image022.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3872.image022.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Place it in the same cloud service, and the same availability set as the other VM. NOTE you will not be able to map port 80 on this VM, we will configure that in a minute.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2210.image023.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2210.image023.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Ok, lets add one more VM for good measure following the same procedure as before. You should now have 3 VMs. Note that they all have same DNS Name.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/1222.image024.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/1222.image024.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Next let\u2019s wire up the load balancer to route all the HTTP traffic to all 3 VMs.<\/p>\n<p>On the 01 machine, go to the endpoints tab, and let\u2019s edit the HTTP endpoint, select the \u201ccreate a load balanced set\u201d check box, and press next.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3443.image025.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3443.image025.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Give your load balanced set a name, and press finish.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3323.image026.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3323.image026.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now let\u2019s add the other two VMs to the load balanced set. Navigate to VM 02, select the endpoints tab, and then select add. Choose the option to \u201cAdd an endpoint to an existing load balanced set\u201d and select the load balanced set name that we just created, and press next.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/6318.image027.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/6318.image027.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Give the end point a name, and press finish.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2766.image028.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/2766.image028.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Repeat the above process to add machine 03 to the load balanced set.<\/p>\n<p>Now if we run our little console application to exercise our web servers we will see that the requests are being handled by all the VMs in our load balanced set.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3833.image029.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/3833.image029.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now that we have this setup what did we get?<\/p>\n<p>First we can now save some cash by configuring the auto scaling service. More details here: <a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/cloud-services-how-to-scale\">https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/cloud-services-how-to-scale<\/a><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/0804.image030.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/0804.image030.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Secondly we now have a highly available configuration. The Azure fabric has deployed our VMs across 3 different update domains and 2 different fault domains. The update domains will ensure that if the fabric has to do some sort of maintenance only one of the VMs will be impacted. The fault domain ensures that our VMs are across 2 different physical racks, thus a hardware failure will not bring down our entire application.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/1108.image031.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/1108.image031.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>This will also protect us if a VM goes down, let\u2019s do a dry run of this, by remoting into one of our machines while it is running and stop IIS, if we do this while our console test client is running we will see the load balancer in action.\u00a0 In the below screen shot you can see what happened when I stopped IIS on web server 02. As IIS was going down I got a 503 error, then you can see that 01 and 03 started serving up the request all by themselves.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8255.image032.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8255.image032.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Now let\u2019s do the same process in reverse, and restart IIS on server 02.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8738.image033.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/8738.image033.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>Remember that configuration we did for the Load Balanced Set? It is pinging port 80 every 15 seconds, and if it gets 2 failures it will remove the VM from the rotation, and once it starts getting successful probes it automatically puts the VM back into rotation.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/7534.image026.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/43\/2019\/03\/7534.image026.png\" alt=\"\" width=\"500\" border=\"0\" \/><\/a><\/p>\n<p>As you can see the Azure fabric gives us a very powerful platform for running our virtual machines. Ensuring that with very little work we can create a highly available and robust VM environment that can automatically grow and shrink to ensure we are getting the most value out of every VM we have running.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NOTE: I implemented the below example using the Azure Government cloud, however this technique will work exactly the same using the public Azure cloud. To ensure a highly available service you want to run at least two IaaS virtual machines in a load balanced set. In this post we will build a basic stateless ASP.NET [&hellip;]<\/p>\n","protected":false},"author":5375,"featured_media":20423,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-azuregov"],"acf":[],"blog_post_summary":"<p>NOTE: I implemented the below example using the Azure Government cloud, however this technique will work exactly the same using the public Azure cloud. To ensure a highly available service you want to run at least two IaaS virtual machines in a load balanced set. In this post we will build a basic stateless ASP.NET [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/users\/5375"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/media\/20423"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/azuregov\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}