溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

hadoop分布式集群部署以及過程中遇到的一些坑

發(fā)布時間:2020-07-18 09:21:08 來源:網(wǎng)絡(luò) 閱讀:694 作者:zfno11 欄目:大數(shù)據(jù)

在hadoop學(xué)習(xí)過程中,首先第一步是部署偽分布以及分布式集群。
在集群的部署過程中http://www.powerxing.com/install-hadoop-cluster/
使用這篇博客作為參考。

在部署過程中。 遇到一些問題。
比如:用PYTHON 跑一個簡單的MAPREDUCE 任務(wù),首先需要現(xiàn)在streamingJAR包,簡單的說這個包封裝了一些常用的接口,PYTHON 通過標(biāo)準輸入輸出來調(diào)用這個包。最終完成在內(nèi)部用JAVA實現(xiàn)的功能。
下載地址為:http://www.java2s.com/Code/JarDownload/hadoop-streaming/

python 程序為 mapper.py

#!/usr/bin/env python
import sys
for line in sys.stdin:
line = line.strip()
words = line.split()
for word in words:
print "%s\t%s" % (word, 1)

以及reducer.py

**#!/usr/bin/env python
from operator import itemgetter
import sys

current_word = None
current_count = 0
word = None

for line in sys.stdin:
line = line.strip()
word, count = line.split('\t', 1)
try:
count = int(count)
except ValueError: #count如果不是數(shù)字的話,直接忽略掉
continue
if current_word == word:
current_count += count
else:
if current_word:
print "%s\t%s" % (current_word, current_count)
current_count = count
current_word = word

if word == current_word: #不要忘記最后的輸出
print "%s\t%s" % (current_word, current_count)**

    運行方式:
hadoop jar ./hadoop-streaming-2.6.0.jar -file ./mappper.py -file ./reducer.py  -input /input -output /output

這里需要注意的是  /input 必須放在hadoop文件系統(tǒng)上
hadoop fs -put input /input 
/output 不能存在,如果存在請先刪除

另外在python中首行必須寫   #!/usr/bin/env python
否則可能會報錯。具體原因可以看http://andylue2008.iteye.com/blog/1622260  這篇博客

另外如果使用hadoop fs -ls 這樣的命令報錯: 找不到ls目錄。是因為沒有創(chuàng)建家目錄
hadoop fs -mkdir -p /user/hadoop
向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI