Hadoop框架HDFS HA 的高可用
hdfs的HA (高可用)
zk:指zookeeper,负责协调,监控

HA的failover原理
- HDFS的HA,指的是在一个集群中存在两个NameNode,分别运行在独立的物理节点上。在任何时间点,只有一个NameNodes是处于Active状态,另一种是在Standby状态。 Active NameNode负责所有的客户端的操作,而Standby NameNode用来同步Active NameNode的状态信息,以提供快速的故障恢复能力。
- 为了保证Active NN与Standby NN节点状态同步,即元数据保持一致。除了DataNode需要向两个NN发送block位置信息外,还构建了一组独立的守护进程”JournalNodes”,用来同步Edits信息。当Active NN执行任何有关命名空间的修改,它需要持久化到一半以上的JournalNodes上。而Standby NN负责观察JNs的变化,读取从Active NN发送过来的Edits信息,并更新自己内部的命名空间。一旦ActiveNN遇到错误,Standby NN需要保证从JNs中读出了全部的Edits,然后切换成Active状态。
使用HA的时候,不能启动SecondaryNameNode,会出错。
HDFS的federation
- HDFS Federation设计可解决单一命名空间存在的以下几个问题:
- 1、 HDFS集群扩展性。多个NameNode分管一部分目录,使得一个集群可以扩展到更多节点,不再像1.0中那样由于内存的限制制约文件存储数目。
- 2、性能更高效。多个NameNode管理不同的数据,且同时对外提供服务,将为用户提供更高的读写吞吐率。
- 3、良好的隔离性。用户可根据需要将不同业务数据交由不同NameNode管理,这样不同业务之间影响很小。
federation架构图-1

federation架构图-2

搭建HDFS HA 高可用
节点 | zk | NN | DN | RM | NM | JN | ZKFC |
---|---|---|---|---|---|---|---|
master | 1 | 1 | 1 | 1 | 1 | ||
node1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
node2 | 1 | 1 | 1 | 1 |
1、关闭防火墙
service firewalld stop
2、时间同步
#查看3台系统时间是否一致
date
#时间同步
yum install ntp
ntpdate -u s2c.time.edu.cn
#或者
date -s 20180503
3、免密(远程执行命令)
#查看密钥是否已经配置
##查看.ssh目录下是否有私钥 id_rsa 和公钥 id_rsa.pub
cd~
cd .ssh/
ls
##使用ssh命令看是否可以免密远程登录
###master节点
ssh node1
ssh node2
### node1节点
ssh master
ssh node2
#### 退出
exit
#在两个主节点生成密钥文件
#master-->master,node1,node2
#node1-->master,node1,node2
ssh-keygen -t rsa
ssh-copy-id ip
- 查看密钥是否已经配置


可见node1节点没有配置免密


- node2配置免密成功


4、修改Hadoop配置文件
# 先在master节点上将hdfs进程停掉
stop-dfs.sh
#切换到hadoop目录
cd /usr/local/soft/hadoop-2.7.6/etc/hadoop/
#停止HDFS集群
stop-dfs.sh
#修改配置文件 vim 命令
core-site.xml
hdfs-site.xml
#保存退出
esc
:wq
#同步到其它节点
#切换到hadoop目录
cd /usr/local/soft/hadoop-2.7.6/etc/hadoop/
scp ./* node1:`pwd`
scp ./* node2:`pwd`
- 在master节点上将hdfs进程停掉

- 修改core-site.xml配置文件

复制粘贴替换掉即可
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
-->
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://cluster</value>
</property>
<property>
<name>hadoop.tmp.dir