How to create a virtual machine in Azure

Introduction

Microsoft Azure provides a comprehensive cloud platform for building, deploying, and managing applications and services. One of the key components of Azure is the ability to create and manage virtual machines (VMs). Azure Virtual Machines allow you to run your applications in the cloud, providing scalability, security, and flexibility.

In this tutorial, we will walk you through the process of creating a virtual machine in Azure. We will cover everything from setting up your Azure account to configuring and managing your VM. By the end of this tutorial, you will have a working virtual machine running in Azure.

Prerequisites

Before you begin, make sure you have the following prerequisites:

  1. An Azure account: If you don’t have an Azure account, you can create a free one by visiting the Azure portal.
  2. Basic knowledge of Azure services: Familiarize yourself with the basic concepts of Azure, including Azure Resource Manager (ARM), Azure Virtual Network, and Azure Storage.

  3. A supported operating system: You can create virtual machines on Azure using Windows, Linux, or other operating systems. Make sure you have a valid license for the operating system you want to use.

  4. An SSH key pair (for Linux VMs): If you are planning to create a Linux VM, you will need an SSH key pair to authenticate your login. If you don’t have an SSH key pair, you can generate one using tools like PuTTYgen or OpenSSH.

Step 1: Sign in to the Azure Portal

To get started, sign in to the Azure portal using your Azure account credentials.

Step 2: Create a Resource Group

A resource group is a logical container for resources in Azure. It helps you organize and manage your resources as a unit. To create a virtual machine, you need to create a resource group first. Follow these steps to create a resource group:

  1. On the Azure Portal homepage, click on “Resource groups” in the left navigation menu.
  2. Click on the “+ Add” button to create a new resource group.

  3. Provide a name for the resource group, choose a region where you want to create the resources, and click on the “Review + create” button.

  4. Review the settings and click on the “Create” button to create the resource group.

Step 3: Create a Virtual Machine

Now that you have created a resource group, you can proceed to create a virtual machine. Follow these steps to create a virtual machine:

  1. In the Azure Portal, navigate to your resource group by clicking on “Resource groups” in the left navigation menu and selecting your resource group.
  2. Inside the resource group, click on the “+ Add” button to add a new resource.

  3. In the search bar, type “Virtual machine” and select “Virtual machine” from the search results.

  4. Click on the “Create” button to start the virtual machine creation process.

  5. Provide the following details in the “Basics” tab:

  • Subscription: Select the subscription you want to use for the virtual machine.
  • Resource group: Choose the resource group you created in the previous step.
  • Virtual machine name: Provide a name for your virtual machine.
  • Region: Choose the region where you want to deploy the virtual machine.
  • Availability options: Choose the availability options based on your requirements.
  • Image: Select the operating system image you want to use for your virtual machine.
  • Size: Choose the size of the virtual machine based on your workload requirements.
  • Username: Provide a username for the virtual machine.
  • Authentication type: Choose the authentication type (password or SSH public key) for the virtual machine.
  • Password/SSH public key: Provide the password or SSH public key depending on the authentication type you chose.
  1. Click on the “Next: Disks” button to configure the virtual machine’s disks.

  2. In the “Disks” tab, configure the following settings:

  • OS disk type: Choose the type of disk for the operating system. You can choose between HDD and SSD.
  • Disk encryption: Choose whether to encrypt the OS disk or not.
  • Virtual machine backup: Choose whether to enable virtual machine backups or not.
  1. Click on the “Next: Networking” button to configure the virtual machine’s networking.

  2. In the “Networking” tab, configure the following settings:

  • Virtual network: Choose the virtual network where you want to deploy the virtual machine.
  • Subnet: Choose the subnet within the virtual network.
  • Public IP: Choose whether to assign a public IP address to the virtual machine.
  • Network security group: Choose whether to associate a network security group with the virtual machine.
  • Accelerated networking: Choose whether to enable accelerated networking or not.
  1. Click on the “Next: Management” button to configure the virtual machine’s management settings.

  2. In the “Management” tab, configure the following settings:

    • Monitoring: Choose whether to enable Azure Monitor for the virtual machine.
    • Boot diagnostics: Choose whether to enable boot diagnostics for the virtual machine.
  3. Click on the “Next: Advanced” button to configure advanced settings if required.
  4. In the “Advanced” tab, configure any additional settings based on your requirements.

  5. Click on the “Review + create” button to review the settings.

  6. Review the settings and click on the “Create” button to create the virtual machine.

