Introduction
This tutorial will walk you through the essential steps to create and configure your very first Virtual Machine (VM) on Microsoft Azure. Azure VMs provide on-demand, scalable computing resources, allowing you to deploy and manage applications without the need for physical hardware.
Note: This tutorial assumes you have an active Azure subscription. If not, you can create a free account.
Prerequisites
- An Azure Subscription (Free trial or Paid).
- A web browser with internet access.
Step 1: Sign in to the Azure Portal
Navigate to the Azure Portal
Open your web browser and go to https://portal.azure.com. Sign in using your Azure account credentials.
Locate the Virtual Machines Service
Once logged in, you will see the Azure dashboard. In the search bar at the top, type "Virtual machines" and select "Virtual machines" from the results.
Step 2: Create a New Virtual Machine
Start the Creation Process
On the Virtual machines page, click the + Create button and then select Virtual machine.
Configure Basic Settings
You will be presented with several tabs to configure your VM. Let's start with the 'Basics' tab:
- Subscription: Select your Azure subscription.
- Resource group: Click "Create new" and give it a descriptive name (e.g.,
myResourceGroup-VM). A resource group is a logical container for your Azure resources. - Virtual machine name: Enter a unique name for your VM (e.g.,
myFirstVM). - Region: Choose a region geographically close to you or your users.
- Availability options: For this tutorial, you can leave this as default ("No infrastructure redundancy required").
- Security type: Leave as "Standard".
- Image: Select an operating system image. For example, choose
Windows Server 2022 Datacenter: Azure Edition - Gen2or a Linux distribution likeUbuntu Server 22.04 LTS - Gen2. - Size: Choose a VM size that fits your needs and budget. For testing, a smaller size like
Standard_B1sorStandard_D2s_v3is often sufficient. - Administrator account:
- Username: Enter an administrator username (e.g.,
azureuser). - Password: Enter a strong password, confirm it. Alternatively, you can use SSH public key authentication for Linux VMs.
- Username: Enter an administrator username (e.g.,
- Inbound port rules:
- Public inbound ports: Select Allow selected ports.
- Select inbound ports: For Windows, select RDP (3389). For Linux, select SSH (22). This allows you to connect to your VM.
Configure Disks
On the 'Disks' tab, you can configure the storage for your VM. The default settings are usually fine for a basic setup. You can choose the OS disk type (e.g., Premium SSD for better performance).
Configure Networking
On the 'Networking' tab, Azure automatically creates a virtual network, subnet, public IP address, and network security group (NSG). You can review these or customize them if you have specific requirements. Ensure the NSG allows inbound traffic on the port you selected (RDP or SSH).
Advanced and Tags (Optional)
The 'Advanced' tab allows for further customization like extensions, cloud-init data (for Linux), and management settings. The 'Tags' tab is useful for organizing your Azure resources. You can add tags like Environment: Development or Project: MyProject.
Review and Create
Click the Review + create button. Azure will validate your configuration. If validation passes, you'll see a summary of your VM settings. Review everything carefully, then click Create.
Important: If you are using SSH keys for Linux and chose that option, you will be prompted to download your private key. Store this key securely, as it's your only way to access the VM.
Deployment Progress
Azure will now start deploying your virtual machine. This process typically takes a few minutes. You can monitor the deployment progress on the deployment page.
Step 3: Connect to Your Virtual Machine
Accessing the VM Overview
Once the deployment is complete, click on "Go to resource" or navigate back to the "Virtual machines" service and select your newly created VM. You will see the VM's overview page.
For Windows VM (RDP)
- On the VM overview page, click the Connect button.
- Select "RDP" and click "Download RDP File".
- Open the downloaded RDP file.
- When prompted, click "Connect".
- Enter the username and password you created earlier.
- You may see a certificate warning; click "Yes" to proceed.
For Linux VM (SSH)
- On the VM overview page, click the Connect button.
- Select "SSH". You will see connection instructions.
- Open your terminal or SSH client.
- Use the provided command, replacing placeholders with your VM's public IP address and your username. If using an SSH key, ensure the key file has the correct permissions (
chmod 400 /path/to/your/private.key). - Example command:
ssh azureuser@20.45.67.89(replace with your details). - If prompted about the authenticity of the host, type
yes.
You can find your VM's Public IP address on the VM overview page.
Step 4: Basic VM Management
Starting and Stopping Your VM
On the VM overview page, you can use the Start, Stop, and Restart buttons to manage the VM's power state. Stopping a VM deallocates its resources, saving costs.
Monitoring Performance
The "Monitoring" section of the VM blade provides insights into CPU usage, network traffic, disk I/O, and more. This is crucial for understanding your VM's performance and identifying potential issues.
Deleting Your VM
When you no longer need the VM, it's important to delete it to avoid ongoing charges. Navigate to the VM's overview page, click Delete. You will typically also want to delete the associated resources like the Public IP address, Network Interface, and Disks if they are no longer needed. Deleting the resource group will also delete all resources within it.
Caution: Deleting a VM and its associated resources is irreversible. Ensure you have backed up any critical data before proceeding.
Conclusion
Congratulations! You have successfully deployed and connected to your first Azure Virtual Machine. This is a fundamental building block for many cloud solutions. You can now install applications, host websites, or run any workload you need.
Explore further by learning about different VM sizes, storage options, networking configurations, and security best practices in Azure.