Day 13: Azure Az-900: Launching Your First Azure Virtual Machine: A Step-by-Step Guide

Day 13: Azure Az-900: Launching Your First Azure Virtual Machine: A Step-by-Step Guide

The cloud offers unparalleled flexibility and scalability, and Azure Virtual Machines (VMs) are a cornerstone of this powerful technology. VMs act as virtualised computers residing in the cloud, providing you with control and customisation akin to physical servers. This blog post will be your guide to launching your very first Azure VM instance, walking you through each configuration option.

Prerequisites:

  • An active Azure subscription (you can sign up for a free trial)
  • A basic understanding of cloud computing concepts

Step 1: Access the Azure Portal

Head over to the Azure portal (https://azure.microsoft.com/en-us/get-started/azure-portal ) and sign in using your Microsoft account credentials. This is your central hub for managing all Azure resources, including VMs.

Step 2: Create a Virtual Machine

  1. Click on “Create a resource” in the top left corner of the dashboard.
  2. In the search bar, type “Virtual Machine” and press Enter.
  3. Select “Virtual Machine” from the search results.

Step 3: Choose a Project and Resource Group

  • Project: Organise your Azure resources into logical groups called projects. If you haven’t created one yet, select “Create new” and provide a name.
  • Resource group: This further categorises resources within a project. Create a new resource group with a descriptive name for your VM.

Step 4: Specify VM Instance Details

  • Name: Choose a clear and identifiable name for your VM instance.

  • Region: Select the geographic location where your VM will reside. Consider factors like latency and regulatory compliance.
  • Availability zone (optional): Enhance your VM’s resiliency by placing it within an availability zone, a physically separate location within the chosen region. This minimises downtime due to localised hardware failures. In our previous blogs learned about Availability Zone , Virtual machine scale set , Availability Set

Step 5: Select a Virtual Machine Size

Azure offers a wide range of VM sizes catering to diverse workloads. Here’s a breakdown of key factors to consider:

  • vCPUs (virtual CPUs): The number of virtual cores available for processing tasks. More vCPUs are suitable for computationally intensive workloads.

  • Memory (RAM): The amount of temporary data storage. Higher RAM is beneficial for applications requiring frequent data access.
  • Storage: Select the type and size of storage disks for your VM. Choose from HDDs for cost-effective storage of large datasets or SSDs for faster performance with frequently accessed data.

Step 6: Configure the Virtual Machine Image

  • Operating System: Azure provides a vast library of operating system images, including various Windows Server and Linux distributions. Choose the OS that aligns with your application requirements

  • Marketplace image (optional): Explore pre-configured images with specific software pre-installed, streamlining your VM setup for tasks like development or web hosting.

Step 7: Network Configuration

  • Virtual network: Create a new virtual network or select an existing one to connect your VM to Azure resources and the internet


  • Subnet: Define a subnet within the virtual network to logically group your VMs.
  • Public IP address (optional): Assign a public IP address if your VM needs to be accessible over the internet.

  • Load Balancer: In our previous blog we learned about load balancers

Step 8: Management Setti

gs

  • Authentication type: Choose between password-based or SSH key authentication for securing access to your VM.
  • Boot diagnostics (optional): Enable boot diagnostics for troubleshooting potential boot issues with your VM.

Advance Features of Azure Virtual?Machine

Above we equipped ourselves with the knowledge to launch our first Azure Virtual Machine (VM). Now, let’s delve deeper and explore the advanced features that unlock the true power of Azure VMs.

Security Enhancements

Securing your VMs is mission-critical. Here’s how Azure empowers you to create a virtual fortress:

  • Just-In-Time (JIT) Access: Imagine granting access to your house only when a guest arrives. JIT Access functions similarly, providing temporary access to VMs only when needed. This significantly reduces the window of vulnerability for attackers.
  • Azure Security Center: Think of this as your personal security guard for your VMs. Azure Security Center continuously monitors your VMs for threats, identifies vulnerabilities, and suggests remediation steps. It’s like having a security expert constantly on watch, proactively safeguarding your environment.
  • Managed Disks: Encryption is vital for protecting sensitive data. With Azure managed disks, your VM storage is automatically encrypted at rest (when stored on Azure servers) and in transit (when moving between servers). This adds an extra layer of security, ensuring your data remains confidential even if someone manages to breach your system.


Networking Optimisation

Azure provides a robust set of networking features to tailor your VM’s connectivity:

  • Network Security Groups (NSGs): Think of NSGs as firewalls for individual VMs. You can define rules to control incoming and outgoing traffic, allowing only authorised connections. This granular control enhances security by blocking unwanted traffic before it reaches your VMs.

  • Azure Load Balancer: Imagine a busy restaurant with a single waiter struggling to serve everyone. A load balancer acts the same way for your VMs, distributing incoming traffic across multiple VMs to ensure optimal performance and prevent any single VM from becoming overloaded. This guarantees a seamless user experience for your applications, even during peak traffic periods.
  • Azure Virtual Network Peering: Do you have resources both on-premises (in your own datacenter) and in Azure? Virtual Network Peering allows VMs in different virtual networks to communicate securely, as if they were on the same network. This eliminates the need for complex configurations and simplifies communication between your on-premises environment and your Azure resources.


Advanced Management Tools

Managing multiple VMs can be time-consuming. Azure offers automation tools to streamline the process:

  • Azure Automation: Imagine a robot assistant handling repetitive tasks for you. Azure Automation allows you to automate VM management tasks like starting, stopping, and configuring settings. This frees you up to focus on more strategic initiatives.

  • Azure Resource Manager (ARM) Templates: Think of these as blueprints for your VMs. ARM templates define the configuration of your VMs in a reusable format. This ensures consistent and efficient deployments, eliminating the need for manual configuration each time you create a new VM.
  • Azure Monitor: Gain real-time insights into your VM’s health and performance with Azure Monitor. It provides detailed metrics on CPU utilization, memory usage, network traffic, and other key indicators. This allows you to proactively identify potential issues and take corrective action before they impact your applications.


Cost Management Strategies

Cloud costs can add up quickly if not managed effectively. Here are some strategies to keep your spending in check:

  • Reserved Instances: Think of reserving a hotel room at a discounted rate for a long stay. Reserved Instances offer significant cost savings compared to on-demand pricing if you commit to using VMs for a specific period. This is ideal for predictable workloads with consistent resource requirements.
  • Spot VMs: Imagine getting amazing deals on last-minute flights. Spot VMs are similar, offering VMs at significantly discounted prices when Azure has excess capacity. This is a good option for workloads with flexible timelines that can tolerate short interruptions. However, be aware that Spot VMs can be preempted by Azure if needed, so they’re not suitable for mission-critical applications.
  • Virtual Machine Scale Sets: Managing a large number of individual VMs can be cumbersome. Scale sets allow you to manage a group of identical VMs that automatically scale up or down based on predefined rules. This ensures you only pay for the resources you actually use, optimising cost-efficiency. For example, a scale set can automatically add VMs during peak traffic hours and remove them during off-peak times.

Step 9: Review and Create

Carefully review all your configuration choices before creating your VM instance. Once satisfied, click “Create” to provision your virtual machine in Azure.

Congratulations! You’ve successfully launched your first Azure VM instance. The deployment process might take a few minutes, but you can monitor its progress within the Azure portal.

Create Azure Instance using Azure?CLI

Create a Linux virtual machine and install?Nginx

Use the following Azure CLI commands to create a Linux VM and install Nginx. After your VM is created, you’ll use the Custom Script Extension to install Nginx. The Custom Script Extension is an easy way to download and run scripts on your Azure VMs. It’s just one of the many ways you can configure the system after your VM is up and running.

  1. From Cloud Shell, run the following az vm create command to create a Linux VM:
  2. Azure CLICopy

az vm create \
  --resource-group "Test" \
  --name my-vm \
  --public-ip-sku Standard \
  --image Ubuntu2204 \
  --admin-username azureuser \
  --generate-ssh-key        

  1. Your VM will take a few moments to come up. You named the VM my-vm. You use this name to refer to the VM in later steps.
  2. Run the following az vm extension set command to configure Nginx on your VM:
  3. Azure CLICopy

az vm extension set \
   --resource-group "Test" \   
   --vm-name my-vm \   
   --name customScript \   
   --publisher Microsoft.Azure.Extensions \
   --version 2.1 \
   --settings '{"fileUris":["https://raw.githubusercontent.com/MicrosoftDocs/mslearn-welcome-to-azure/master/configure-nginx.sh"]}' \
   --protected-settings '{"commandToExecute": "./configure-nginx.sh"}'        

  1. This command uses the Custom Script Extension to run a Bash script on your VM. The script is stored on GitHub. While the command runs, you can choose to examine the Bash script from a separate browser tab. To summarise, the script:
  2. Runs apt-get update to download the latest package information from the internet. This step helps ensure that the next command can locate the latest version of the Nginx package.
  3. Installs Nginx.
  4. Sets the home page, /var/www/html/index.html, to print a welcome message that includes your VM’s host name.


This blog series has equipped you with a comprehensive understanding of Azure VMs, from launching your first instance to exploring advanced features for security, networking, automation, cost management, and more. By now, you’ve grasped the power and flexibility Azure VMs offer for building scalable and robust cloud solutions.

The Road Ahead

The world of Azure VMs is vast and ever-evolving. Here are some additional resources to fuel your journey:

We encourage you to experiment, explore, and leverage the vast capabilities of Azure VMs. As you gain experience, you’ll unlock the true potential of cloud computing for your projects and endeavours.

Stay tuned for future blog posts where we’ll delve into other exciting Azure services and solutions!


要查看或添加评论,请登录

社区洞察

其他会员也浏览了