hadoop学习笔记之-生产环境Hadoop大集群配置安装
2013-3-7
安装环境
操作平台:vmware2
操作系统:Oracle Enterprise Linux 5.6
软件版本:hadoop-0.22.0,jdk-6u18
集群架构:3+ node,master node(hotel01),slave node(hotel02,hotel03…)
主机名
IP
系统版本
Hadoop node
hadoop进程名
hotel01
192.168.2.111
OEL5.6
master
namenode,jobtracker
hotel02
192.168.2.112
OEL5.6
slave
datanode,tasktracker
hotel03
192.168.2.113
OEL5.6
slave
datanode,tasktracker
…..
说明:目前hadoop测试主机只有三台,但在真正的hadoop集群生产环境中,可能上百台或是更多主机,所以下面的安装步骤尽可能站在一个大的hadoop集群环境角度进行安装,减少在每台服务器的单独操作,因为这样每个操作都可能是一个庞大的工程。
安装步骤
1. 下载Hadoop和jdk:
http://mirror.bit.edu.cn/apache/hadoop/common/
如:hadoop-0.22.0
2. 配置DNS解析主机名
说明:在生产的hadoop集群环境中,由于服务器可能会有许多台,通过配置DNS映射机器名,相比配置/etc/host方法,可以避免在每个节点都配置各自的host文件,而且在新增节点时也不需要修改每个节点的/etc/host的主机名-IP映射文件。减少了配置步骤和时间,便于管理。
详细步骤见:
【hadoop学习笔记之-DNS配置】
http://blog.csdn.net/lichangzai/article/details/8645524
配置说明:NDS服务器放在了hotel01(master)节点上,对hotel01、hotel02、hotel03节点的主机名进行解析。
3. 建立hadoop运行账号
在所有的节点创建hadoop运行账号
[root@gc ~]# groupadd hadoop
[root@gc ~]# useradd -g hadoop grid--注意此处一定要指定分组,不然可能会不能建立互信
[root@gc ~]# idgrid
uid=501(grid)gid=54326(hadoop) groups=54326(hadoop)
[root@gc ~]# passwd grid
Changingpassword for user grid.
New UNIXpassword:
BAD PASSWORD: itis too short
Retype new UNIXpassword:
passwd: allauthentication tokens updated successfully.
说明:在大的hadoop集群安装环境中,这步可以在批量安装linux系统之前完成,然后再进行系统的复制。(没有试过,据说可以ghost工具软件应该可以实现)
4. 通过NFS配置ssh免密码连入
说明:通过NFS配置ssh免密码连入时,当我们有新的节点接入时,不再需要分别向其它节点各自添加自己公钥信息,只需要把公钥信息追加到共享的authorized_keys公钥当中,其它节点就直接指向最新的公钥文件。便于分配公钥和管理。
详细步骤见:
【hadoop学习笔记之-NFS配置】
http://blog.csdn.net/lichangzai/article/details/8646227
5. 解压hadoop安装包
--可先一某节点解压配置文件
[grid@hotel01 ~]$ ll
总计 43580
-rw-r--r-- 1 grid hadoop 445755682012-11-19 hadoop-0.20.2.tar.gz
[grid@hotel01~]$tar xzvf /home/grid/hadoop-0.20.2.tar.gz
[grid@hotel01~]$ ll
总计 43584
drwxr-xr-x 12 grid hadoop 4096 2010-02-19hadoop-0.20.2
-rw-r--r-- 1 grid hadoop 44575568 2012-11-19 hadoop-0.20.2.tar.gz
--在各节点安装jdk
[root@hotel01~]#./jdk-6u18-linux-x64-rpm.bin
6. Hadoop配置有关文件
◆ 配置hadoop-env.sh
[root@gc conf]#pwd
/root/hadoop-0.20.2/conf
--修改jdk安装路径
[root@gc conf]vihadoop-env.sh
export JAVA_HOME=/usr/java/jdk1.6.0_18
◆ 配置namenode,修改site文件
--修改core-site.xml文件
[gird@hotel01conf]# vi core-site.xml
<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl" href="configuration.xsl"?>
<!-- Putsite-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://hotel01.licz.com:9000</value>#完全分布式不能用localhost,要用master节点的IP或机器名.
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/grid/hadoop/tmp</value>
</property>
</configuration>
注:fs.default.nameNameNode的IP地址和端口
--修改hdfs-site.xml文件
[grid@hotel01hadoop-0.20.2]$ mkdir data
[gird@hotel01conf]# vi hdfs-site.xml
<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl" href="configuration.xsl"?>
<!-- Putsite-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.data.dir</name>
<value>/home/grid/hadoop-0.20.2/data</value>--注意此目录必需已经创建并能读写
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
</configuration>
hdfs-site.xml文件中常用配置参数:
--修改mapred-site.xml文件
[gird@hotel01conf]# vi mapred-site.xml
<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl" href="configuration.xsl"?>
<!-- Putsite-specific property overrides in this file. -->
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>hotel01.licz.com:9001</value>
</property>
</configuration>
mapred-site.xml文件中常用配置参数
◆ 配置masters和slaves文件
[gird@hotel01conf]$ vi masters
hotel01.licz.com
[gird@hotel01conf]$ vi slaves
hotel02.licz.com
hotel03.licz.com
7. 向各节点复制hadoop(awk命令)
--把hotel01.licz.com主机上面hadoop配置好的文件分别copy到各节点
--原来copy的方法是一个个命令执行,如下
[gird@hotel01conf]$ scp -rp hadoop-0.20.2 hotel02.licz.com:/home/grid/
[gird@hotel01conf]$ scp -rp hadoop-0.20.2 hotel03.licz.com:/home/grid/
--但站在hadoop大集群的角度,上面方法会很费时,我们可用awk命令生成批量执行的脚本,批量执行,省时省力,如下:
[grid@hotel01~]$ cat hadoop-0.20.2/conf/slaves| awk '{print "scp -rp hadoop-0.20.2grid@"$1":/home/grid"}' > scp.sh
[grid@hotel01~]$ chmod u+x scp.sh
[grid@hotel01~]$ cat scp.sh
scp -rp hadoop-0.20.2grid@hotel02.licz.com:/home/grid
scp -rp hadoop-0.20.2grid@hotel03.licz.com:/home/grid
[grid@hotel01~]$ ./scp.sh
8. 格式化namenode
--在namenode节点进行格式化
[grid@hotel01bin]$ pwd
/home/grid/hadoop-0.20.2/bin
[gird@hotel01bin]$ ./hadoop namenode -format
12/10/3108:03:31 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG:Starting NameNode
STARTUP_MSG: host = gc.localdomain/192.168.2.100
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 0.20.2
STARTUP_MSG: build =https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20 -r 911707;compiled by 'chrisdo' on Fri Feb 19 08:07:34 UTC 2010
************************************************************/
12/10/3108:03:31 INFO namenode.FSNamesystem: fsOwner=grid,hadoop
12/10/3108:03:31 INFO namenode.FSNamesystem: supergroup=supergroup
12/10/3108:03:31 INFO namenode.FSNamesystem: isPermissionEnabled=true
12/10/3108:03:32 INFO common.Storage: Image file of size 94 saved in 0 seconds.
12/10/3108:03:32 INFO common.Storage: Storage directory /tmp/hadoop-grid/dfs/name hasbeen successfully formatted.
12/10/3108:03:32 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG:Shutting down NameNode at gc.localdomain/192.168.2.100
************************************************************/
9. 启动hadoop
--在master节点启动hadoop守护进程
[gird@hotel01bin]$ pwd
/home/grid/hadoop-0.20.2/bin
[gird@hotel01bin]$ ./start-all.sh
startingnamenode, logging to /home/grid/hadoop-0.20.2/bin/../logs/hadoop-grid-namenode-gc.localdomain.out
rac2: startingdatanode, logging to /home/grid/hadoop-0.20.2/bin/../logs/hadoop-grid-datanode-rac2.localdomain.out
rac1: startingdatanode, logging to /home/grid/hadoop-0.20.2/bin/../logs/hadoop-grid-datanode-rac1.localdomain.out
The authenticityof host 'gc (192.168.2.100)' can't be established.
RSA keyfingerprint is 8e:47:42:44:bd:e2:28:64:10:40:8e:b5:72:f9:6c:82.
Are you sure youwant to continue connecting (yes/no)? yes
gc: Warning:Permanently added 'gc,192.168.2.100' (RSA) to the list of known hosts.
gc: startingsecondarynamenode, logging to /home/grid/hadoop-0.20.2/bin/../logs/hadoop-grid-secondarynamenode-gc.localdomain.out
startingjobtracker, logging to /home/grid/hadoop-0.20.2/bin/../logs/hadoop-grid-jobtracker-gc.localdomain.out
rac2: startingtasktracker, logging to /home/grid/hadoop-0.20.2/bin/../logs/hadoop-grid-tasktracker-rac2.localdomain.out
rac1: startingtasktracker, logging to /home/grid/hadoop-0.20.2/bin/../logs/hadoop-grid-tasktracker-rac1.localdomain.out
10. 用jps检验各后台进程是否成功启动
--在master节点查看后台进程
[gird@hotel01bin]$ /usr/java/jdk1.6.0_18/bin/jps
27462 NameNode
29012 Jps
27672 JobTracker
27607SecondaryNameNode
--在slave节点查看后台进程
[grid@rac1 conf]$ /usr/java/jdk1.6.0_18/bin/jps
16722 Jps
16672TaskTracker
16577 DataNode
[grid@rac2conf]$ /usr/java/jdk1.6.0_18/bin/jps
31451 DataNode
31547TaskTracker
31608 Jps
11. 通过web了解Hadoop的活动
通过用浏览器和http访问jobtracker所在节点的50030端口监控jobtracker
Jobtracker监控
http://192.168.2.111:50030/jobtracker.jsp
通过用浏览器和http访问namenode所在节点的50070端口监控集群
http://192.168.2.111:50070/dfshealth.jsp