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
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-keysOp het werk
Do not give servers a public IP. Reach them through Azure Bastion or a VPN, and publish apps through a load balancer.
Choose a size
The letter of the size family tells the purpose.
| Family | For |
|---|---|
| B | Burstable: small, cheap, mostly idle servers |
| D | General purpose: most servers |
| E | Memory optimised: databases, caches |
| F | Compute optimised: CPU-heavy jobs |
| L | Storage optimised: big, fast local disks |
| N | GPU: 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_v5Onthoud
A resize restarts the VM. If the new size is not available on the current hardware cluster, stop (deallocate) the VM first.
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 type | For |
|---|---|
| Standard HDD | Backups, rarely used data |
| Standard SSD | Light servers, dev/test |
| Premium SSD | Production servers and databases |
| Premium SSD v2 / Ultra | Very 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-data1In the VM, partition, format and mount the new disk like any Linux disk: Create partitions and file systems.
Plan for availability
One VM can fail. Two or more VMs in zones or an availability set keep the service running.
| Option | Spreads VMs over | SLA (2+ VMs) |
|---|---|---|
| Availability set | Fault domains (racks) and update domains in one data centre | 99.95 % |
| Availability zones | Separate data centres in the region | 99.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-keysScale 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 1Configure 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 tableOp het werk
For bigger setups, use cloud-init (--custom-data cloud-init.yaml) at create time, or configuration tools like Ansible.
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.
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.