Share via


CLI 예제: Azure Batch에서 Linux 풀 만들기 및 관리

이 스크립트는 Azure Batch에서 Linux 컴퓨팅 노드 풀을 만들고 관리할 수 있는 Azure CLI 명령 중 일부를 보여줍니다.

Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

사전 요구 사항

샘플 스크립트

Azure Cloud Shell 시작

Azure Cloud Shell은 이 항목의 단계를 실행하는 데 무료로 사용할 수 있는 대화형 셸입니다. 공용 Azure 도구가 사전 설치되어 계정에서 사용하도록 구성되어 있습니다.

Cloud Shell을 열려면 코드 블록의 오른쪽 위 모서리에 있는 사용해 보세요를 선택하기만 하면 됩니다. 또한 https://shell.azure.com 로 이동하여 별도의 브라우저 탭에서 Cloud Shell을 시작할 수 있습니다.

Cloud Shell이 열리면 환경에 대해 Bash가 선택되어 있는지 확인합니다. 후속 세션은 Bash 환경에서 Azure CLI를 사용합니다. 복사를 선택하여 코드 블록을 복사하고 Cloud Shell에 붙여넣고 Enter 키를 눌러 실행합니다.

Azure에 로그인

Cloud Shell은 로그인한 초기 계정에서 자동으로 인증됩니다. 다음 스크립트를 통해 다른 구독을 사용하여 로그인하고 <Subscription ID>를 Azure 구독 ID로 바꿉니다. Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

자세한 내용은 활성 구독 설정 또는 대화형으로 로그인을 참조하세요.

Azure Batch에서 Linux 풀을 만들려면 다음을 수행합니다.

# Create and manage a Linux pool in Azure Batch

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
[[ "$RESOURCE_GROUP" == '' ]] && resourceGroup="msdocs-batch-rg-$randomIdentifier" || resourceGroup="${RESOURCE_GROUP}"
tag="manage-pool-linux"
batchAccount="msdocsbatch$randomIdentifier"

# Create a resource group.
echo "Creating $resourceGroup in "$location"..."
az group create --name $resourceGroup --location "$location" --tag $tag

# Create a Batch account.
echo "Creating $batchAccount"
az batch account create --resource-group $resourceGroup --name $batchAccount --location "$location"

# Authenticate Batch account CLI session.
az batch account login --resource-group $resourceGroup --name $batchAccount --shared-key-auth

# Retrieve a list of available images and node agent SKUs.
az batch pool supported-images list --query "[?contains(imageReference.offer,'ubuntuserver') && imageReference.publisher == 'canonical'].{Offer:imageReference.offer, Publisher:imageReference.publisher, Sku:imageReference.sku, nodeAgentSkuId:nodeAgentSkuId}[-1]" --output tsv

# Create a new Linux pool with a virtual machine configuration. The image reference 
# and node agent SKUs ID can be selected from the ouptputs of the above list command.
# The image reference is in the format: {publisher}:{offer}:{sku}:{version} where {version} is
# optional and defaults to 'latest'."

az batch pool create --id mypool-linux --vm-size Standard_A1 --image canonical:ubuntuserver:18_04-lts-gen2 --node-agent-sku-id "batch.node.ubuntu 18.04"

# Resize the pool to start some VMs.
az batch pool resize --pool-id mypool-linux --target-dedicated 5

# Check the status of the pool to see when it has finished resizing.
az batch pool show --pool-id mypool-linux

# List the compute nodes running in a pool.
az batch node list --pool-id mypool-linux

# returns [] if no compute nodes are running

일괄 처리 노드를 다시 부팅하려면 다음을 수행합니다.

풀의 특정 노드에 문제가 있는 경우 다시 부팅하거나 이미지로 다시 설치할 수 있습니다. 노드의 ID는 위의 list 명령을 사용하여 검색할 수 있습니다. 일반적인 노드 ID는 tvm-xxxxxxxxxx_1-<timestamp> 형식입니다.

az batch node reboot \
    --pool-id mypool-linux \
    --node-id tvm-123_1-20170316t000000z

일괄 처리 노드를 삭제하려면 다음을 수행합니다.

하나 이상의 컴퓨팅 노드를 풀에서 삭제할 수 있으며 이미 할당된 모든 작업을 다른 노드에 다시 할당할 수 있습니다.

az batch node delete \
    --pool-id mypool-linux \
    --node-list tvm-123_1-20170316t000000z tvm-123_2-20170316t000000z \
    --node-deallocation-option requeue

리소스 정리

다음 명령을 사용하여 이러한 리소스가 계속해서 필요한 경우가 아니면 az group delete 명령을 사용하여 리소스 그룹 및 연결된 모든 리소스를 제거합니다. 이러한 리소스 중 일부는 만들고 삭제하는 데 시간이 걸릴 수 있습니다.

az group delete --name $resourceGroup

샘플 참조

이 스크립트는 다음 명령을 사용합니다. 표에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

명령 주의
az group create 모든 리소스가 저장되는 리소스 그룹을 만듭니다.
az batch account create Batch 계정을 만듭니다.
az batch account login 추가 CLI 상호 작용을 위해 지정된 Batch 계정에 대해 인증합니다.
az batch pool node-agent-skus list 사용 가능한 노드 에이전트 SKU 및 이미지 정보를 나열합니다.
az batch pool create 컴퓨팅 노드 풀을 만듭니다.
az batch pool resize 지정된 풀에서 실행 중인 VM 수를 조정합니다.
az batch pool show 풀의 속성을 표시합니다.
az batch node list 지정된 풀의 컴퓨팅 노드를 모두 나열합니다.
az batch node reboot 지정된 컴퓨팅 노드를 다시 부팅합니다.
az batch node delete 지정된 풀에서 나열된 노드를 삭제합니다.
az group delete 모든 중첩 리소스를 포함한 리소스 그룹을 삭제합니다.

다음 단계

Azure CLI에 대한 자세한 내용은 Azure CLI 설명서를 참조하세요.