Azure PowerShell を使用して Azure HDInsight の Apache Hadoop クラスターを管理する
Azure PowerShell を使用して、Azure のワークロードのデプロイと管理を制御し自動化することができます。 この記事では、Az PowerShell モジュールを使用して Azure HDInsight の Apache Hadoop クラスターを管理する方法について説明します。 HDInsight PowerShell コマンドレットの一覧については、Az.HDInsight リファレンスを参照してください。
Azure サブスクリプションをお持ちでない場合は、開始する前に 無料アカウント を作成してください。
前提条件
Note
Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を始めるには、「Azure PowerShell をインストールする」を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。
Az PowerShell モジュールがインストールされていること。
クラスターの作成
クラスターを作成するには、「Azure PowerShell を使用した HDInsight の Linux ベースのクラスターの作成」を参照してください。
クラスターを一覧表示する
現在のサブスクリプションにあるクラスターすべてを一覧表示するには、次のコマンドを使用します。
Get-AzHDInsightCluster
クラスターの表示
現在のサブスクリプションにある特定のクラスターの詳細を表示するには、次のコマンドを使用します。
Get-AzHDInsightCluster -ClusterName <Cluster Name>
クラスターの削除
クラスターを削除するには、次のコマンドを使用します。
Remove-AzHDInsightCluster -ClusterName <Cluster Name>
クラスターが含まれるリソース グループを削除して、クラスターを削除することもできます。 リソース グループを削除すると、既定のストレージ アカウントを含め、グループ内のすべてのリソースが削除されます。
Remove-AzResourceGroup -Name <Resource Group Name>
クラスターのスケール
クラスターのスケーリング機能を使うと、HDInsight 内で実行されているクラスターによって使用されるワーカー ノードの数を、クラスターを再作成することなく変更できます。 PowerShell を使用して Hadoop クラスターのサイズを変更するには、クライアント マシンから次のコマンドを実行します。
Set-AzHDInsightClusterSize -ClusterName <Cluster Name> -TargetInstanceCount <NewSize>
クラスターのスケーリングの詳細については、HDInsight クラスターのスケーリングに関するページを参照してください。
HTTP ユーザーの資格情報の更新
Set-AzHDInsightGatewayCredential パラメーターは、HDInsight クラスターのゲートウェイの HTTP 資格情報を設定します。
$clusterName = "CLUSTERNAME"
$credential = Get-Credential -Message "Enter the HTTP username and password:" -UserName "admin"
Set-AzHDInsightGatewayCredential -ClusterName $clusterName -HttpCredential $credential
既定のストレージ アカウントの検索
次の PowerShell スクリプトでは、既定のストレージ アカウント名と関連情報を取得する方法を示します。
#Connect-AzAccount
$clusterName = "<HDInsight Cluster Name>"
$clusterInfo = Get-AzHDInsightCluster -ClusterName $clusterName
$storageInfo = $clusterInfo.DefaultStorageAccount.split('.')
$defaultStorageType = $storageInfo[1]
$defaultStorageName = $storageInfo[0]
echo "Default Storage account name: $defaultStorageName"
echo "Default Storage account type: $defaultStorageType"
if ($defaultStorageType -eq "blob")
{
$defaultBlobContainerName = $cluster.DefaultStorageContainer
$defaultStorageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $defaultStorageAccountName)[0].Value
$defaultStorageAccountContext = New-AzStorageContext -StorageAccountName $defaultStorageAccountName -StorageAccountKey $defaultStorageAccountKey
echo "Default Blob container name: $defaultBlobContainerName"
echo "Default Storage account key: $defaultStorageAccountKey"
}
リソース グループの検索
Azire Resource Manager モードでは、各 HDInsight クラスターは Azure リソース グループに属しています。 リソース グループを検索するには、次のコマンドを使用します。
$clusterName = "<HDInsight Cluster Name>"
$cluster = Get-AzHDInsightCluster -ClusterName $clusterName
$resourceGroupName = $cluster.ResourceGroup
ジョブの送信
次の製品を使用してジョブを送信するには、リファレンスの指示に従ってください。
- MapReduce: HDInsight に含まれる MapReduce サンプルを実行する
- Apache Hive: PowerShell を使用して Apache Hive クエリを実行する
- Apache Sqoop: HDInsight で Apache Sqoop を使用する
- Apache Oozie: HDInsight での Azure Oozie と Apache Hadoop を使用したワークフローの定義と実行
Azure Blob Storage にデータをアップロードする
Azure Blob Storage にデータをアップロードするには、「HDInsight にデータをアップロードする」を参照してください。