📜 ⬆️ ⬇️

Creating a Windows Azure Virtual Machine for hosting web applications

image
Good day!

In my previous article, I talked about how you can easily publish a web application written in ASP.NET MVC 4 in the new Windows Azure Web Sites service.

In today's article, I will try to tell you how you can expand the boundaries of using Azure using the example of creating a virtual machine in it and hosting a web application on it.
')

Step 0. Access.


For those who are too lazy to click on the link at the beginning of the article, I remind you how you can get free access to new features of Windows Azure.

First, you need to register for the 90-day trial , and then add to your subscription new preview functions (the very ones in question). This is done on the Preview Components page, where you can choose what you want to try. In this case, choose Virtual Machine .

Step 1. Create a virtual machine


Once we have access to the components of Windows Azure, it's time to start using them. To do this, select the Virtual Machines item in the management portal and at the bottom of the page, click the big plus button (you won't miss):


Two items will be available to us: Quick Create and From Gallery. In fact, the difference between them is small, so consider a more complete path. Choose From Gallery :


In this dialog box we have several options to choose from. To begin with, in addition to ready-made OS images (seen in the screenshot), we also have the opportunity to upload our own image or a VHD disk, from which a virtual machine will be created later. It will be convenient for large projects where you need to create a farm of identical machines, without bothering with setting up each of them. We are not interested in it now, so we turn our eyes on the available ready-made images.

There are several options to choose from. There is Windows Server 2008 R2 (two versions), Linux machines, a specialized server for SQL Server (about this image, by the way, they recently wrote on Habré ) and the hero of our experiment today - Windows Server 2012. Why him? This is my personal choice. Since I use Windows Azure so far more for informational purposes, I decided that it would be nice to try the “new product of the season” - the new server 2012.

So, choose the OS we need and click the arrow below. We get to the next screen of the virtual machine creation wizard:


Everything is pretty clear here. You must specify the name of the VM, the administrator password and select one of the proposed configurations of the future hardware. The selection is pretty good and can cover most of the performance requirements for different types of project. I chose Small, which suits me perfectly. Go ahead.

At the third step of the wizard, everything is also pretty clear:


First you need to decide on the appointment of a future car. If we want to use it as an independent resource (and at the moment we just want it), then choose Standalone . Connect To mode, as written in the tooltip, will allow us to connect this VM to some existing network for load sharing. We are not interested in it yet.

Then you need to come up with the name of the host on which the machine will be available. Here it is necessary not to confuse the name of the machine in the previous step and the given name of the host. The machine name is the computer name in Windows. The host name is a subdomain in the cloudapp.net domain, through which the server will be accessed and controlled. This name must be unique, so we are immediately given a hint in the wizard about the availability or employment of a particular name.

The remaining fields are quite understandable and you shouldn’t particularly focus on them. There you have to choose a storage account (either existing or create a new one), VM location and subscription, under which this machine will be charged.

In the fourth step, you don’t need to do anything at all; leave it as it is:


Click on the checkbox below, and the virtual machine will start to be created.

Step 2. Managing the virtual machine


Once you have created a virtual machine, it will be available in the appropriate list:


Be sure to wait until the machine status changes from Provisioning to Running . This will mean that the machine is ready for use. If you click on its name, the virtual machine control panel will open:


At the bottom of the page there is a Connect button. It will help you get the right rdp file to connect to this machine using remote desktop. It's time to go to the fresh server and manage them.

Step 3. Server Management


In fact, in this article I will not talk in detail about the administration of Windows Server 2012. Since the title of this article mentions web applications, this is what we are going to do - install IIS.

When you first login to the new server, the Server Manager window will open:


By default, IIS is not included in Windows Server 2012, so you need to add them. Select Add roles and features , and then the Add Roles Wizard opens. Click Next three times (especially curious people read what they write there, but now we are not interested), and in the opened tree select the Web Server (IIS) . Next, we need to choose the necessary IIS components that will allow running ASP.NET MVC applications on it. I will not write the exact settings, everyone will decide for himself exactly what he needs. Be sure to include ASP.NET, the rest to taste.