Step 4: Connect to the Virtual Machine

Once the virtual machine is created, you can connect to it using various remote desktop protocols or SSH. Follow these steps to connect to the virtual machine:

Connect to a Windows Virtual Machine

To connect to a Windows virtual machine, follow these steps:

  1. In the Azure Portal, navigate to the virtual machine you created.
  2. On the virtual machine overview page, click on the “Connect” button.

  3. In the “Connect to virtual machine” window, select the desired options for the connection type and the download method.

  4. Click on the “Download RDP File” button to download the Remote Desktop Protocol (RDP) file.

  5. Open the downloaded RDP file and enter the credentials for the virtual machine.

  6. Click on the “Connect” button to establish the remote desktop connection to the virtual machine.

Connect to a Linux Virtual Machine

To connect to a Linux virtual machine, follow these steps:

  1. In the Azure Portal, navigate to the virtual machine you created.
  2. On the virtual machine overview page, click on the “Connect” button.

  3. In the “Connect to virtual machine” window, select the desired options for the connection type and the download method.

  4. Click on the “Copy” button next to the SSH command to copy the command to your clipboard.

  5. Open a terminal or command prompt on your local machine and paste the SSH command.

  6. Press Enter to establish the SSH connection to the virtual machine.

Step 5: Configure the Virtual Machine

After connecting to the virtual machine, you can configure it according to your requirements. Here are some common configuration tasks:

Install Software and Dependencies

Use the package manager provided by the operating system to install software and dependencies on the virtual machine. For example, on a Linux virtual machine, you can use apt (Ubuntu/Debian) or yum (CentOS/RHEL) to install software packages.

sudo apt-get update
sudo apt-get install <package-name>

Configure Firewall and Network Settings

Use the built-in firewall and network configuration tools provided by the operating system to configure firewall rules and network settings on the virtual machine. For example, on a Linux virtual machine, you can use ufw to configure firewall rules.

sudo ufw enable
sudo ufw allow 80/tcp

Enable Remote Desktop or SSH Access

Depending on the operating system and your requirements, you may need to enable Remote Desktop or SSH access to the virtual machine. Use the appropriate tools provided by the operating system to enable and configure remote access.

  • For Windows virtual machines, use the “Remote Desktop” settings in the Control Panel.
  • For Linux virtual machines, edit the SSH server configuration file (/etc/ssh/sshd_config) to allow remote SSH access.

Set up Monitoring and Alerts

Azure provides various monitoring and alerting services that you can use to monitor the health and performance of your virtual machine. Set up monitoring and alerts based on your requirements.

  • For Windows virtual machines, you can use Azure Monitor and configure alerts using the Azure portal.
  • For Linux virtual machines, you can use tools like Prometheus or Nagios to monitor the virtual machine’s performance, and configure alerts based on the monitoring metrics.

Step 6: Manage and Scale the Virtual Machine

Once your virtual machine is up and running, you can manage and scale it as needed. Here are some common management tasks:

Start, Stop, and Restart the Virtual Machine

You can start, stop, or restart the virtual machine using the Azure portal or command-line tools. To start or stop the virtual machine, navigate to the virtual machine in the Azure portal and use the “Start” or “Stop” button. To restart the virtual machine, use the “Restart” button.

Resize the Virtual Machine

If you need more resources for your virtual machine, you can resize it to a different size with more CPU, memory, or storage. To resize the virtual machine, navigate to the virtual machine in the Azure portal and use the “Size” option to choose a different size.

Configure High Availability and Load Balancing

For critical workloads or applications that require high availability, you can configure virtual machine scale sets and load balancers in Azure. Virtual machine scale sets allow you to automatically scale the number of virtual machines based on demand, while load balancers distribute incoming network traffic across multiple virtual machines. Configure high availability and load balancing based on your workload requirements.

Conclusion

In this tutorial, you learned how to create a virtual machine in Azure using the Azure portal. You also learned how to connect to the virtual machine, configure it according to your requirements, and manage and scale it as needed. Azure Virtual Machines provide a flexible and powerful platform for running your applications in the cloud. By following the steps in this tutorial, you can easily create and manage virtual machines in Azure.

Related Post