3、运行编译文件
make
4、上传运行程序到hdfs
Hadoop fs -mkdir bin
hadoop fs -put wordcount bin
5、准备测试文件
sudo gedit myfile.txt
文件内容:1 2 3 4 5 6 7 8 9 10 11 12 13。
6、上传测试文件
hadoop fs -mkdir input
hadoop fs -put myfile.txt input
7、编写配置文件
sudo gedit job_config.xml
<?xml version="1.0"?>
<configuration>
<property>
<name>mapred.job.name</name>
<value>WordCount</value>
</property>
<property>
<name>mapred.reduce.tasks</name>
<value>10</value>
</property>
<property>
<name>mapred.task.timeout</name>
<value>180000</value>
</property>
<property>
<name>hadoop.pipes.executable</name>
<value>/user/hadoop/bin/wordcount</value>
<description> Executable path is given as"path#executable-name"
sothat the executable will havea symlink in working directory.
This can be used for gdbdebugging etc.
</description>
</property>
<property>
<name>mapred.create.symlink</name>
<value>yes</value>
</property>
<property>
<name>hadoop.pipes.java.recordreader</name>
<value>true</value>
</property>
<property>
<name>hadoop.pipes.java.recordwriter</name>
<value>true</value>
</property>
</configuration>
8、运行任务
hadoop fs -rmr output
hadoop pipes -conf job_config.xml -input input/myfile.txt -output output -program bin/wordcount
9、查看结果
hadoop fs -ls output
hadoop fs -cat output/part-00000
hadoop fs -cat output/part-00001
结果格式如下
1 1
12 1
13 1
2 1
3 1
4 1
5 1
更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13
