Hadoop搭建以及实例演示
1.下载jdk和hadoop,并解压至/opt
2.配置环境变量:gedit /etc/profile最后面添加:export PATH="$PATH:/opt/hadoop-0.20.2/bin:/opt/jdk1.7.0_21/bin"
3.配置在/opt/hadoop-0.20.2/conf下的3个文件: gedit hadoop-env.sh
打开java环境变量: export JAVA_HOME=/opt/jdk1.7.0_21
-------------------------------------------
gedit hdfs-site.xml 添加:
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
--------------------------------------------
gedit mapred-site.xml添加:
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
<property>
<name>mapred.child.tmp</name>
<value>/opt/temp</value>
</property>
----------------------------------------------
4.配置完成,可以在浏览器打开:50070和:50030进如管理监视界面。
5.从本地拷贝文件到hadoop:hadoop fs -mkdir /temp(创建文件夹)hadoop fs -copyFromLocal /opt/a.txt /temp/即可在浏览器界面查看刚刚考入的文件。
6.演示统计字符个数程序:[root@localhost hadoop-0.20.2]# hadoop jar hadoop-0.20.2-examples.jar wordcount /achun/a.txt /tt
演示结果:
在程序临时创建的文件夹中生成结果文件,内容如下:
book 2
fuck 4
good 2
haha 2
hello 4
mask 2
master 2
yello 2
----------------------------------------------------------
原文如下:
hello
fuck
book
mask
yello
hello
good
fuck
master
haha
hello
fuck
book
mask
yello
hello
good
fuck
master
haha