多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
不做强制要求,能完成最好。但是要求要明白 NameNode 和 ResourceManager是存在单点故障问题的,解决方式就是 HA(High Available、即高可用性集群)。 [TOC] # 1. HDFS-HA集群配置 ## 1.1 配置HDFS-HA集群 1. 官方地址:http://hadoop.apache.org/ 2. HDFS高可用集群规划,请先搭建好一个Hadoop完全分布式集群(可以未进行namenode格式化)和ZooKeeper完全分布式环境已经安装完成。 | Hadoop102 | Hadoop103 | Hadoop104 | | --- | --- | --- | | NameNode | NameNode | | | ResourceManager | ResourceManager | | | ZKFC(zookeeper的一个集群监控工具) | ZKFC | | | DataNode | DataNode | DataNode | | JournalNode | JournalNode | JournalNode | | NodeManager | NodeManager | NodeManager | | ZooKeeper | ZooKeeper | ZooKeeper | 3. 在hadoop102配置core-site.xml ```xml <configuration> <!-- 把两个NameNode)的地址组装成一个集群mycluster --> <property> <name>fs.defaultFS</name> <value>hdfs://mycluster</value> </property> <!-- 指定hadoop运行时产生文件的存储目录 --> <property> <name>hadoop.tmp.dir</name> <value>/opt/install/hadoop/data/tmp</value> </property> </configuration> ``` 4. 在hadoop102配置hdfs-site.xml ```xml <configuration> <!-- 完全分布式集群名称 --> <property> <name>dfs.nameservices</name> <value>mycluster</value> </property> <!-- 集群中NameNode节点都有哪些,这里是nn1和nn2 --> <property> <name>dfs.ha.namenodes.mycluster</name> <value>nn1,nn2</value> </property> <!-- nn1的RPC通信地址 --> <property> <name>dfs.namenode.rpc-address.mycluster.nn1</name> <value>hadoop102:9000</value> </property> <!-- nn2的RPC通信地址 --> <property> <name>dfs.namenode.rpc-address.mycluster.nn2</name> <value>hadoop103:9000</value> </property> <!-- nn1的http通信地址 --> <property> <name>dfs.namenode.http-address.mycluster.nn1</name> <value>hadoop102:50070</value> </property> <!-- nn2的http通信地址 --> <property> <name>dfs.namenode.http-address.mycluster.nn2</name> <value>hadoop103:50070</value> </property> <!-- 指定NameNode元数据在JournalNode上的存放位置 --> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://hadoop102:8485;hadoop103:8485;hadoop104:8485/mycluster</value> </property> <!-- 配置隔离机制,即同一时刻只能有一台服务器对外响应,多个机制用换行分割,即每个机制占用一行 --> <property> <name>dfs.ha.fencing.methods</name> <value> sshfence shell(/bin/true) </value> </property> <!-- 使用隔离机制时需要ssh无秘钥登录--> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/home/hadoop/.ssh/id_rsa</value> </property> <!-- 声明journalnode服务器存储目录--> <property> <name>dfs.journalnode.edits.dir</name> <value>/opt/install/hadoop/data/jn</value> </property> <!-- 关闭权限检查--> <property> <name>dfs.permissions.enable</name> <value>false</value> </property> <!-- 访问代理类:client,mycluster,active配置失败自动切换实现方式--> <property> <name>dfs.client.failover.proxy.provider.mycluster</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> </configuration> ``` 5. 拷贝配置好的hadoop环境到其他节点。 ```xml scp core-site.xml root@hadoop103:$PWD scp hdfs-site.xml root@hadoop103:$PWD ``` <br/> ## 1.2 启动HDFS-HA集群 1. 在各个JournalNode节点上,输入以下命令启动journalnode服务: ```sql $HADOOP_HOME/sbin/hadoop-daemon.sh start journalnode ``` 2. 在[nn1]上,对其进行格式化,并启动(如果之前已经格式化过,此处格式化会导致namenode和datanode VRESION中的clusterID不一致,进而导致datanode无法启动。解决方案:修改datanode中的clusterID与namenode中的clusterID相同): ```sql $HADOOP_HOME/bin/hdfs namenode -format $HADOOP_HOME/sbin/hadoop-daemon.sh start namenode ``` 3. 在[nn2]上,同步nn1的元数据信息: ```sql $HADOOP_HOME/bin/hdfs namenode -bootstrapStandby ``` 4. 启动[nn2]: ```sql $HADOOP_HOME/sbin/hadoop-daemon.sh start namenode ``` 5. 查看web页面显示 ![](https://img.kancloud.cn/6f/b9/6fb9da0a5e6308333137c05515199250_487x161.png) ![](https://img.kancloud.cn/b5/af/b5af1a68b34012a2f994ba7e4ac55de4_493x167.png) 6. 在[nn1]上,启动所有datanode ```sql $HADOOP_HOME/sbin/hadoop-daemons.sh start datanode ``` 7. 将[nn1]切换为Active ```sql $HADOOP_HOME/bin/hdfs haadmin -transitionToActive nn1 ``` 8. 查看是否Active ```sql $HADOOP_HOME/bin/hdfs haadmin -getServiceState nn1 ``` <br/> ## 1.3 配置HDFS-HA自动故障转移 1. 具体配置 (1)在hdfs-site.xml中增加 ```xml <property> <name>dfs.ha.automatic-failover.enabled</name> <value>true</value> </property> (2)在core-site.xml文件中增加 <property> <name>ha.zookeeper.quorum</name> <value>hadoop102:2181,hadoop103:2181,hadoop104:2181</value> </property> ``` 2. 启动 (1)关闭所有HDFS服务: ```sql stop-dfs.sh ``` (2)启动Zookeeper集群: ```sql zkServer.sh start ``` (3)初始化HA在Zookeeper中状态: ```sql hdfs zkfc -formatZK ``` (4)启动HDFS服务: ```sql start-dfs.sh ``` (5)在各个NameNode节点上启动DFSZK Failover Controller,先在哪台机器启动,哪个机器的NameNode就是Active NameNode(默认start-dfs.sh已经自动启动,以下是单独启动的命令) ```sql hadoop-daemon.sh start zkfc ``` 3.验证 (1)将Active NameNode进程kill ```sql kill -9 namenode的进程id ``` (2)将Active NameNode机器断开网络 ```sql service network stop ``` <br/> # 2. YARN-HA配置 ## 2.1 配置YARN-HA集群 1. 规划集群 | hadoop102 | hadoop103 | | --- | --- | | ResourceManager | ResourceManager | 2. 具体配置 (1)yarn-site.xml ```xml <configuration> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <!--启用resourcemanager ha--> <property> <name>yarn.resourcemanager.ha.enabled</name> <value>true</value> </property> <!--声明两台resourcemanager的地址--> <property> <name>yarn.resourcemanager.cluster-id</name> <value>cluster-yarn1</value> </property> <property> <name>yarn.resourcemanager.ha.rm-ids</name> <value>rm1,rm2</value> </property> <property> <name>yarn.resourcemanager.hostname.rm1</name> <value>hadoop102</value> </property> <property> <name>yarn.resourcemanager.hostname.rm2</name> <value>hadoop103</value> </property> <!--指定zookeeper集群的地址--> <property> <name>yarn.resourcemanager.zk-address</name> <value>hadoop102:2181,hadoop103:2181,hadoop104:2181</value> </property> <!--启用自动恢复--> <property> <name>yarn.resourcemanager.recovery.enabled</name> <value>true</value> </property> <!--指定resourcemanager的状态信息存储在zookeeper集群--> <property> <name>yarn.resourcemanager.store.class</name> <value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value> </property> </configuration> ``` (2)同步更新其他节点的yarn-site.xml配置信息 3. 启动yarn (1)在hadoop102中执行: `start-yarn.sh` (2)在hadoop103中执行: `yarn-daemon.sh start resourcemanager` (3)查看服务状态 `yarn rmadmin -getServiceState rm1`