We click Next several times, configure the future role as we need it and after the installation process is completed, our server is happy to receive guests. You can verify this by going to localhost . Something like this should appear:


Step 4. Opening Access


Everything is great, so we finally set up a web server, placed some application on it and it opens on localhost. How now to open it from the outside? In fact, everything is quite simple. Surely, at the stage of creating a virtual machine, you tried to click on the link in the control panel, which looks like <your_virut_machine> .cloudapp.net. And surely you did not see anything. This is because access to the virtual machine is closed from the outside, and not at the level of the firewall of the operating system itself, but at the level of the Windows Azure infrastructure.

If you look up at the virtual machine control panel, you will see three menu items there: Dashboard , Endpoints and Configure . We figured out the first one at the very beginning, everything is clear with the latter - the hardware parameters are configured there, but let's look at what Endpoints are.

In the Endpoints tab, we can specify which protocols and ports will be open for this virtual machine and to which physical ports they will be redirected:


By default, there will be only one port in this list — the one through which you connect via Remote Desktop. Moreover, the public port can be anything that, apparently, is made for greater security. In order to open web applications on this virtual machine, you need to open the 80th port. The screenshot above shows this. After this action on the link <your_virut_mashina> .cloudapp.net you will need to see your own application. A small victory has been achieved.

Step 5. Assigning your own domain


In the previous step, we did everything to make the application work in the cloud and be accessible from the outside. However, you will agree that it would not be at all cool if we could access it only by subdomain and in no way could we assign our own one or several domains.

Of course, this is possible and quite simple. For this official documentation advises two different ways and both of them are associated with editing the DNS zone. The first implies that you create a CNAME record, which indicates that, for example, www.mydomain.com will be redirected to mywinazure.cloudapp.net. This method is simple, but too straightforward. If you have several web applications on the server, or there may be several subdomains on the main domain, this method will not work. Fortunately, there is a second, better way.

As a solution, which, by the way, I used, editing A records in the DNS zone is proposed. In the control panel of the virtual machine, in the area on the right, you might notice two IP addresses. One is called private and is the IP of the machine itself, and the second is public, virtual (Virtual IP, VIP). That's it, and it must be specified in zone A for the edited domain. In this case, all traffic will be sent to your virtual machine, where IIS will determine the domain and issue the appropriate application (provided that Web Sites are correctly configured in IIS itself). Everything is simple and obvious to the obscene, but this is how it works.

Step 6. Bonus


As a bonus, I will talk about an example of integrating one Windows Azure service with another. If you read my previous article, then you know that in it I described the service of facts about programming. Within that article, I described the process of publishing an ASP.NET MVC 4 application to the cloud using Windows Azure Web Sites and the Windows Azure SQL Database. Now, while studying Virtual Machines, I decided to transfer the same service from Web Sites to a virtual machine in order to be able to bind my own domain, and generally to have everything in one place (now several websites are hosted in VM).

I transferred the files of the application itself painlessly. But when I remembered the base, I was a little sad at first. I immediately imagined that I would have to download the distribution first, then allocate some place for it. Start the database service on the already not the fastest machine. Have a database and web application on the same server. Transfer data from one server to another. Well, a few more similar troubles. Not to say that it was so hard, but, frankly, lazy.

And then I thought - what if I set up an application hosted in a virtual machine on a database that was created as part of hosting the site on Web Sites? Indeed, from the point of view of the application, this database is exactly the same as if it were installed on a local server. No sooner said than done. I changed the web.config as necessary, specifying as the database server the same server that I had in Windows Azure. And what would you think? It is working. Now I have a separate application server and a separate database, which can be independently replaced, expanded and mirrored if necessary. Thank you Azure for such amenities.

Conclusion


On this pleasant note, I would like to finish the story. I hope the material will be useful to novice Azure researchers and will help determine the choice of hosting for their web projects. Just in case, I want to make sure that I am in no way affiliated with Microsoft and reflect only my personal point of view, without any advertising.

If anyone is interested in seeing what kind of application is working in the cloud, then here are the links: prog-facts.ru and ss10.ru (the second just cited as an example that the two domains are perfectly forwarded to the same hosting).

Thanks for attention!

Source: https://habr.com/ru/post/149971/


All Articles