转载别人的Hadoop pipes初学笔记,好好学习下!

1.安装配置好hadoop
常用命令:
hadoop dfs -ls path
hadoop dfs -rmr file
hadoop dfs -mkdir path
hadoop dfs -cat file
2.找个wordcount程序,命名为wordcount.cpp
可以是:http://wiki.apache.org/hadoop/C++WordCount
也可以是hadoop安装路径下的:/usr/local/hadoop-0.20.2/src/examples/pipes/impl/wordcount-simple.cc
3.写Makefile
HADOOP_INSTALL=/usr/local/hadoop-0.20.2
PLATFORM=Linux-i386-32

CC = g++
CPPFLAGS = -m32 -I$(HADOOP_INSTALL)/c++/$(PLATFORM)/include

wordcount: wordcount.cpp
$(CC) $(CPPFLAGS) $< -Wall -L$(HADOOP_INSTALL)/c++/$(PLATFORM)/lib -lhadooppipes -lhadooputils -lpthread -g -O2 -o $@
###
cat /proc/cpuinfo 查看cpu是intel的还是amd的,对应修改PLATFORM。
4.执行:
上传wordcount.cpp文件作为输入文件:hadoop fs -put wordcount.cpp input.txt
上传可执行文件: hadoop fs -put wordcount bin/wordcount
运行代码:
hadoop pipes \
-D hadoop.pipes.java.recordreader=true \
-D hadoop.pipes.java.recordwriter=true \
-input input.txt \
-output output \
-program bin/wordcount
查看结果:
hadoop dfs -cat output/*

参考:
http://hadoop.apache.org/common/docs/current/api/org/apache/hadoop/mapred/pipes/package-summary.html
《Hadoop:The Definitive Guide》P.36
posted @ 2010-09-06 16:03  衣不解带  阅读(790)  评论(0编辑  收藏  举报