Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Azure Virtual Machines Tutorial

Introduction

Azure Virtual Machines (VMs) are one of the primary services offered by Microsoft Azure. They allow you to create scalable, on-demand computing resources in the cloud. Whether you need to host applications, databases, or development environments, Azure VMs provide a versatile and powerful solution.

Prerequisites

Before you start, ensure you have the following:

  • An active Azure subscription. If you don't have one, you can create a free account at Azure Free Account.
  • Basic understanding of cloud computing concepts.

Creating a Virtual Machine

Follow these steps to create your first Azure Virtual Machine:

  1. Navigate to the Azure Portal: Go to the Azure Portal.
  2. Create a Resource: Click on "Create a resource" and select "Virtual Machine" from the list of available resources.
  3. Configure Basic Settings: Fill in the required fields such as the VM name, region, and image (e.g., Windows Server, Ubuntu).
  4. Choose Size: Select the size of the VM based on the required CPU, memory, and disk space.
  5. Configure Networking: Configure the virtual network, subnet, and public IP address.
  6. Review and Create: Review your settings and click "Create" to provision the VM.

Example:

az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys

Connecting to Your Virtual Machine

Once your VM is created, you can connect to it using SSH (for Linux VMs) or RDP (for Windows VMs).

Connecting to a Linux VM:

  1. Open a terminal on your local machine.
  2. Use the SSH command to connect to your VM:
    ssh azureuser@your-vm-ip-address

Connecting to a Windows VM:

  1. Open the Remote Desktop Connection application on your local machine.
  2. Enter the public IP address of your VM and click "Connect".
  3. Log in using the credentials you specified during VM creation.

Managing Your Virtual Machine

Azure provides several options to manage your VM, including starting, stopping, and resizing it. You can perform these actions through the Azure Portal or using the Azure CLI.

Using Azure Portal:

  • Navigate to your VM in the Azure Portal.
  • Use the "Start", "Stop", and "Restart" buttons to manage the VM's state.
  • To resize the VM, click on "Size" and select a new size from the available options.

Using Azure CLI:

Here are some common commands to manage your VM:

Starting a VM:

az vm start --resource-group myResourceGroup --name myVM

Stopping a VM:

az vm stop --resource-group myResourceGroup --name myVM

Resizing a VM:

az vm resize --resource-group myResourceGroup --name myVM --size Standard_DS2_v2

Monitoring and Diagnostics

Azure provides robust monitoring and diagnostic tools to help you keep track of your VM's performance and health.

Using Azure Portal:

  • Navigate to your VM in the Azure Portal.
  • Click on "Monitoring" in the left-hand menu to view metrics such as CPU usage, disk I/O, and network statistics.
  • Set up alerts to notify you of any performance issues or threshold breaches.

Using Azure Monitor:

Azure Monitor offers advanced monitoring capabilities across your Azure resources.

Example:

az monitor metrics list --resource /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName} --metric-names "Percentage CPU"

Conclusion

In this tutorial, we covered the basics of Azure Virtual Machines, including creating, connecting, managing, and monitoring VMs. Azure VMs offer a flexible and scalable solution for various computing needs, and with the Azure Portal and CLI, managing these resources is straightforward. Continue exploring Azure's documentation and resources to deepen your understanding and make the most of Azure Virtual Machines.