Linux Powered By Azure Series
I am starting a 4-5 part series on running Linux out on Azure. Starting from standing up a virtual machine to installing WordPress and remote debugging and deploying.
Azure provides three compute models for running applications: Azure Websites, Azure Virtual Machines, and Azure Cloud Services. Azure Websites is a quick and easy way to deploy your website running .NET, PHP, Node.js and Java along with many frameworks and applications that are ready to go. However, there are some instances that you may want bit more control over the configuration of your website. This tutorial will show how to build a Linux based webserver out on Azure just for that reason.
- Azure subscription is needed. If you do not have one, please sign up for a free trial.
- A computer to connect to the internet and run command line utilities.
- I will be using a Mac to show how this is done, however the same mechanics can be applied to running other OS’s except for a few steps which I will point out.
Creating a Private/Public Key
The first step of this process is to ensure that we have a secure connection to our Virtual Machine. Before we stand one up, we will generate the appropriate keys to use when we start configuring our VM. If you want more detail on how to go about generating a key on Linux or on Windows, please be sure to view the Azure documentation.
- Open up a Terminal Window and issue the following command:
- openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout YOURKEYNAME.key -out YOURKEYNAME.pem
- Where it states YOURKEYNAME replace that with the name of your choice. I chose my host name that I will be using for my VM.
- Hit enter.
- You will be asked a series of questions that you need to fill out. Country, State etc. The information is needed to create the certificate. It does not have to be 100% but it should be valid enough.
- Once done your file should be saved as a .key and a .pem. It is the .pem that you upload to Azure VM and the .key you use to connect via SSH.
Creating the Virtual Machine
Head on over to Azure and login. If you do not have an account, be sure to sign up for the free trial.
Within in your control panel you want to choose NEW > COMPUTE > VIRTUAL MACHINE
Be sure to choose FROM GALLERY, not QUICK CREATE. From gallery allows you to change settings before the VM is created.
You can either search or select UBUNTU and choose version 14. This portion of the tutorial holds true if you choose Suse or Centos. I just favor Ubuntu
Then click the next arrow.
The configuration page is displayed and we get to configure a few items
- Virtual Machine Name – this is the name of the machine. Different from DNS name.
- Tier – this is your compute configuration, standard is fine for now
- New User Name: name of the su
- Authentication – make sure it is checked. This is the file we created in the first part of the tutorial
For the Certificate option, choose the ‘Browse’ option and location your .pem file that you created in the prior step and upload it. The certificate will be added to the account.
Click the next arrow
A few things on this page you can configure
- Cloud Service – most likely we want a new one but you can select and existing one if needed.
- DNS Name – this will be the name of your machine registered in the DNS
- Regional Affinity – recommend choosing one close to your location
- Storage Account – if you want to select an existing one, most likely create a new one.
- Availability Set – for this tutorial is it not needed but if we were going to load balance or have a separate DB we may want to keep all of the VMs in the same set.
- Endpoints – leave for now. We will add endpoints for the Webserver and DB connections later.
- Click next and wait a few moments while the VM is created.
Connecting to the Virtual Machine
If everything above went well, then connecting should be a snap. One thing to note: depending upon permissions and how you created your key pairs, you may have to change permissions on them. To do that you will need to issue the following command:
- sudo chmod 600 LOCATION-TO/YOURKEYNAME.key
After that is done you can SSH by issuing the following command:
ssh -i ./.ssh/YOURKEYNAME.key YOURUSERNAME@YOURDNSNAME.cloudapp.net -p22
The “i” option is the location of your identity_file, “p” is the port. If you are running into trouble you can add the V option for verbose output to see what the error is.
Once connected be sure to issue one more command out on your new VM:
- sudo apt-get update
This will install any updates to your Linux VM
Stay tuned for Part 2.