Azure Resource Manager 템플릿 및 Azure REST API를 사용하여 HDInsight 클러스터를 만드는 방법을 알아봅니다.
Azure REST API를 사용하면 HDInsight 클러스터와 같은 새 리소스를 만드는 것을 포함하여 Azure 플랫폼에서 호스트되는 서비스에 대한 관리 작업을 수행할 수 있습니다.
비고
이 문서의 단계에서는 curl(유틸리티를https://curl.haxx.se/) 사용하여 Azure REST API와 통신합니다.
템플릿 만들기
Azure Resource Manager 템플릿은 리소스 그룹 및 리소스 그룹의 모든 리소스(예: HDInsight)를 설명하는 JSON 문서입니다. 이 템플릿 기반 접근 방식을 사용하면 하나의 템플릿에서 HDInsight에 필요한 리소스를 정의할 수 있습니다.
다음 JSON 문서는 SSH 사용자 계정을 보호하기 위해 암호를 사용하여 Linux 기반 클러스터를 만드는 템플릿 및 매개 변수 파일 https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.hdinsight/hdinsight-linux-ssh-password/azuredeploy.json의 병합입니다.
{
"properties": {
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterType": {
"type": "string",
"allowedValues": ["hadoop",
"hbase",
"spark"],
"metadata": {
"description": "The type of the HDInsight cluster to create."
}
},
"clusterName": {
"type": "string",
"metadata": {
"description": "The name of the HDInsight cluster to create."
}
},
"clusterLoginUserName": {
"type": "string",
"metadata": {
"description": "These credentials can be used to submit jobs to the cluster and to log into cluster dashboards."
}
},
"clusterLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The password must be at least 10 characters in length and must contain at least one digit, one non-alphanumeric character, and one upper or lower case letter."
}
},
"sshUserName": {
"type": "string",
"metadata": {
"description": "These credentials can be used to remotely access the cluster."
}
},
"sshPassword": {
"type": "securestring",
"metadata": {
"description": "The password must be at least 10 characters in length and must contain at least one digit, one non-alphanumeric character, and one upper or lower case letter."
}
},
"clusterStorageAccountName": {
"type": "string",
"metadata": {
"description": "The name of the storage account to be created and be used as the cluster's storage."
}
},
"clusterWorkerNodeCount": {
"type": "int",
"defaultValue": 4,
"metadata": {
"description": "The number of nodes in the HDInsight cluster."
}
}
},
"variables": {
"defaultApiVersion": "2015-05-01-preview",
"clusterApiVersion": "2015-03-01-preview"
},
"resources": [{
"name": "[parameters('clusterStorageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"location": "[resourceGroup().location]",
"apiVersion": "[variables('defaultApiVersion')]",
"dependsOn": [],
"tags": {
},
"properties": {
"accountType": "Standard_LRS"
}
},
{
"name": "[parameters('clusterName')]",
"type": "Microsoft.HDInsight/clusters",
"location": "[resourceGroup().location]",
"apiVersion": "[variables('clusterApiVersion')]",
"dependsOn": ["[concat('Microsoft.Storage/storageAccounts/',parameters('clusterStorageAccountName'))]"],
"tags": {
},
"properties": {
"clusterVersion": "3.6",
"osType": "Linux",
"clusterDefinition": {
"kind": "[parameters('clusterType')]",
"configurations": {
"gateway": {
"restAuthCredential.isEnabled": true,
"restAuthCredential.username": "[parameters('clusterLoginUserName')]",
"restAuthCredential.password": "[parameters('clusterLoginPassword')]"
}
}
},
"storageProfile": {
"storageaccounts": [{
"name": "[concat(parameters('clusterStorageAccountName'),'.blob.core.windows.net')]",
"isDefault": true,
"container": "[parameters('clusterName')]",
"key": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('clusterStorageAccountName')), variables('defaultApiVersion')).key1]"
}]
},
"computeProfile": {
"roles": [{
"name": "headnode",
"targetInstanceCount": "2",
"hardwareProfile": {
"vmSize": "{}"
},
"osProfile": {
"linuxOperatingSystemProfile": {
"username": "[parameters('sshUserName')]",
"password": "[parameters('sshPassword')]"
}
}
},
{
"name": "workernode",
"targetInstanceCount": "[parameters('clusterWorkerNodeCount')]",
"hardwareProfile": {
"vmSize": "{}"
},
"osProfile": {
"linuxOperatingSystemProfile": {
"username": "[parameters('sshUserName')]",
"password": "[parameters('sshPassword')]"
}
}
}]
}
}
}],
"outputs": {
"cluster": {
"type": "object",
"value": "[reference(resourceId('Microsoft.HDInsight/clusters',parameters('clusterName')))]"
}
}
},
"mode": "incremental",
"Parameters": {
"clusterName": {
"value": "newclustername"
},
"clusterType": {
"value": "hadoop"
},
"clusterStorageAccountName": {
"value": "newstoragename"
},
"clusterLoginUserName": {
"value": "admin"
},
"clusterLoginPassword": {
"value": "changeme"
},
"sshUserName": {
"value": "sshuser"
},
"sshPassword": {
"value": "changeme"
}
}
}
}
이 예제는 이 문서의 단계에서 사용됩니다. 매개 변수 섹션의 예제 값을 클러스터의 값으로 바꿉다.
중요합니다
템플릿은 HDInsight 클러스터에 대해 기본 작업자 노드 수(4)를 사용합니다. 32개 이상의 작업자 노드를 계획하는 경우 8개 이상의 코어와 14GB RAM이 있는 헤드 노드 크기를 선택해야 합니다.
노드 크기 및 관련된 비용에 대한 자세한 내용은 HDInsight 가격 책정을 참조하세요.
Azure 구독에 로그인
Azure CLI 시작에 설명된 단계를 따라 az login
명령어를 사용하여 구독에 연결합니다.
서비스 주체 만들기
비고
이러한 단계는 Azure CLI를 사용하여 리소스에 액세스하기 위한 서비스 주체 만들기 문서의 암호를 사용한 서비스 주체 만들기 섹션의 요약 버전입니다. 이러한 단계는 Azure REST API에 인증하는 데 사용되는 서비스 주체를 만듭니다.
명령줄에서 다음 명령을 사용하여 Azure 구독을 나열합니다.
az account list --query '[].{Subscription_ID:id,Tenant_ID:tenantId,Name:name}' --output table
목록에서 사용하려는 구독을 선택하고 Subscription_ID 및 Tenant_ID 열을 기록해 둡니다. 이러한 값을 저장합니다.
다음 명령을 사용하여 Microsoft Entra ID로 애플리케이션을 만듭니다.
az ad app create --display-name "exampleapp" --homepage "https://www.contoso.org" --identifier-uris "https://www.contoso.org/example" --password <Your password> --query 'appId'
에 대한 값을 사용자 고유의
--display-name
--homepage
--identifier-uris
값으로 바꿉습니다. 새 Active Directory 항목에 대한 암호를 제공합니다.비고
--home-page
값과--identifier-uris
값은 인터넷에서 호스트되는 실제 웹 페이지를 참조할 필요가 없습니다. 고유한 URI여야 합니다.이 명령에서 반환되는 값은 새 애플리케이션의 앱 ID 입니다. 이 값을 저장합니다.
다음 명령을 사용하여 앱 ID를 사용하여 서비스 주체를 만듭니다.
az ad sp create --id <App ID> --query 'objectId'
이 명령에서 반환되는 값은 개체 ID입니다. 이 값을 저장합니다.
개체 ID 값을 사용하여 서비스 주체에 소유자 역할을 할당합니다. 이전에 얻은 구독 ID 를 사용합니다.
az role assignment create --assignee <Object ID> --role Owner --scope /subscriptions/<Subscription ID>/
인증 토큰 가져오기
다음 명령을 사용하여 인증 토큰을 검색합니다.
curl -X "POST" "https://login.microsoftonline.com/$TENANTID/oauth2/token" \
-H "Cookie: flight-uxoptin=true; stsservicecookie=ests; x-ms-gateway-slice=productionb; stsservicecookie=ests" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=$APPID" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_secret=$PASSWORD" \
--data-urlencode "resource=https://management.azure.com/"
이전에 가져오거나 사용한 값으로 $TENANTID
, $APPID
, 및 $PASSWORD
을 설정합니다.
이 요청이 성공하면 200 시리즈 응답이 수신되고 응답 본문에 JSON 문서가 포함됩니다.
이 요청에서 반환된 JSON 문서에는 access_token라는 요소가 포함되어 있습니다. access_token 값은 REST API에 대한 인증 요청에 사용됩니다.
{
"token_type":"Bearer",
"expires_in":"3599",
"expires_on":"1463409994",
"not_before":"1463406094",
"resource":"https://management.azure.com/","access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWoNBVGZNNXBPWWlKSE1iYTlnb0VLWSIsImtpZCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuYXp1cmUuY29tLyIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI2Ny8iLCJpYXQiOjE0NjM0MDYwOTQsIm5iZiI6MTQ2MzQwNjA5NCwiZXhwIjoxNDYzNDA5OTk5LCJhcHBpZCI6IjBlYzcyMzM0LTZkMDMtNDhmYi04OWU1LTU2NTJiODBiZDliYiIsImFwcGlkYWNyIjoiMSIsImlkcCI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0Ny8iLCJvaWQiOiJlNjgxZTZiMi1mZThkLTRkZGUtYjZiMS0xNjAyZDQyNWQzOWYiLCJzdWIiOiJlNjgxZTZiMi1mZThkLTRkZGUtYjZiMS0xNjAyZDQyNWQzOWYiLCJ0aWQiOiI3MmY5ODhiZi04NmYxLTQxYWYtOTFhYi0yZDdjZDAxMWRiNDciLCJ2ZXIiOiIxLjAifQ.nJVERbeDHLGHn7ZsbVGBJyHOu2PYhG5dji6F63gu8XN2Cvol3J1HO1uB4H3nCSt9DTu_jMHqAur_NNyobgNM21GojbEZAvd0I9NY0UDumBEvDZfMKneqp7a_cgAU7IYRcTPneSxbD6wo-8gIgfN9KDql98b0uEzixIVIWra2Q1bUUYETYqyaJNdS4RUmlJKNNpENllAyHQLv7hXnap1IuzP-f5CNIbbj9UgXxLiOtW5JhUAwWLZ3-WMhNRpUO2SIB7W7tQ0AbjXw3aUYr7el066J51z5tC1AK9UC-mD_fO_HUP6ZmPzu5gLA6DxkIIYP3grPnRVoUDltHQvwgONDOw"
}
리소스 그룹 만들기
리소스 그룹을 만들려면 다음을 사용합니다.
- 서비스 주체를 만들 때 받은 구독 ID를
$SUBSCRIPTIONID
에 설정합니다. - 이전 단계에서 받은 액세스 토큰으로 설정합니다
$ACCESSTOKEN
. - 리소스 그룹과 리소스를 생성하려는 데이터 센터로
DATACENTERLOCATION
을 변경하십시오. 예를 들어 '미국 중남부'입니다. - 이 그룹에 사용할 이름으로
$RESOURCEGROUPNAME
를 설정하세요.
curl -X "PUT" "https://management.azure.com/subscriptions/$SUBSCRIPTIONID/resourcegroups/$RESOURCEGROUPNAME?api-version=2015-01-01" \
-H "Authorization: Bearer $ACCESSTOKEN" \
-H "Content-Type: application/json" \
-d $'{
"location": "DATACENTERLOCATION"
}'
이 요청이 성공하면 200 시리즈 응답을 받게 되며 응답 본문에는 그룹에 대한 정보가 포함된 JSON 문서가 포함됩니다.
"provisioningState"
요소는 "Succeeded"
값을 포함하고 있습니다.
배포 생성하기
다음 명령을 사용하여 리소스 그룹에 템플릿을 배포합니다.
-
$DEPLOYMENTNAME
을(를) 이 배포에 사용할 이름으로 지정하세요.
curl -X "PUT" "https://management.azure.com/subscriptions/$SUBSCRIPTIONID/resourcegroups/$RESOURCEGROUPNAME/providers/microsoft.resources/deployments/$DEPLOYMENTNAME?api-version=2015-01-01" \
-H "Authorization: Bearer $ACCESSTOKEN" \
-H "Content-Type: application/json" \
-d "{set your body string to the template and parameters}"
비고
템플릿을 파일에 저장한 경우 다음 명령 대신 -d "{ template and parameters}"
사용할 수 있습니다.
--data-binary "@/path/to/file.json"
이 요청이 성공하면 200 시리즈 응답을 받게 되며 응답 본문에는 배포 작업에 대한 정보가 포함된 JSON 문서가 포함됩니다.
중요합니다
배포가 제출되었지만 완료되지 않았습니다. 배포가 완료되려면 일반적으로 약 15분 정도 걸릴 수 있습니다.
배포 상태 확인
배포 상태를 확인하려면 다음 명령을 사용합니다.
curl -X "GET" "https://management.azure.com/subscriptions/$SUBSCRIPTIONID/resourcegroups/$RESOURCEGROUPNAME/providers/microsoft.resources/deployments/$DEPLOYMENTNAME?api-version=2015-01-01" \
-H "Authorization: Bearer $ACCESSTOKEN" \
-H "Content-Type: application/json"
이 명령은 배포 작업에 대한 정보가 포함된 JSON 문서를 반환합니다. 요소에는 "provisioningState"
배포 상태가 포함됩니다. 이 요소에 값 "Succeeded"
이 포함된 경우 배포가 성공적으로 완료되었습니다.
문제 해결
HDInsight 클러스터를 만드는 동안 문제가 발생할 경우 액세스 제어 요구 사항을 참조하세요.
다음 단계
이제 HDInsight 클러스터를 성공적으로 만들었으므로 다음을 사용하여 클러스터를 사용하는 방법을 알아봅니다.