Hadoop Pipes编程之C++实现WordCount

Hadoop尽管用java实现,可是相同能够支持其它语言的Map和Reduce。因为须要学习C++方面的Hadoop实现,所以近期一直在研究Hadoop Streaming编程,当中Hadoop pipes同意C++程序猿编写mapreduce程序,它同意用户混用C++和Java的RecordReader, Mapper, Partitioner,Rducer和RecordWriter等五个组件。以下是我的搭建以及遇到的问题。

一般这样的搭建的流程都是从官网看比較好。參考http://wiki.apache.org/hadoop/C++WordCount,里面的流程简单易懂。进入hadoop的安装文件夹。运行:

ant -Dcompile.c++=yes examples

依据错误提示,安装ant:

 sudo apt-get install ant

以下是源源不断的错误以及源源不断的解决的方法。。。

Error1:/build.xml:634: Execute failed: java.io.IOException: Cannot run program "autoreconf" (in directory "/home/hadoop/hadoop-1.2.1/src/native"): error=2, No such file or directory

Solution1:依据报错是因为没有安装automake工具。所以运行:

 sudo apt-get install automake

Error2:build.xml:634: exec returned: 1

Solution2http://stackoverflow.com/questions/23112074/building-hadoop-1-2-1-core-jar-using-ant-failed,运行:

sudo apt-get install libtool

Error3:build.xml:2164: exec returned: 255

Solution3forum.hadoop.tw/viewtopic.php?f=7&t=37970。參考里面的实现步骤。

1)安装g++

sudo apt-get install g++

2)编译wordcount.cpp

g++ -I/home/hadoop/hadoop-1.2.1/c++/Linux-i386-32/include -c wordcount.cpp

3)生成可运行文件

g++ wordcount.o -o wordcount -L/home/hadoop/hadoop-1.2.1/c++/Linux-i386-32/lib -lnsl -lpthread -lhadooppipes –lhadooputils

Error4:In function `HadoopPipes::BinaryProtocol::createDigest(std::string&, std::string&)':

Solution4http://blog.sina.com.cn/s/blog_605f5b4f010195w6.html

Step1:

sudo apt-get install libssl-dev

Step2:

g++ wordcount.o -o wordcount -L/home/hadoop/hadoop-1.2.1/c++/Linux-i386-32/lib -lnsl -lpthread -lhadooppipes -lhadooputils –lcrypto

经历了上面的重重问题。如今最终生成了可运行程序WordCount了,然后须要上传到HDFS。利用可运行文件运行。以下是命令:


hadoop fs -mkdir wordcount/bin
 hadoop fs -mkdir wordcount/input
 hadoop fs -put wordcount.cpp /user/hadoop/wordcount/input/
 hadoop fs -put wordcount /user/hadoop/wordcount/bin/
 hadoop pipes -D hadoop.pipes.java.recordreader=true -D hadoop.pipes.java.recordwriter=true -program /user/hadoop/wordcount/bin/wordcount -input /user/hadoop/wordcount/input/ -output /user/hadoop/wordcount/output

当中我以wordcount.cpp为输入文件,将可运行文件上传到bin文件夹,输出文件夹是output。

运行的过程中又遇到问题:

Error5:java.io.IOException

at org.apache.hadoop.mapred.pipes.OutputHandler.waitForAuthentication(OutputHandler.java:188)

Solution5http://blog.csdn.net/sigxxl/article/details/12293435,最终找到同仁了。。

。基本的解决方法就是又一次编译生成libhadooppipes.a和libhadooputils.a这两个静态库,然后覆盖原先的静态库。

1)  进入hadoop/src/c++/pipes文件夹。运行./ configure。

Error6:./configure: line 413: test: please: integer expression expected

./configure: line 416: $4: Bad file descriptor

configure: error: check

./configure: line 302: return: please: numeric argument required

./configure: line 312: exit: please: numeric argument required

Solution6:找到configure文件的这一行,一般报错会指定这一行的,将as_fn_exit凝视掉,例如以下:


solution:as_fn_error ()
 { as_status=$1; test $as_status -eq && as_status=1
 if test "$4"; then
 as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
 $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
 fi $as_echo "$as_me: error: $2" >&2
 #as_fn_exit $as_status } as_fn_error

2)   ./configure

make install(遇到相同的报错再次改动configure文件如上)

3)  进入hadoop/src/c++/utils。运行相同的步骤

./configure

make install

生成好新的libhadooppipes.a和libhadooputils.a这两个静态库和相关的头文件之后,将这些文件覆盖到~/hadoop/c++/Linux-i386-32/ 文件夹中的include文件夹和lib文件夹中去。重新启动hadoop,然后又一次执行C++程序。

再次执行,OK。

转载请注明出处:http://www.ming-yue.cn/hadoop-pipes-wordcount/

posted @ 2017-06-18 15:34  jzdwajue  阅读(329)  评论(0编辑  收藏  举报