环境说明如下:
192.168.2.96 SN2015-02-96
192.168.2.97 SN2015-02-97
192.168.2.98 SN2015-02-98
安装
1,安装jdk环境:
===============================================
vim jdk-install.sh
#!/bin/sh
pwd
mkdir /data
cd /data
wget http://xxx/jdk-7u55-linux-x64.rpm
rpm -ivh jdk-7u55-linux-x64.rpm
cat >> /etc/profile.d/development.sh <<EOF
export JAVA_HOME=/usr/java/jdk1.7.0_55
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
EOF
sh jdk-install.sh
source /etc/profile.d/development.sh
================================================
2,安装Hadoop,版本为1.2.1
cd /data
wget http://mirrors.cnnic.cn/apache/hadoop/common/hadoop-1.2.1/hadoop-1.2.1.tar.gz
tar zxvf hadoop-1.2.1.tar.gz
cd hadoop-1.2.1/conf
修改conf目录中的四个Hadoop核心配置文件hadoop-env.sh、core-site.xml、hdfs-site.xml、mapred-site.xml,具体内容如下:
hadoop-env.sh, hadoop环境变量配置文件,指定JAVA_HOME
=========================================================
export JAVA_HOME=/usr/java/jdk1.7.0_55
=========================================================
core-site.xml, hadoop core的配置项,主要针对Common组件的属性配置。由于默认的hadoop.tmp.dir的路径为/tmp/hadoop-${user.name},笔者的Linux系统的/tmp文件系统的类型是Hadoop不支持的,会报异常,因此手工修改hadoop.tmp.dir指向/data/tmp/hadoop-${user.name},作为hadoop用户的临时存储目录,配置如下:
=========================================================
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/data/tmp/hadoop-${user.name}</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://192.168.2.96:9000</value> //master主机ip:9000端口
</property>
</configuration>
==========================================================
hdfs-site.xml, hadoop的HDFS组件的配置项,包括Namenode、Secondarynamenode和Datanode等,配置如下:
=========================================================
<configuration>
<property>
<name>dfs.name.dir</name>
<value>/data/hdfs/name</value> //Namenode持久存储名字空间、事务日志路径
</property>
<property>
<name>dfs.data.dir</name>
<value>/data/hdfs/data</value> //Datanode数据存储路径
</property>
<property>
<name>dfs.datanode.max.xcievers</name>
<value>4096</value> //Datanode所允许同时执行的发送和接受任务数量,默认为256
</property>
<property>
<name>dfs.replication</name>
<value>2</value> //数据备份的个数,默认为3
</property>
</configuration>
==========================================================
mapred-site.xml,配置map-reduce组件的属性,包括jobtracker和tasktracker,配置如下:
==========================================================
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>192.168.2.96:9001</value>
</property>
</configuration>
==========================================================
masters,配置Secondarynamenode项,环境使用主设备192.168.2.96同时承担Secondarynamenode的角色,生产环境要求使用独立服务器,起到HDFS文件系统元数据(metadata)信息的备份作用,当Namenode发生故障后可以快速还原数据,配置内容如下:
192.168.2.96
salves,配置所有slave主机信息,填写IP地址即可。本示例中slave的信息如下:
192.168.2.97
192.168.2.98
接下来,从主节点(master)复制jdk及Hadoop环境到所有slave,目标路径要与Master保持一致,切记!执行以下命令进行复制:
# scp -r /usr/java/jdk1.7.0_55 192.168.2.97:/usr/java/
# scp -r /usr/java/jdk1.7.0_55 192.168.2.98:/usr/java/
# scp -r /data/tools/hadoop-1.2.1 192.168.2.97:/data/tools/
# scp -r /data/tools/hadoop-1.2.1 192.168.2.98:/data/tools/
Hadoop部分功能是通过主机名来寻址的,因此需要配置主机名hosts信息(生产环境建议直接搭建内网DNS服务),保证Hadoop环境所有主机的/etc/hosts文件配置如下:
192.168.2.96 SN2015-02-96
192.168.2.97 SN2015-02-97
192.168.2.98 SN2015-02-98
如设备启用了iptables防火墙,需要对主节点Master及Slave主机添加一下限制:
=========================================================
Master:
-I INPUT -s 192.168.2.0/24 -p tcp --dport 50030 -j ACCEPT
-I INPUT -s 192.168.2.0/24 -p tcp --dport 50070 -j ACCEPT
-I INPUT -s 192.168.2.0/24 -p tcp --dport 9000 -j ACCEPT
-I INPUT -s 192.168.2.0/24 -p tcp --dport 9001 -j ACCEPT
Slaves:
-I INPUT -s 192.168.2.0/24 -p tcp --dport 50075 -j ACCEPT
-I INPUT -s 192.168.2.0/24 -p tcp --dport 50060 -j ACCEPT
-I INPUT -s 192.168.2.96 -p tcp --dport 50010 -j ACCEPT
==========================================================
配置完成后再主节点Master上格式化文件系统的namenode,执行:
# bin/hadoop namenode -format
最后,在主节点Master上执行启动命令,如下:
# bin/start-all.sh
校验安装结果
Hadoop官方提供的一个测试MapReduce的示例,执行:
# bin/hadoop jar hadoop-examples-1.2.1.jar pi 10 100
如果返回如下所示结果,则说明配置成功。
Number of Maps = 10
Samples per Map = 100
Wrote input for Map #0
Wrote input for Map #1
Wrote input for Map #2
Wrote input for Map #3
Wrote input for Map #4
Wrote input for Map #5
Wrote input for Map #6
Wrote input for Map #7
Wrote input for Map #8
Wrote input for Map #9
Starting Job
15/03/13 09:10:21 INFO mapred.FileInputFormat: Total input paths to process : 10
15/03/13 09:10:22 INFO mapred.JobClient: Running job: job_201503130851_0001
15/03/13 09:10:23 INFO mapred.JobClient: map 0% reduce 0%
15/03/13 09:10:37 INFO mapred.JobClient: map 20% reduce 0%
15/03/13 09:10:38 INFO mapred.JobClient: map 40% reduce 0%
15/03/13 09:10:45 INFO mapred.JobClient: map 60% reduce 0%
15/03/13 09:10:48 INFO mapred.JobClient: map 80% reduce 0%
15/03/13 09:10:52 INFO mapred.JobClient: map 100% reduce 0%
15/03/13 09:10:58 INFO mapred.JobClient: map 100% reduce 26%
15/03/13 09:11:00 INFO mapred.JobClient: map 100% reduce 100%
访问Hadoop提供的管理页面,Map/Reduce管理地址:http://192.168.2.96:50030/,如下图所示
HDFS存储管理地址:http://192.168.2.96:50070 ,如下图所示
本文出自 “我的运维之路” 博客,请务必保留此出处http://pythonhome.blog.51cto.com/10015972/1622604
原文地址:http://pythonhome.blog.51cto.com/10015972/1622604