Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
使用 Azure 自动化可创建在云中运行的脚本,并按需或按计划管理 Azure 资源。 本文介绍如何通过创建 PowerShell runbook 来创建和删除 Azure HDInsight 群集。
本教程中,您将学习如何:
- 安装与 HDInsight 交互所需的模块。
- 创建并存储群集创建期间所需的凭据。
- 创建新的自动化 Runbook 以创建 HDInsight 群集。
如果没有 Azure 订阅,请在开始前创建一个试用版订阅。
先决条件
- 现有的自动化帐户。
- 现有的 Azure 存储帐户,它可能会用作群集存储。
安装 HDInsight 模块
登录到 Azure 门户。
选择自动化帐户。
在“共享资源”下,选择“模块库”。
在框中输入 AzureRM.Profile,然后选择 Enter 进行搜索。 选择可用的搜索结果。
在 AzureRM.profile 屏幕上,选择“导入”。 选择“更新 Azure 模块”对应的框,然后选择“确定”。
返回到模块库。 在“共享资源”下,选择“模块库”。
输入 HDInsight,然后选择“AzureRM.HDInsight”。
在 AzureRM.HDInsight 面板上,选择“导入”“确定”。>
创建凭据
在“共享资源”下,选择“凭据”。
选择“添加凭据”。
在“新凭据”面板上输入所需的信息。 此凭据用于存储群集密码。 使用它登录 Ambari。
资产 价值 Name cluster-password用户名 admin密码 SECURE_PASSWORD确认密码 SECURE_PASSWORD选择 创建。
使用用户名 sshuser 和所选密码对新的凭据 ssh 密码 重复相同的过程。 选择 创建。 此凭据用于存储群集的安全外壳协议密码。
创建 runbook 以创建群集
在“过程自动化”下,选择“Runbook”。
选择“创建 Runbook”。
在“创建 Runbook”窗格中,输入 Runbook 的名称,例如 hdinsight-cluster-create。 在“Runbook 类型”下拉列表中,选择 PowerShell。
选择 创建。
在“编辑 PowerShell Runbook”屏幕上输入以下代码,然后选择“发布”。
Param ( [Parameter (Mandatory= $true)] [String] $subscriptionID, [Parameter (Mandatory= $true)] [String] $resourceGroup, [Parameter (Mandatory= $true)] [String] $storageAccount, [Parameter (Mandatory= $true)] [String] $containerName, [Parameter (Mandatory= $true)] [String] $clusterName ) ### Authenticate to Azure $Conn = Get-AutomationConnection -Name 'AzureRunAsConnection' Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint # Set cluster variables $storageAccountKey = (Get-AzureRmStorageAccountKey -Name $storageAccount -ResourceGroupName $resourceGroup)[0].value # Setting cluster credentials #Automation credential for Cluster Admin $clusterCreds = Get-AutomationPSCredential -Name 'cluster-password' #Automation credential for user to SSH into cluster $sshCreds = Get-AutomationPSCredential -Name 'ssh-password' $clusterType = "Hadoop" #Use any supported cluster type (Hadoop, HBase, etc.) $clusterOS = "Linux" $clusterWorkerNodes = 3 $clusterNodeSize = "Standard_D3_v2" $location = Get-AzureRmStorageAccount -StorageAccountName $storageAccount -ResourceGroupName $resourceGroup | %{$_.Location} ### Provision HDInsight cluster New-AzureRmHDInsightCluster -ClusterName $clusterName -ResourceGroupName $resourceGroup -Location $location -DefaultStorageAccountName "$storageAccount.blob.core.chinacloudapi.cn" -DefaultStorageAccountKey $storageAccountKey -DefaultStorageContainer $containerName -ClusterType $clusterType -OSType $clusterOS -Version "3.6" -HttpCredential $clusterCreds -SshCredential $sshCreds -ClusterSizeInNodes $clusterWorkerNodes -HeadNodeSize $clusterNodeSize -WorkerNodeSize $clusterNodeSize
创建 Runbook 以删除群集
在“过程自动化”下,选择“Runbook”。
选择“创建 Runbook”。
在“创建 Runbook”窗格中,输入 Runbook 的名称,例如 hdinsight-cluster-delete。 在“Runbook 类型”下拉列表中,选择 PowerShell。
选择 创建。
在“编辑 PowerShell Runbook”屏幕上输入以下代码,然后选择“发布”。
Param ( [Parameter (Mandatory= $true)] [String] $clusterName ) ### Authenticate to Azure $Conn = Get-AutomationConnection -Name 'AzureRunAsConnection' Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint Remove-AzureRmHDInsightCluster -ClusterName $clusterName
运行 Runbook
本部分介绍如何运行 Runbook。
创建群集
查看自动化帐户的 Runbook 列表。 在“过程自动化”下,选择“Runbook”。
选择 hdinsight-cluster-create 或创建群集创建 Runbook 时使用的名称。
选择“开始”以立即运行 Runbook。 你还可以安排 Runbook 定期运行。 有关详细信息,请参阅在自动化中计划 Runbook。
输入脚本所需的参数,然后选择“确定”。 此步骤会创建一个新的 HDInsight 群集,该群集具有你在 CLUSTERNAME 参数中指定的名称。
删除群集
通过选择创建的 hdinsight-cluster-delete Runbook 来删除群集。 选择“开始”,输入 CLUSTERNAME 参数,然后选择“确定”。
清理资源
如果资源不再被需要,请删除所创建的自动化帐户以避免意外的费用。 转到 Azure 门户,选择创建了自动化帐户的资源组,选择自动化帐户,然后选择“删除”。