0%
Azure CLI Commands for Virtual Machines

Azure CLI Commands for Virtual Machines

Discover the Azure CLI commands for creating and managing virtual machines with web servers.

I

InSkillCoach

· min

Azure CLI Commands for Virtual Machines

Discover the essential commands for managing Azure virtual machines and installing web servers.

Creating a Virtual Machine

Create a resource group

# Create a resource group
az group create --name mon-groupe --location westeurope

# Create a virtual network
az network vnet create \
    --resource-group mon-groupe \
    --name mon-vnet \
    --subnet-name mon-subnet

# Create a public IP address
az network public-ip create \
    --resource-group mon-groupe \
    --name mon-ip \
    --sku Standard

Create a Linux VM

# Create an Ubuntu VM
az vm create \
    --resource-group mon-groupe \
    --name ma-vm \
    --image UbuntuLTS \
    --size Standard_B1s \
    --admin-username azureuser \
    --generate-ssh-keys \
    --public-ip-address mon-ip \
    --vnet-name mon-vnet \
    --subnet mon-subnet

Create a Windows VM

# Create a Windows VM
az vm create \
    --resource-group mon-groupe \
    --name ma-vm-windows \
    --image Win2019Datacenter \
    --size Standard_B1s \
    --admin-username azureuser \
    --admin-password MonMotDePasse123! \
    --public-ip-address mon-ip \
    --vnet-name mon-vnet \
    --subnet mon-subnet

Installing Web Servers

Installing Apache on Ubuntu

# Connect to the VM
ssh azureuser@<ip-publique>

# Update packages
sudo apt update && sudo apt upgrade -y

# Install Apache
sudo apt install apache2 -y

# Start Apache
sudo systemctl start apache2
sudo systemctl enable apache2

# Check the status
sudo systemctl status apache2

Installing Nginx on Ubuntu

# Connect to the VM
ssh azureuser@<ip-publique>

# Update packages
sudo apt update && sudo apt upgrade -y

# Install Nginx
sudo apt install nginx -y

# Start Nginx
sudo systemctl start nginx
sudo systemctl enable nginx

# Check the status
sudo systemctl status nginx

Installing IIS on Windows

# Connect to the VM via RDP
# Open PowerShell as administrator

# Install IIS
Install-WindowsFeature -Name Web-Server -IncludeManagementTools

# Verify the installation
Get-WindowsFeature Web-Server

Firewall Configuration

Configuring Ubuntu (UFW)

# Install UFW
sudo apt install ufw -y

# Configure the rules
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https

# Enable the firewall
sudo ufw enable

# Check the status
sudo ufw status

Configuring Windows (Windows Firewall)

# Allow HTTP traffic
New-NetFirewallRule -DisplayName "HTTP" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 80

# Allow HTTPS traffic
New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 443

Managing VMs

Basic commands

# Start a VM
az vm start --resource-group mon-groupe --name ma-vm

# Stop a VM
az vm stop --resource-group mon-groupe --name ma-vm

# Restart a VM
az vm restart --resource-group mon-groupe --name ma-vm

# Delete a VM
az vm delete --resource-group mon-groupe --name ma-vm

Managing disks

# Create a disk
az disk create \
    --resource-group mon-groupe \
    --name mon-disque \
    --size-gb 10 \
    --sku Standard_LRS

# Attach a disk
az vm disk attach \
    --resource-group mon-groupe \
    --vm-name ma-vm \
    --disk mon-disque

Best Practices

  1. Security

    • Use strong passwords
    • Configure the firewall
    • Apply updates regularly
    • Use SSH keys
  2. Performance

    • Choose the right VM size
    • Optimize disks
    • Monitor resources
    • Use optimized images
  3. Costs

    • Stop unused VMs
    • Use reservations
    • Monitor usage
    • Clean up resources

Conclusion

Key takeaways:

  • Essential CLI commands
  • Installing web servers
  • Security configuration
  • Resource management

Recommendations:

  • Document your commands
  • Automate installations
  • Follow best practices
  • Monitor costs
  • Train on Microsoft Learn
InSkillCoach

About InSkillCoach

Training and technology expert

Coach specializing in advanced technologies and AI, backed by GNeurone Inc.

Certifications:

  • AWS Certified Solutions Architect – Professional
  • Google Cloud certifications
  • Microsoft Certified: DevOps Engineer Expert
  • Certified Kubernetes Administrator (CKA)
  • CompTIA Security+
1.5k
128

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!