티스토리 뷰

 

HDInsight Hadoop – Word Count(2)

 

앞에서 Hadoop Command 창에서 Word Count를 실행해보았습니다. 사실 Hadoop에 연결해야 하는 번거로움이 있기는 합니다. Microsoft AzurePowerShell을 통해 원격에서도 Word Count 등의 MapReduce 작업을 실행할 수 있습니다. Azure PowerShellhttp://azure.microsoft.com/ko-kr/ 의 다운로드 링크를 통해 설치할 수 있습니다.

아래는 PowerShell ISE를 통해 진행합니다.

 

l  Word Count

# 변수 선언

$subscriptionName =Azure subscription name"

$clusterName = "HDInsight cluster name"

 

# Azure 로그온, 구독 선택

Import-AzurePublishSettingsFile "G:\HDInsight\Azure.publishsettings"

Select-AzureSubscription $subscriptionName

 

 

# MapReduce 작업 (한줄로 실행)

$wordCountJobDefinition = New-AzureHDInsightMapReduceJobDefinition

-JarFile "wasb:///example/jars/hadoop-mapreduce-examples.jar"

-ClassName "wordcount"

-Arguments "wasb:///example/data/gutenberg/davinci.txt", "wasb:///example/data/WordCountOutput"

 

# 작업 제출 (한줄로 실행)

$wordCountJob = Start-AzureHDInsightJob -Cluster $clusterName

-JobDefinition $wordCountJobDefinition | Wait-AzureHDInsightJob -WaitTimeoutInSeconds 3600 

 

 

# 작업 결과 확인

Get-AzureHDInsightJobOutput -Cluster $clusterName -JobId $wordCountJob.JobId -StandardError

 

Word CountPowerShell hadoop-mapreduce-examples.jar 파일을 통해 davinci.txt 파일을 처리한 결과입니다. MapReduce 작업 결과를 확인할 수 있습니다.

 

 

 

실제 출력 파일이 생성된 것을 관리 포털의 저장소, 컨테이너에서 확인 가능합니다.

 

 

l 출력 결과 문자열 확인

 

출력 결과 파일을 다운로드하여 cat 명령으로 특정 문자를 검색할 수 있습니다. 저장소에 있는 출력 파일을 다운로드하여 결과를 화면에 표시해줍니다.

 

# 변수 선언

$subscriptionName =Azure subscription name"

$clusterName = "HDInsight cluster name"

$storageAccountName = "Azure storage account name"

$containerName = "Blob storage container name

 

# 저장소 계정 정보

$storageAccountKey = Get-AzureStorageKey $storageAccountName | %{ $_.Primary }

$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey 

 

# 작업 결과 다운로드 (한줄로 실행)

Get-AzureStorageBlobContent -Container $ContainerName

-Blob example/data/WordCountOutput/part-r-00000 -Context $storageContext -Force

 

cat ./example/data/WordCountOutput/part-r-00000 | findstr "there"

 

아래는 위 PowerShell의 결과입니다.

 hadoop-mapreduce-examples.jar MapReduce 함수는 아래 링크를 참고할 수 있습니다.

https://azure.microsoft.com/ko-kr/documentation/articles/hdinsight-develop-deploy-java-mapreduce/

매번 작업에 jar 파일을 생성하기에는 제한적이며 보다 더 쉽게 구성할 수 있도록 Hive, Pig 등을 제공하고 있습니다. 다음 글에서는 Hive를 통해 MapReduce 작업을 살펴 보겠습니다.

 

 

댓글