hadoop2.5的第一个HelloWorld程序—单词计数(WordCount.)

本文介绍了如何使用Hadoop进行WordCount实例操作,包括启动Hadoop服务、上传文本文件到HDFS、运行WordCount程序并查看结果等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先启动hadoop服务.

在文件系统上创建一个文件夹data:

[root@Master hadoop-2.5.0]# hdfs dfs -mkdir /data
Java HotSpot(TM) Client VM warning: You have loaded library /home/jzz/hadoop-2.5.0/lib/native/libhadoop.so.1.0.0 which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
14/12/21 22:36:36 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
[root@Master hadoop-2.5.0]# hdfs dfs -put -f example/file1.txt example/file2.txt  /data
Java HotSpot(TM) Client VM warning: You have loaded library /home/jzz/hadoop-2.5.0/lib/native/libhadoop.so.1.0.0 which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
14/12/21 22:37:49 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
此时访问文件系统,

http://192.168.122.130:50070

可以查看创建的文件夹。

在本地创建单词文件:

[root@Master hadoop-2.5.0]# cat example/words.txt 
hello world
hello hadoop
hello mapreduce
将单词文件放入文件系统中:

[root@Master hadoop-2.5.0]# hdfs dfs -put -f example/words.txt /data
Java HotSpot(TM) Client VM warning: You have loaded library /home/jzz/hadoop-2.5.0/lib/native/libhadoop.so.1.0.0 which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
14/12/21 23:09:23 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
运行WordCount.java:

[root@Master hadoop-2.5.0]# hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.5.0-sources.jar org.apache.hadoop.examples.WordCount /data /outputs
Java HotSpot(TM) Client VM warning: You have loaded library /home/jzz/hadoop-2.5.0/lib/native/libhadoop.so.1.0.0 which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
14/12/21 23:12:02 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14/12/21 23:12:02 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
14/12/21 23:12:03 INFO input.FileInputFormat: Total input paths to process : 3
14/12/21 23:12:04 INFO mapreduce.JobSubmitter: number of splits:3
......

查看输出结果:

[root@Master hadoop-2.5.0]# hdfs dfs -cat /outputs/part-r-00000

hadoop	1
hello	3
mapreduce	1
world	1
至于文件名,可以查询文件系统。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值