2010-12-16 69 views
18

this guide開始,我已成功運行示例練習。但在運行我的MapReduce工作,我從日誌文件Python中的Hadoop Streaming Job失敗錯誤

java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 2 
at org.apache.hadoop.streaming.PipeMapRed.waitOutputThreads(PipeMapRed.java:311) 
at org.apache.hadoop.streaming.PipeMapRed.mapRedFinished(PipeMapRed.java:545) 
at org.apache.hadoop.streaming.PipeMapper.close(PipeMapper.java:132) 
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:57) 
at org.apache.hadoop.streaming.PipeMapRunner.run(PipeMapRunner.java:36) 
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:358) 
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:307) 
at org.apache.hadoop.mapred.Child.main(Child.java:170) 

Mapper.py

import sys 

i=0 

for line in sys.stdin: 
    i+=1 
    count={} 
    for word in line.strip().split(): 
     count[word]=count.get(word,0)+1 
    for word,weight in count.items(): 
     print '%s\t%s:%s' % (word,str(i),str(weight)) 

Reducer.py

import sys 

keymap={} 
o_tweet="2323" 
id_list=[] 
for line in sys.stdin: 
    tweet,tw=line.strip().split() 
    #print tweet,o_tweet,tweet_id,id_list 
    tweet_id,w=tw.split(':') 
    w=int(w) 
    if tweet.__eq__(o_tweet): 
     for i,wt in id_list: 
      print '%s:%s\t%s' % (tweet_id,i,str(w+wt)) 
     id_list.append((tweet_id,w)) 
    else: 
     id_list=[(tweet_id,w)] 
     o_tweet=tweet 

收到以下錯誤
ERROR streaming.StreamJob: Job not Successful!
10/12/16 17:13:38 INFO streaming.StreamJob: killJob...
Streaming Job Failed!

錯誤命令來運行作業:

[email protected]:/usr/local/hadoop$ bin/hadoop jar contrib/streaming/hadoop-0.20.0-streaming.jar -file /home/hadoop/mapper.py -mapper /home/hadoop/mapper.py -file /home/hadoop/reducer.py -reducer /home/hadoop/reducer.py -input my-input/* -output my-output 

輸入是句子的任意隨機序列。

謝謝,

回答

19

您的-mapper和-reducer應該只是腳本名稱。

[email protected]:/usr/local/hadoop$ bin/hadoop jar contrib/streaming/hadoop-0.20.0-streaming.jar -file /home/hadoop/mapper.py -mapper mapper.py -file /home/hadoop/reducer.py -reducer reducer.py -input my-input/* -output my-output 

當你的腳本是在是在另一個文件夾內HDFS的工作,這是相對於作爲執行任務的嘗試「」 (僅供參考,如果您想要另外添加一個文件,例如查找表,您可以在Python中打開它,就好像它與您的腳本位於相同的目錄中,而腳本處於M/R作業中)

也可以確保您有存取權限chmod a + X mapper.py和chmod一+ X reducer.py

+0

感謝您的答覆,但我仍然收到相同的錯誤。 – db42 2010-12-17 05:08:05

+8

嘗試將#!/ usr/bin/env python添加到您的python腳本的頂部,它應該能夠通過執行cat data.file | ./mapper.py | sort | ./reducer從命令行執行。 py,並且它不會在文件 – 2010-12-17 07:26:03

+0

頂部的「#!/ usr/bin/env python」感謝Joe,那就是訣竅。 – db42 2010-12-17 10:54:34

12

嘗試添加腳本的

#!/usr/bin/env python 

頂部。

或者,

-mapper 'python m.py' -reducer 'r.py' 
+0

太棒了!它在向頭添加「#!/ usr/bin/env python」時解決了我的問題。 – 2016-07-24 20:55:59

+0

該死的,通過vim複製粘貼代碼刪除了'#!',併爲我造成了這個問題。感謝提醒添加標題! – asgs 2017-06-05 19:31:45

2

我遇到了這個錯誤最近,我的問題竟然是因爲這些其他解決方案那樣明顯的東西(事後):

我只是有一個錯誤在我的Python代碼。 (就我而言,我使用的是Python v2.7字符串格式,而我使用的AWS EMR集羣是使用Python v2.6)。

要找到實際的Python錯誤,請轉到Job Tracker Web UI(對於AWS EMR,端口9100用於AMI 2.x,端口9026用於AMI 3.x);找到失敗的映射器;打開它的日誌;並讀取stderr輸出。

0

確保您的輸入目錄只包含正確的文件

+0

我有這個問題..我沒有任何問題在hadoop外運行...但我在這裏嘗試的建議,並沒有看到任何日誌..任何其他方式來調試此問題 – 2017-02-07 07:43:15