大数据实验三——MapRuduce
实验步骤:
1、启动Hadoop
[[email protected] ~]# jps
2、在/usr/local/filecotent下新建hellodemo文件,并写入以下内容,以\t(tab键隔开)
[[email protected] filecontent]# vi hellodemo
hello you
hello me
3、在SecureCRT中运行执行以下步骤:
①hdfs中创建data目录
[[email protected] filecontent]# hadoop dfs -mkdir /data
②将/usr/local/filecontent/hellodemo 上传到hdfs的data目录中
[[email protected] filecontent]# hadoop dfs -put hellodemo /data
③查看data目录下的内容
[[email protected] filecontent]# hadoop dfs -ls /data
④查看hellodemo的文件内容
[[email protected] filecontent]# hadoop dfs -text /data/hellodemo
4、编写WordCountTest.java并打包成jar文件
因为运行的是Wordcount程序,只需要如下三个jar包:
$HADOOP_HOME/share/hadoop/common/hadoop-common-2.6.0.jar
$HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.6.0.jar
$HADOOP_HOME/share/hadoop/common/lib/commons-cli-1.2.jar
导入后不再报错,下一步就是生成jar文件。右键单击包,选择Export–>Java–>JAR file–>next,输入jar文件的文件名和生成路径
5、打成jar包并指定主类,最后运行
[[email protected] filecontent]# hadoop jar hellodemo.jar