Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberenu aan te melden ofde directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen demappen te wijzigen.
Van toepassing op: ✔️ Flexibele schaalsets voor Linux-VM's ✔️
This article shows you how to use cloud-init to configure the swap partition on various Linux distributions. The swap partition was traditionally configured by the Linux Agent (WALA) based on which distributions required one. This document outlines the process for building the swap partition on demand during provisioning time using cloud-init. Zie het overzicht van cloud-init voor meer informatie over hoe cloud-init systeemeigen werkt in Azure en de ondersteunde Linux-distributies
Create swap partition for Ubuntu based images
By default on Azure, Ubuntu gallery images don't create swap partitions. To enable swap partition configuration during VM provisioning time using cloud-init - please see the AzureSwapPartitions document on the Ubuntu wiki.
Create swap partition for RHEL based images
Create a file in your current shell named cloud_init_swappart.txt and paste the following configuration. Maak voor dit voorbeeld het bestand in Cloud Shell niet op uw lokale computer. U kunt elke editor die u wilt gebruiken. Zorg ervoor dat het hele cloud-init-bestand correct is gekopieerd, met name de eerste regel.
#cloud-config
disk_setup:
ephemeral0:
table_type: gpt
layout: [66, [33,82]]
overwrite: true
fs_setup:
- device: ephemeral0.1
filesystem: ext4
- device: ephemeral0.2
filesystem: swap
mounts:
- ["ephemeral0.1", "/mnt"]
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service", "0", "0"]
The mount is created with the nofail option to ensure that the boot process continues even if the mount isn't completed successfully.
Voordat u deze image implementeert, moet u met de opdracht az group create een resourcegroep maken. Een Azure-resourcegroep is een logische container waarin Azure-resources worden geïmplementeerd en beheerd. In het volgende voorbeeld wordt een resourcegroep met de naam myResourceGroup gemaakt in de regio eastus.
az group create --name myResourceGroup --location eastus
Maak nu een virtuele machine met az vm create en geef het cloud-init-bestand --custom-data cloud_init_swappart.txt als volgt op:
az vm create \
--resource-group myResourceGroup \
--name vmName \
--image imageCIURN \
--custom-data cloud_init_swappart.txt \
--generate-ssh-keys
Opmerking
Vervang de waarden myResourceGroup, vmName en imageCIURN dienovereenkomstig. Zorg ervoor dat een afbeelding met Cloud-init is gekozen.
Modify an already running machine
If you already provisioned your server and wish to modify the mount point of the ephemeral storage and want to configure a part of the disk as swap space, use the following steps.
Create cloud-init configuration file named 00-azure-swap.cfg in the /etc/cloud/cloud.cfg.d directory with the following content:
#cloud-config
disk_setup:
ephemeral0:
table_type: gpt
layout: [66, [33,82]]
overwrite: true
fs_setup:
- device: ephemeral0.1
filesystem: ext4
- device: ephemeral0.2
filesystem: swap
mounts:
- ["ephemeral0.1", "/mnt"]
- ["ephemeral0.2", "none", "swap", "sw,nofail,x-systemd.requires=cloud-init.service", "0", "0"]
Next, append a line to the /etc/systemd/system.conf file with following content:
DefaultEnvironment="CLOUD_CFG=/etc/cloud/cloud.cfg.d/00-azure-swap.cfg"
Opmerking
The name of the file is totally arbitrary, it can be replaced with any particular name of your preference, it just needs the .cfg suffix and make sure to reflect the changes in the CLOUD_CFG parameter line as well.
After the changes are done, the machine needs to be deallocated or redeployed for the changes to take effect.
Verify swap partition was created
SSH naar het openbare IP-adres van uw VM zoals getoond in de uitvoer van het voorgaande commando. Voer als volgt uw eigen gebruiker en publicIpAddress in:
ssh <user>@<publicIpAddress>
Once you have SSH'ed into the vm, check if the swap partition was created
sudo swapon -s
The output from this command should look like this:
Filename Type Size Used Priority
/dev/sdb2 partition 2494440 0 -1
Opmerking
If you have an existing Azure image that has a swap partition configured and you want to change the swap partition configuration for new images, you should remove the existing swap partition. Please see Customize Images to provision by cloud-init document for more details.
Volgende stappen
For more cloud-init examples of configuration changes, see the following: