Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 7Naam in de cursus: Create and configure virtual machines

Create and run virtual machines

Azure VMs are the cloud version of the servers you know. This chapter covers sizes, images, disks, availability (sets and zones), scale sets, extensions, encryption, resizing and moving VMs.

  • 8 Lessen
  • 3 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Vaardigheden in dit hoofdstuk

  • Virtuele machines en scale sets maken en instellen

7.1

Create a VM

A VM needs a resource group, an image, a size, a network and a way to log in (SSH key for Linux).

az vm create -g rg-web -n vm-web1 --image Ubuntu2404 --size Standard_B2s \
    --admin-username azureuser --generate-ssh-keys --vnet-name vnet-prod --subnet snet-web \
    --public-ip-address "" --nsg ""
az vm list -g rg-web -d -o table
az vm image list --publisher RedHat --offer RHEL --all -o table | tail -5
az vm create -g rg-web -n vm-rhel1 --image RedHat:RHEL:9-lvm-gen2:latest --size Standard_D2s_v5 --admin-username azureuser --generate-ssh-keys

Op het werk

Do not give servers a public IP. Reach them through Azure Bastion or a VPN, and publish apps through a load balancer.

7.2

Choose a size

The letter of the size family tells the purpose.

FamilyFor
BBurstable: small, cheap, mostly idle servers
DGeneral purpose: most servers
EMemory optimised: databases, caches
FCompute optimised: CPU-heavy jobs
LStorage optimised: big, fast local disks
NGPU: AI and graphics
az vm list-sizes -l westeurope -o table | grep -E 'Standard_D2s_v5|Standard_B2s'
az vm resize -g rg-web -n vm-web1 --size Standard_D2s_v5

Onthoud

A resize restarts the VM. If the new size is not available on the current hardware cluster, stop (deallocate) the VM first.

7.3

Add and manage disks

A VM has an OS disk, optional data disks and a temporary disk (lost at redeploy — never keep data there).

Disk typeFor
Standard HDDBackups, rarely used data
Standard SSDLight servers, dev/test
Premium SSDProduction servers and databases
Premium SSD v2 / UltraVery high IOPS, size and speed set separately
az vm disk attach -g rg-web --vm-name vm-web1 --name disk-data1 --new --size-gb 64 --sku Premium_LRS
az disk update -g rg-web -n disk-data1 --size-gb 128
az snapshot create -g rg-web -n snap-data1 --source disk-data1

In the VM, partition, format and mount the new disk like any Linux disk: Create partitions and file systems.

Commando's in deze les

7.4

Plan for availability

One VM can fail. Two or more VMs in zones or an availability set keep the service running.

OptionSpreads VMs overSLA (2+ VMs)
Availability setFault domains (racks) and update domains in one data centre99.95 %
Availability zonesSeparate data centres in the region99.99 %
Single VM, Premium SSD—99.9 %
az vm create -g rg-web -n vm-web2 --image Ubuntu2404 --zone 2 --size Standard_D2s_v5 --admin-username azureuser --generate-ssh-keys

Commando's in deze les

7.5

Scale out with scale sets

A Virtual Machine Scale Set runs many identical VMs and adds or removes them by rules (autoscale).

az vmss create -g rg-web -n vmss-web --image Ubuntu2404 --instance-count 2 --zones 1 2 3 \
    --admin-username azureuser --generate-ssh-keys --vnet-name vnet-prod --subnet snet-web
az monitor autoscale create -g rg-web --resource vmss-web --resource-type Microsoft.Compute/virtualMachineScaleSets --name as-web --min-count 2 --max-count 6 --count 2
az monitor autoscale rule create -g rg-web --autoscale-name as-web --condition "Percentage CPU > 70 avg 5m" --scale out 1

Commando's in deze les

7.6

Configure VMs with extensions

Extensions run tasks inside a VM after it is created: a script, the monitoring agent, disk encryption.

az vm extension set -g rg-web --vm-name vm-web1 --name CustomScript --publisher Microsoft.Azure.Extensions \
    --settings '{"commandToExecute":"apt-get update && apt-get install -y nginx"}'
az vm run-command invoke -g rg-web -n vm-web1 --command-id RunShellScript --scripts "systemctl status nginx"
az vm extension list -g rg-web --vm-name vm-web1 -o table

Op het werk

For bigger setups, use cloud-init (--custom-data cloud-init.yaml) at create time, or configuration tools like Ansible.

Commando's in deze les

7.7

Encrypt VM disks

Disks are encrypted at rest by default (server-side encryption). For more, use encryption at host or customer-managed keys.

  • Server-side encryption (SSE): always on, platform or customer-managed keys.
  • Encryption at host: also encrypts temp disks and caches.
  • Azure Disk Encryption (ADE): BitLocker / dm-crypt inside the VM, keys in Key Vault.

7.8

Move a VM

VMs (with their disks, NICs and IPs) can move to another resource group or subscription; to another region with Azure Resource Mover or Site Recovery.

az resource move --destination-group rg-web-new --ids $(az vm show -g rg-web -n vm-web1 --query id -o tsv) $(az disk list -g rg-web --query "[].id" -o tsv)

Onthoud

The move does not change the region. All dependent resources must move together.

Commando's in deze les

Alle commando's in dit hoofdstuk