적용 대상: ✔️ Linux VM ✔️ 유연한 확장 집합
This article shows you how to use cloud-init to configure a specific hostname on a virtual machine (VM) or virtual machine scale sets (VMSS) at provisioning time in Azure. Azure에서 리소스가 프로비전되면 처음 부팅 시 이러한 cloud-init 스크립트가 실행됩니다. 기본적으로 cloud-init가 Azure에서 작동되는 방식과 지원되는 Linux 배포판에 대한 자세한 내용은 cloud-init 개요를 참조하세요.
Set the hostname with cloud-init
By default, the hostname is the same as the VM name when you create a new virtual machine in Azure. To run a cloud-init script to change this default hostname when you create a VM in Azure with az vm create, specify the cloud-init file with the --custom-data switch.
To see upgrade process in action, create a file in your current shell named cloud_init_hostname.txt and paste the following configuration. 이 예제에서는 로컬 컴퓨터에 없는 Cloud Shell에서 파일을 만듭니다. 원하는 모든 편집기를 사용할 수 있습니다. 전체 cloud-init 파일, 특히 첫 줄이 올바르게 복사되었는지 확인합니다.
#cloud-config
fqdn: myhostname
이 이미지를 배포하기 전에 az group create 명령을 사용하여 리소스 그룹을 만들어야 합니다. Azure 리소스 그룹은 Azure 리소스가 배포 및 관리되는 논리적 컨테이너입니다. 다음 예제에서는 eastus 위치에 myResourceGroup이라는 리소스 그룹을 만듭니다.
az group create --name myResourceGroup --location eastus
이제 az vm create로 VM을 만들고 다음과 같이 --custom-data cloud_init_hostname.txt로 cloud-init 파일을 지정합니다.
az vm create \
--resource-group myResourceGroup \
--name vmName \
--image imageCIURN \
--custom-data cloud_init_hostname.txt \
--generate-ssh-keys
비고
myResourceGroup, vmName, imageCIURN 값을 적절하게 바꿉니다. Cloud-init가 포함된 이미지가 선택되어 있는지 확인합니다.
Once created, the Azure CLI shows information about the VM. Use the publicIpAddress to SSH to your VM. Enter your own address as follows:
ssh <user>@<publicIpAddress>
To see the VM name, use the hostname command as follows:
sudo hostname
The VM should report the hostname as that value set in the cloud-init file, as shown in the following example output:
myhostname
다음 단계
구성 변경에 대한 추가 cloud-init 예제를 보려면 다음을 참조하세요.