.NET SDK를 사용하여 HDInsight에서 Apache Hadoop 클러스터 관리
HDInsight.NET SDK를 사용하여 Azure HDInsight 클러스터를 관리하는 방법을 알아봅니다.
필수 조건
이 문서를 시작하기 전에 다음이 있어야 합니다.
- 활성 구독이 있는 Azure 계정. Azure 구독이 아직 없는 경우 시작하기 전에 체험 계정을 만듭니다.
Azure HDInsight에 연결
다음 NuGet 패키지가 필요합니다.
Install-Package Microsoft.Rest.ClientRuntime.Azure.Authentication -Pre
Install-Package Microsoft.Azure.Management.ResourceManager -Pre
Install-Package Microsoft.Azure.Management.HDInsight
다음 코드 샘플은 Azure 구독에서 HDInsight 클러스터를 관리할 수 있기 전에 Azure에 연결하는 방법을 보여 줍니다.
using System;
using Microsoft.Azure;
using Microsoft.Azure.Management.HDInsight;
using Microsoft.Azure.Management.HDInsight.Models;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
using Microsoft.Rest.Azure.Authentication;
namespace HDInsightManagement
{
class Program
{
private static HDInsightManagementClient _hdiManagementClient;
// Replace with your Azure Active Directory tenant ID if necessary.
private const string TenantId = UserTokenProvider.CommonTenantId;
private const string SubscriptionId = "<Your Azure Subscription ID>";
// This is the GUID for the PowerShell client. Used for interactive logins in this example.
private const string ClientId = "1950a258-227b-4e31-a9cf-717495945fc2";
static void Main(string[] args)
{
// Authenticate and get a token
var authToken = Authenticate(TenantId, ClientId, SubscriptionId);
// Flag subscription for HDInsight, if it isn't already.
EnableHDInsight(authToken);
// Get an HDInsight management client
_hdiManagementClient = new HDInsightManagementClient(authToken);
// insert code here
System.Console.WriteLine("Press ENTER to continue");
System.Console.ReadLine();
}
/// <summary>
/// Authenticate to an Azure subscription and retrieve an authentication token
/// </summary>
static TokenCloudCredentials Authenticate(string TenantId, string ClientId, string SubscriptionId)
{
var authContext = new AuthenticationContext("https://login.microsoftonline.com/" + TenantId);
var tokenAuthResult = authContext.AcquireToken("https://management.core.windows.net/",
ClientId,
new Uri("urn:ietf:wg:oauth:2.0:oob"),
PromptBehavior.Always,
UserIdentifier.AnyUser);
return new TokenCloudCredentials(SubscriptionId, tokenAuthResult.AccessToken);
}
/// <summary>
/// Marks your subscription as one that can use HDInsight, if it has not already been marked as such.
/// </summary>
/// <remarks>This is essentially a one-time action; if you have already done something with HDInsight
/// on your subscription, then this isn't needed at all and will do nothing.</remarks>
/// <param name="authToken">An authentication token for your Azure subscription</param>
static void EnableHDInsight(TokenCloudCredentials authToken)
{
// Create a client for the Resource manager and set the subscription ID
var resourceManagementClient = new ResourceManagementClient(new TokenCredentials(authToken.Token));
resourceManagementClient.SubscriptionId = SubscriptionId;
// Register the HDInsight provider
var rpResult = resourceManagementClient.Providers.Register("Microsoft.HDInsight");
}
}
}
이 프로그램을 실행할 때 프롬프트가 표시됩니다. 프롬프트를 표시하지 않으려면 비터활성 인증 .NET HDInsight 애플리케이션 만들기를 참조 하세요.
클러스터 나열
다음 코드 조각은 클러스터 및 일부 속성을 나열합니다.
var results = _hdiManagementClient.Clusters.List();
foreach (var name in results.Clusters) {
Console.WriteLine("Cluster Name: " + name.Name);
Console.WriteLine("\t Cluster type: " + name.Properties.ClusterDefinition.ClusterType);
Console.WriteLine("\t Cluster location: " + name.Location);
Console.WriteLine("\t Cluster version: " + name.Properties.ClusterVersion);
}
클러스터 삭제
다음 코드 조각을 사용하여 동기적 또는 비동기적으로 클러스터를 삭제합니다.
_hdiManagementClient.Clusters.Delete("<Resource Group Name>", "<Cluster Name>");
_hdiManagementClient.Clusters.DeleteAsync("<Resource Group Name>", "<Cluster Name>");
클러스터 크기 조정
클러스터 크기 조정 기능을 사용하여 클러스터를 다시 만들지 않고도 HDInsight에서 실행되는 클러스터에서 사용하는 작업자 노드 수를 변경합니다.
참고 항목
HDInsight 버전 3.1.3 이상을 사용하는 클러스터만 지원됩니다. 클러스터 버전을 잘 모르는 경우 속성 페이지를 확인합니다. 자세한 내용은 클러스터 나열 및 표시를 참조하세요.
HDInsight에서 지원하는 각 클러스터 유형에 대한 데이터 노드 수를 변경하는 효과:
Apache Hadoop: 보류 중이거나 실행 중인 작업에 영향을 주지 않고 실행 중인 Hadoop 클러스터의 작업자 노드 수를 원활하게 늘릴 수 있습니다. 작업이 진행 중인 동안 새 작업을 제출할 수도 있습니다. 크기 조정 작업의 오류는 정상적으로 처리되므로 클러스터는 항상 기능 상태로 남아 있습니다.
데이터 노드 수를 줄여 Hadoop 클러스터를 축소하면 클러스터의 서비스 중 일부가 다시 시작됩니다. 크기 조정 작업이 완료되면 실행 중인 모든 작업과 보류 중인 작업이 실패합니다. 작업이 완료되면 작업을 다시 제출할 수 있습니다.
Apache HBase: 실행되는 동안 HBase 클러스터에 노드를 원활하게 추가하거나 제거할 수 있습니다. 지역 서버는 크기 조정 작업을 완료한 후 몇 분 이내에 자동으로 분산됩니다. 지역 서버의 부하를 수동으로 분산할 수도 있습니다. 클러스터의 헤드 노드에 로그인하고 명령 프롬프트 창에서 다음 명령을 실행합니다.
>pushd %HBASE_HOME%\bin >hbase shell >balancer
HTTP 사용자 자격 증명 업데이트
업데이트 절차는 HTTP 액세스 권한을 부여하거나 취소하는 데 사용하는 절차와 동일합니다. 클러스터에 HTTP 액세스 권한이 부여된 경우 먼저 취소해야 합니다. 그런 다음 새 HTTP 사용자 자격 증명을 사용하여 액세스 권한을 부여할 수 있습니다.
기본 스토리지 계정 찾기
다음 코드 조각은 클러스터의 기본 스토리지 계정 이름 및 키를 가져오는 방법을 보여 줍니다.
var results = _hdiManagementClient.Clusters.GetClusterConfigurations(<Resource Group Name>, <Cluster Name>, "core-site");
foreach (var key in results.Configuration.Keys)
{
Console.WriteLine(String.Format("{0} => {1}", key, results.Configuration[key]));
}
작업 제출
다음 제품에 대한 작업을 제출하는 방법을 알아봅니다.
- MapReduce: HDInsight에서 MapReduce 샘플 실행
- Apache Hive: .NET SDK를 사용하여 Apache Hive 쿼리 실행
- Apache Sqoop: HDInsight에서 Apache Sqoop 사용
- Apache Oozie: Hadoop과 함께 Apache Oozie를 사용하여 HDInsight에서 워크플로 정의 및 실행
Azure Blob Storage에 데이터 업로드
데이터를 업로드하려면 HDInsight에 데이터 업로드를 참조하세요.