集群规划:
主机名 IP 安装的软件 运行的进程
hadoop01 192.168.88.155 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
hadoop02(A)192.168.88.164 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
hadoop03(B)192.168.88.165 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
hadoop04(C)192.168.88.162 jdk、hadoop NameNode、DFSZKFailoverController(zkfc)
hadoop05(D)192.168.88.166 jdk、hadoop NameNode、DFSZKFailoverController(zkfc)
hadoop06(E)192.168.88.167 jdk、hadoop ResourceManager
hadoop07(F) 192.168.88.168 jdk、hadoop ResourceManager
说明:
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进行协调
2.安装配置hadoop集群
2.1解压
[root@localhost Desktop]# tar -zxvf hadoop-2.6.0.tar.gz -C /home/hadoop #解压到目录/home/hadoop
[root@localhost Desktop]# cd /home/hadoop
2.2配置HDFS(hadoop2.0所有的配置文件都在$HADOOP_HOME/etc/hadoop目录下)
#将hadoop添加到环境变量中
vim /etc/profile
export JAVA_HOME=/usr/lib/java/java-7-sun
export HADOOP_HOME=/home/hadoop/hadoop-2.6.0
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin
[root@localhost hadoop-2.6.0]# cd etc
[root@localhost etc]# ls
hadoop
[root@localhost etc]# cd hadoop
2.2.1修改hadoop-env.sh
export JAVA_HOME=/usr/lib/java/java-7-sun
2.2.2修改core-site.xml
<!-- 指定hdfs的nameservice为ns1 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1</value>
</property>
<!-- 指定hadoop临时目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/hadoop-2.6.0/tmp</value>
</property>
<!-- 指定zookeeper地址 -->
<property>
<name>ha.zookeeper.quorum</name>
<value>hadoop01:2181,hadoop02:2181,hadoop03:2181</value>
</property>
2.2.3修改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>hadoop04:9000</value>
</property>
<!-- nn1的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>hadoop04:50070</value>
</property>
<!-- nn2的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>hadoop05:9000</value>
</property>
<!-- nn2的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>hadoop05:50070</value>
</property>
<!-- 指定NameNode的元数据在JournalNode上的存放位置 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://hadoop01:8485;hadoop02:8485;hadoop03:8485/ns1</value>
</property>
<!-- 指定JournalNode在本地磁盘存放数据的位置 -->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/home/hadoop/hadoop-2.6.0/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>/home/hadoop/.ssh/id_rsa</value>
</property>
<!-- 配置sshfence隔离机制超时时间 -->
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
</configuration>
2.2.6修改slaves(slaves是指定子节点的位置,因为要在hadoop04上启动HDFS、在hadoop06启动yarn,所以hadoop04上的slaves文件指定的是datanode的位置,hadoop06上的slaves文件指定的是nodemanager的位置)(最好六个都这样配)
hadoop01
hadoop02
hadoop03
2.2.7配置免密码登陆
#首先要配置hadoop04到hadoop01、hadoop02、hadoop03、hadoop04、hadoop05、hadoop06 hadoop07的免密码登陆
#在whadoop04上生产一对钥匙
ssh-keygen -t rsa
#将公钥拷贝到其他节点,包括自己
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop01
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop02
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop03
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop04
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop05
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop06
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop07
#配置hadoop06到hadoop01、hadoop02、hadoop03、hadoop07的免密码登陆
#在hadoop03上生产一对钥匙
ssh-keygen -t rsa
#将公钥拷贝到其他节点
ssh-coyp-id hadoop01
ssh-coyp-id hadoop02
ssh-coyp-id hadoop03
ssh-coyp-id hadoop07
#注意:两个namenode之间要配置ssh免密码登陆,别忘了配置hadoop05到hadoop04的免登陆
在hadoop05上生产一对钥匙
ssh-keygen -t rsa
sh-coyp-id -i hadoop04
2.4将配置好的hadoop04拷贝到其他节点
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop01:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop02:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop03:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop05:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop06:/home/hadoop/
[root@hadoop01 hadoop]# scp -r hadoop-2.6.0/ root@hadoop07:/home/hadoop/
###注意:严格按照下面的步骤
2.5启动zookeeper集群(分别在hadoop01、hadoop02、hadoop03上启动zk)
cd /root/Desktop/app/zookeeper-3.4.5/bin
./zkServer.sh start
#查看状态:一个leader,两个follower
./zkServer.sh status
2.6启动journalnode(分别在在hadoop01、hadoop02、hadoop03上执行)
[root@hadoop02 bin]# cd /home/hadoop/hadoop-2.6.0
[root@hadoop01 hadoop-2.6.0]# sbin/hadoop-daemon.sh start journalnode
starting journalnode, logging to /home/hadoop/hadoop-2.6.0/logs/hadoop-root-journalnode-hadoop01.out
[root@hadoop01 hadoop-2.6.0]# jps
4539 QuorumPeerMain
4929 Jps
4893 JournalNode
一定要确定三台datenode启动起来若没启动看“home/hadoop/hadoop-2.6.0/logs/hadoop-root-journalnode-hadoop01.out”日志
#运行jps命令检验,hadoop01、hadoop02、hadoop03上多了JournalNode进程
2.7格式化HDFS
#在hadoop04上执行命令:
hdfs namenode -format
15/12/17 04:17:19 INFO namenode.FSImage: Allocated new BlockPoolId: BP-853305614-192.168.88.162-1450354639048
15/12/17 04:17:19 INFO common.Storage: Storage directory /home/hadoop/hadoop-2.6.0/tmp/dfs/name has been successfully formatted.
15/12/17 04:17:20 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
15/12/17 04:17:20 INFO util.ExitUtil: Exiting with status 0
15/12/17 04:17:20 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at hadoop04/192.168.88.162
************************************************************/
#格式化后会在根据core-site.xml中的hadoop.tmp.dir配置生成个文件,这里我配置的是/home/hadoop/hadoop-2.6.0/tmp,然后将/home/hadoop/hadoop-2.6.0/tmp拷贝到hadoop05的/hadoop/hadoop-2.6.0/下。[root@hadoop04 hadoop-2.6.0]# scp -r tmp/ hadoop05:/home/hadoop/hadoop-2.6.0
[root@hadoop04 hadoop-2.6.0]# scp -r tmp/ hadoop05:/home/hadoop/hadoop-2.6.0
seen_txid 100% 2 0.0KB/s 00:00
fsimage_0000000000000000000 100% 351 0.3KB/s 00:00
VERSION 100% 206 0.2KB/s 00:00
fsimage_0000000000000000000.md5 100% 62 0.1KB/s 00:00
##也可以这样,建议hdfs namenode -bootstrapStandby
2.8格式化ZKFC(在hadoop04上执行即可)
hdfs zkfc -formatZK
5/12/17 04:44:46 INFO ha.ActiveStandbyElector: Session connected.
15/12/17 04:44:46 INFO ha.ActiveStandbyElector: Successfully created /hadoop-ha/ns1 in ZK.
15/12/17 04:44:46 INFO zookeeper.ZooKeeper: Session: 0x351aff1d8980000 closed
15/12/17 04:44:46 INFO zookeeper.ClientCnxn: EventThread shut down、
2.9启动HDFS(在hadoop04上执行)
[root@hadoop04 hadoop-2.6.0]# sbin/hadoop-daemon.sh start zkfc(不启动这个就会两台standby)
[root@hadoop04 hadoop-2.6.0]# sbin/start-dfs.sh
[root@hadoop05 hadoop-2.6.0]# sbin/hadoop-daemon.sh start zkfc(另一台namenode 启用zkfc)
这时候配置里面得datanode和name node全部都启动起来了
http://192.168.88.162:50070/dfshealth.html#tab-overview
Started: | Sat Dec 19 04:35:20 PST 2015 |
---|---|
Version: | 2.6.0, re3496499ecb8d220fba99dc5ed4c99c8f9e33bb1 |
Compiled: | 2014-11-13T21:10Z by jenkins from (detached from e349649) |
Cluster ID: | CID-4cb4b3a6-09a5-49c8-a88a-40248886089b |
Block Pool ID: | BP-915542458-192.168.88.162-1450526096844 |
另一台namenode
http://192.168.88.166:50070/dfshealth.html#tab-overview
Started: | Sat Dec 19 04:35:20 PST 2015 |
---|---|
Version: | 2.6.0, re3496499ecb8d220fba99dc5ed4c99c8f9e33bb1 |
Compiled: | 2014-11-13T21:10Z by jenkins from (detached from e349649) |
Cluster ID: | CID-4cb4b3a6-09a5-49c8-a88a-40248886089b |
Block Pool ID: | BP-915542458-192.168.88.162-1450526096844 |
如hadoop01
[root@hadoop01 hadoop-2.6.0]# jps
4539 QuorumPeerMain
1502 DataNode
1616 Jps
621 JournalNode
[root@hadoop04 hadoop-2.6.0]# sbin/hadoop-daemon.sh start namenode
hadoop04
[root@hadoop04 hadoop-2.6.0]# jps
4282 NameNode
4674 Jps
hadoop01,2,3
[root@hadoop02 hadoop-2.6.0]# jps
32417 JournalNode
28495 Jps
28175 DataNode
28366 NodeManager
4561 QuorumPeerMain
2.10启动YARN(#####注意#####:是在hadoop6上执行start-yarn.sh,把namenode和resourcemanager分开是因为性能问题,因为他们都要占用大量资源,所以把他们分开了,他们分开了就要分别在不同的机器上启动)
[root@hadoop06 hadoop-2.6.0]# sbin/start-yarn.sh
[root@hadoop07 ~]# jps
27582 Jps
28583 ResourceManager
[root@hadoop06 ~]# jps
27582 Jps
28583 ResourceManager
hadoop04上上传文件
[root@hadoop04 Desktop]# hadoop fs -put test.sh /
http://192.168.88.162:50070/explorer.html#/的
Permission | Owner | Group | Size | Replication | Block Size | Name |
---|---|---|---|---|---|---|
drwxr-xr-x | root | supergroup | 0 B | 0 | 0 B | test.sh |
测试yarn http://192.168.88.167:8088/cluster
Apps Submitted | Apps Pending | Apps Running | Apps Completed | Containers Running | Memory Used | Memory Total | Memory Reserved | VCores Used | VCores Total | VCores Reserved | Active Nodes | Decommissioned Nodes | Lost Nodes | Unhealthy Nodes | Rebooted Nodes |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 B | 24 GB | 0 B | 0 | 24 | 0 | 3 | 0 | 3 | 0 | 0 |
Show
entries
Search:
ID |
User |
Name |
Application Type |
Queue |
StartTime |
FinishTime |
State |
FinalStatus |
Progress |
Tracking UI |
---|---|---|---|---|---|---|---|---|---|---|
No data available in table |
[root@hadoop06 mapreduce]# cd /home/hadoop/hadoop-2.6.0/share/hadoop/mapreduce
[root@hadoop06 mapreduce]# hadoop jar hadoop-mapreduce-examples-2.6.0.jar pi 5 5
[root@hadoop03 hadoop-2.6.0]# jps(任务调度)
1049 MRAppMaster
32407 DataNode
4729 JournalNode
32629 NodeManager
4549 QuorumPeerMain
1166 Jps
测试yarn http://192.168.88.168:8088/cluster
This is standby RM. Redirecting to the current active RM: http://hadoop06:8088/cluster
在hadoop04上测试
[root@hadoop04 Desktop]# hdfs haadmin -getServiceState nn1
active
[root@hadoop04 Desktop]# hdfs haadmin -getServiceState nn2
standby
[root@hadoop04 Desktop]#
测试集群工作状态的一些指令 :
bin/hdfs dfsadmin -report 查看hdfs的各节点状态信息
bin/hdfs haadmin -getServiceState nn1 获取一个namenode节点的HA状态
sbin/hadoop-daemon.sh start namenode 单独启动一个namenode进程
./hadoop-daemon.sh start zkfc 单独启动一个zkfc进程