准备Linux环境
修改主机名:
$ vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=hadoop001
修改IP:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=♦♦♦♦♦♦♦♦♦♦♦♦♦
TYPE=Ethernet
UUID=♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=172.17.30.111
NETMASK=255.255.254.0
GATEWAY=172.17.30.1
DNS1=223.5.5.5
DNS2=223.6.6.6
关闭防火墙:
查看防火墙状态
service iptables status
关闭防火墙
service iptables stop
查看防火墙开机启动状态
chkconfig iptables --list
关闭防火墙开机启动
chkconfig iptables off
修改主机名和IP映射关系:
$ vim /etc/hosts
172.17.30.111 hadoop001
172.17.30.112 hadoop002
172.17.30.113 hadoop003
172.17.30.114 hadoop004
172.17.30.115 hadoop005
172.17.30.116 hadoop006
172.17.30.117 hadoop007
重启机器:
# reboot
安装JDK
解压jdk:
# tar -zxvf jdk-7u79-linux-x64.tar.gz -C /opt/modules/
添加环境变量:
# vim /etc/profile
##JAVA
JAVA_HOME=/opt/modules/jdk1.7.0_79
JRE_HOME=/opt/modules/jdk1.7.0_79/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
刷新配置:
# source /etc/profile
安装hadoop2.4.1
解压hadoop2.4.1:
# tar -zxvf hadoop-2.4.1.tar.gz -C /opt/modules/
添加环境变量:
# vim /etc/profile
##HADOOP
export HADOOP_HOME=/opt/modules/hadoop-2.4.1
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
刷新配置:
# source /etc/profile
集群规划:
主机名 IP 安装的软件 运行的进程
hadoop001 172.17.30.111 jdk、hadoop NameNode、DFSZKFailoverController(zkfc)
hadoop002 172.17.30.112 jdk、hadoop NameNode、DFSZKFailoverController(zkfc)
hadoop003 172.17.30.113 jdk、hadoop ResourceManager
hadoop004 172.17.30.114 jdk、hadoop ResourceManager
hadoop005 172.17.30.115 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
hadoop006 172.17.30.116 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
hadoop007 172.17.30.117 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
说明:
1.在hadoop2.0中通常由两个NameNode组成,一个处于active状态,另一个处于standby状态。Active NameNode对外提供服务,而Standby NameNode则不对外提供服务,仅同步active namenode的状态,以便能够在它失败时快速进行切换。
hadoop2.0官方提供了两种HDFS HA的解决方案,一种是NFS,另一种是QJM。这里我们使用简单的QJM。在该方案中,主备NameNode之间通过一组JournalNode同步元数据信息,一条数据只要成功写入多数JournalNode即认为写入成功。通常配置奇数个JournalNode
这里还配置了一个zookeeper集群,用于ZKFC(DFSZKFailoverController)故障转移,当Active NameNode挂掉了,会自动切换Standby NameNode为standby状态
2.hadoop-2.2.0中依然存在一个问题,就是ResourceManager只有一个,存在单点故障,hadoop-2.4.1解决了这个问题,有两个ResourceManager,一个是Active,一个是Standby,状态由zookeeper进行协调
配置HDFS:
修改hadoop-env.sh:
# vim hadoop-env.sh
export JAVA_HOME=/opt/modules/jdk1.7.0_79
修改core-site.xml:
# vim core-site.xml
<configuration> <!-- 指定hdfs的nameservice为ns1 --> <property> <name>fs.defaultFS</name> <value>hdfs://ns1</value> </property> <!-- 指定hadoop临时目录 --> <property> <name>hadoop.tmp.dir</name> <value>/opt/data/tmp</value> </property> <!-- 指定zookeeper地址 --> <property> <name>ha.zookeeper.quorum</name> <value>hadoop005:2181,hadoop006:2181,hadoop007:2181</value> </property> </configuration> |
修改hdfs-site.xml:
# vim hdfs-site.xml
<configuration> <!--指定hdfs的nameservice为ns1,需要和core-site.xml中的保持一致 --> <property> <name>dfs.nameservices</name> <value>ns1</value> </property> <!-- ns1下面有两个NameNode,分别是nn1,nn2 --> <property> <name>dfs.ha.namenodes.ns1</name> <value>nn1,nn2</value> </property> <!-- nn1的RPC通信地址 --> <property> <name>dfs.namenode.rpc-address.ns1.nn1</name> <value>hadoop001:9000</value> </property> <!-- nn1的http通信地址 --> <property> <name>dfs.namenode.http-address.ns1.nn1</name> <value>hadoop001:50070</value> </property> <!-- nn2的RPC通信地址 --> <property> <name>dfs.namenode.rpc-address.ns1.nn2</name> <value>hadoop002:9000</value> </property> <!-- nn2的http通信地址 --> <property> <name>dfs.namenode.http-address.ns1.nn2</name> <value>hadoop002:50070</value> </property> <!-- 指定NameNode的元数据在JournalNode上的存放位置 --> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://hadoop005:8485;hadoop006:8485;hadoop007:8485/ns1</value> </property> <!-- 指定JournalNode在本地磁盘存放数据的位置 --> <property> <name>dfs.journalnode.edits.dir</name> <value>/opt/data/journaldata</value> </property> <!-- 开启NameNode失败自动切换 --> <property> <name>dfs.ha.automatic-failover.enabled</name> <value>true</value> </property> <!-- 配置失败自动切换实现方式 --> <property> <name>dfs.client.failover.proxy.provider.ns1</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> <!-- 配置隔离机制方法,多个机制用换行分割,即每个机制暂用一行--> <property> <name>dfs.ha.fencing.methods</name> <value> sshfence shell(/bin/true) </value> </property> <!-- 使用sshfence隔离机制时需要ssh免登陆 --> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/root/.ssh/id_rsa</value> </property> <!-- 配置sshfence隔离机制超时时间 --> <property> <name>dfs.ha.fencing.ssh.connect-timeout</name> <value>30000</value> </property> </configuration> |
修改mapred-site.xml:
# cp mapred-site.xml.template mapred-site.xml
# vim mapred-site.xml
<configuration> <!-- 指定mr框架为yarn方式 --> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration> |
修改yarn-site.xml:
# vim yarn-site.xml
<configuration> <!-- 开启RM高可用 --> <property> <name>yarn.resourcemanager.ha.enabled</name> <value>true</value> </property> <!-- 指定RM的cluster id --> <property> <name>yarn.resourcemanager.cluster-id</name> <value>yrc</value> </property> <!-- 指定RM的名字 --> <property> <name>yarn.resourcemanager.ha.rm-ids</name> <value>rm1,rm2</value> </property> <!-- 分别指定RM的地址 --> <property> <name>yarn.resourcemanager.hostname.rm1</name> <value>hadoop003</value> </property> <property> <name>yarn.resourcemanager.hostname.rm2</name> <value>hadoop004</value> </property> <!-- 指定zk集群地址 --> <property> <name>yarn.resourcemanager.zk-address</name> <value>hadoop005:2181,hadoop006:2181,hadoop007:2181</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> </configuration> |
修改slaves(slaves是指定子节点的位置,因为要在hadoop001上启动HDFS、在hadoop003启动yarn,所以hadoop001上的slaves文件指定的是datanode的位置,hadoop003上的slaves文件指定的是nodemanager的位置):
# vim slaves
hadoop005 hadoop006 hadoop007 |
配置免密码登录:
在hadoop001上产生一对密钥
# ssh-keygen -t rsa
配置hadoop001到hadoop002、hadoop003、hadoop004、hadoop005、hadoop006、hadoop007的免密码登陆
将公钥拷贝到其他节点,包括自己
# ssh-copy-id hadoop001
# ssh-copy-id hadoop002
# ssh-copy-id hadoop003
# ssh-copy-id hadoop004
# ssh-copy-id hadoop005
# ssh-copy-id hadoop006
# ssh-copy-id hadoop007
在hadoop003上产生一对密钥
# ssh-keygen -t rsa
配置hadoop003到hadoop004、hadoop005、hadoop006、hadoop007的免密码登陆
# ssh-copy-id hadoop004
# ssh-copy-id hadoop005
# ssh-copy-id hadoop006
# ssh-copy-id hadoop007
注意:两个namenode之间要配置ssh免密码登陆,
在hadoop002上产生一对密钥
# ssh-keygen -t rsa
配置hadoop002到hadoop001的免登陆
# ssh-copy-id hadoop001
将配置好的hadoop2.4.1拷贝到其他节点:
# scp -r hadoop-2.4.1/ hadoop002:/opt/modules/
# scp -r hadoop-2.4.1/ hadoop003:/opt/modules/
# scp -r hadoop-2.4.1/ hadoop004:/opt/modules/
# scp -r hadoop-2.4.1/ hadoop005:/opt/modules/
# scp -r hadoop-2.4.1/ hadoop006:/opt/modules/
# scp -r hadoop-2.4.1/ hadoop007:/opt/modules/
安装配置zooekeeper集群(在hadoop005)
解压zookeeper:
# tar -zxvf zookeeper-3.4.5.tar.gz -C /opt/modules/
添加环境变量:
# vim /etc/profile
##ZOOKEEPER
export ZOOKEEPER_HOME=/opt/modules/zookeeper-3.4.5
export PATH=$PATH:$ZOOKEEPER_HOME/bin
修改配置:
# pwd
/opt/modules/zookeeper-3.4.5/conf
# cp zoo_sample.cfg zoo.cfg
# vim zoo.cfg
修改:dataDir=/opt/modules/zookeeper-3.4.5/tmp
在配置文件最后添加:
server.1=hadoop005:2888:3888
server.2=hadoop006:2888:3888
server.3=hadoop007:2888:3888
创建tmp文件夹
# mkdir tmp
在tmp文件夹中创建空文件添加myid文本为1
# echo 1 > myid
示例:
# cat myid
1
将配置好的zookeeper拷贝到其他节点:
# scp -r zookeeper-3.4.5/ hadoop006:/opt/modules/
# scp -r zookeeper-3.4.5/ hadoop007:/opt/modules/
注意:修改hadoop006、hadoop007对应/opt/modules/zookeeper-3.4.5/tmp/myid内容
hadoop006:
# echo 2 > myid
hadoop007:
# echo 3 > myid
注意:第一次启动集群严格按照下面的步骤:
启动zookeeper集群(分别在hadoop005、hadoop00、hadoop007上启动)
$ zkServer.sh start
查看状态:
# zkServer.sh status 一个leader两个follower
启动journalnode(分别在hadoop005、hadoop00、hadoop007上执行)
# hadoop-daemon.sh start journalnode
运行jps命令:若是有JournalNode进程说明journalnode执行成功
# jps
示例:
2308 QuorumPeerMain
2439 JournalNode
2486 Jps
格式化HDFS:
# hdfs namenode –format
格式化后会在根据core-site.xml中的hadoop.tmp.dir配置生成个文件,这里我配置的是/opt/data/tmp,然后将/opt/data/tmp拷贝到hadoop002的/opt/data/下。
scp -r tmp/ hadoop002: /opt/data/
格式化ZKFC:
# hdfs zkfc –formatZK
启动HDFS(在hadoop001上启动):
# start-dfs.sh
启动YARN(注意:在hadoop003上启动。把namenode和resourceManager分开是因为性能问题,因为他们都要占用大量的资源,所以要分开,启动当然是在不同机器上启动。):
# start-yarn.sh
hadoop2.4.1配置完毕,可以浏览器访问:
NameNode’hadoop001:9000’(active)
NameNode’hadoop002:9000’(standby)
测试集群工作状态的一些指令 :
# hdfs dfsadmin -report 查看hdfs的各节点状态信息
# hdfs haadmin -getServiceState nn1 获取一个namenode节点的HA状态
# hadoop-daemon.sh start namenode 单独启动一个namenode进程
# hadoop-daemon.sh start zkfc 单独启动一个zkfc进程
如果只有3台主机,可以按照如下规划来部署安装
hadoop001 zookeeper journalnode namenode zkfc resourcemanager datanode
hadoop002 zookeeper journalnode namenode zkfc resourcemanager datanode
hadoop003 zookeeper journalnode datanode