Hadoop在Linux下伪分布式的安装以及wordcount实例的运行与
Hadoop版本:hadoop-0.20.2
1、hadoop伪分布式的安装
1.安装配置java1.6。配置完毕后,在命令行中输入java -version,如出现下列信息说明java环境安装成功。
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)
2.配置ssh免密码登录
(1)安装ssh:sudo apt-get install ssh
(2)配置可以无密码登陆本机:
首先查看在u用户下是否存在.ssh文件夹(注意ssh前面有“.”,这是一个隐藏文件夹),输入命令:
cd /home/wangxing。
接下来,输入命令:
ssh-keygen -t dsa -P '' –f~/.ssh/id_dsa
这个命令会在.ssh文件夹下创建两个文件id_dsa及id_dsa.pub,这是ssh的一对私钥和公钥,类似于钥匙及锁,把id_da.pub(公钥)追加到授权的key里面去,
输入命令:cat ~/.ssh/id_dsa.pub >>~/.ssh/authorized_keys
这段话的意思是把公钥加入到用于认证的公钥文件中,这里authorized_keys是用于认证的公钥文件。至此无密码登陆本机以安装完成。
(3)验证ssh已安装成功及无密码登陆本机
输入命令:ssh –version
显示结果:
OpenSSH_5.1p1 Debian-6Ubuntu2, OpenSSL 0.9.8g 19Oct 2007
Bad escape character 'rsion'.
这显示了ssh已经安装成功
输入命令:
ssh localhost
会有如下显示:
The authenticity of host 'localhost (::1)' can't beestablished.
RSA key fingerprint is8b:c3:51:a5:2a:31:b7:74:06:9d:62:04:4f:84:f8:77.
Are you sure you want to continue connecting(yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to thelist of known hosts.
Linux master 2.6.31-14-generic #48-Ubuntu SMP FriOct 16 14:04:26 UTC 2009 i686
To access official Ubuntu documentation, pleasevisit:
http://help.ubuntu.com/
Last login: Mon Oct 18 17:12:40 2010 from master
如上显示,说明已经安装成功,第一次登录时会询问你是否继续链接,输入yes即可以进入。
实际上,在hadoop的安装过程中,是否无密码登陆不是必须的,但是如果不配置无密码登陆的话,每次启动hadoop,都需要输入密码以登陆到每台daotanode,考虑到一般的hadoop集群动辄数十数百台机器,因此一般来说都会配置ssh的无密码登陆。
3.下载hadoop-0.20.2.tar.gz,放在用户根目录下,例如:/home/wangxing/hadoop-0.20.2:
下载地址:http://mirror.bjtu.edu.cn/apache/hadoop/common/hadoop-0.20.2/
解压:tar –zvxf hadoop-0.20.2.tar.gz
4.配置hadoop,hadoop 的主要配置都在hadoop-0.20.2/conf 下。
(1)在conf/hadoop-env.sh 中配置Java 环境以及HADOOP_HOME、PATH,例如
export JAVA_HOME=/usr/local/jre1.6.0_24
export HADOOP_HOME=/home/wangxing/hadoop-0.20.2
export PATH=$PATH:/home/wangxing/hadoop-0.20.2/bin
(2)配置conf/core-site.xml、conf/hdfs-site.xml、conf/mapred-site.xml
core-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000/</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/wangxing/hadoop-0.20.2/tmpdir</value>
</property>
</configuration>
hdfs-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.name.dir</name>
<value>/home/wangxing/hadoop-0.20.2/tmpdir/hdfs/name</value>
</property>
<property>
<name>dfs.data.dir</name>
<value>/home/wangxing/hadoop-0.20.2/tmpdir/hdfs/data</value>
</property>
</configuration>
mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
<property>
<name>mapred.local.dir</name>
<value>/home/wangxing/hadoop-0.20.2/tmpdir/mapred/local</value>
</property>
<property>
<name>mapred.system.dir</name>
<value>/home/wangxing/hadoop-0.20.2/tmpdir/mapred/system</value>
</property>
</configuration>
5.格式化namenode、datanode:bin/hadoop namenode -format、bin/hadoop datanode -format
6.启动hadoop所有进程:bin/start-all.sh
7.验证hadoop是否安装成功
打开浏览器,分别输入网址
http://localhost:50030 (mapreduce的web页面)
http://localhost:50070 (hdfs的web页面)
如果都能查看,说明hadoop已经安装成功。
8.查看hadoop进程启动情况:jps。正常情况下应该有NameNode、SecondaryNameNode、DataNode、JobTracker、TaskTracker
9.查看集群状态:bin/hadoop dfsadmin -report