本文共 14742 字,大约阅读时间需要 49 分钟。
[toc]
单机版的Hadoop环境只有一个namenode,一般namenode出现问题,整个系统也就无法使用,所以高可用主要指的是namenode的高可用,即存在两个namenode节点,一个为active状态,一个为standby状态。如下图:
说明如下:
HDFS的HA,指的是在一个集群中存在两个NameNode,分别运行在独立的物理节点上。在任何时间点,只有一个NameNodes是处于Active状态,另一种是在Standby状态。 Active NameNode负责所有的客户端的操作,而Standby NameNode用来同步Active NameNode的状态信息,以提供快速的故障恢复能力。为了保证Active NN与Standby NN节点状态同步,即元数据保持一致。除了DataNode需要向两个NN发送block位置信息外,还构建了一组独立的守护进程”JournalNodes”,用来同步FsEdits信息。当Active NN执行任何有关命名空间的修改,它需要持久化到一半以上的JournalNodes上。而Standby NN负责观察JNs的变化,读取从Active NN发送过来的FsEdits信息,并更新自己内部的命名空间。一旦ActiveNN遇到错误,Standby NN需要保证从JNs中读出了全部的FsEdits,然后切换成Active状态。使用HA的时候,不能启动SecondaryNameNode,会出错。ip 基本的软件 运行的进程 uplooking01 jdk、zk、hadoop NameNode、zkfc、zk、journalNode uplooking02 jdk、zk、hadoop NameNode、zkfc、zk、journalNode、datanode、ResourceManager、NodeManager uplooking03 jdk、zk、hadoop zk、journalNode、datanode、ResourceManager、NodeManager
1、解压: [uplooking@uplooking01 ~]$ tar -zxvf soft/zookeeper-3.4.6.tar.gz -C app/ 2、重命名 [uplooking@uplooking01 ~]$ mv app/zookeeper-3.4.6 app/zookeeper 3、配置文件重命名 [uplooking@uplooking01 zookeeper]$ cp conf/zoo_sample.cfg conf/zoo.cfg 4、修改配置文件$ZOOKEEPER_HOME/conf/zoo.cfg dataDir=/home/uplooking/app/zookeeper/data dataLogDir=/home/uplooking/logs/zookeeper server.101=uplooking01:2888:3888 server.102=uplooking02:2888:3888 server.103=uplooking03:2888:3888 启动server表示当前节点就是zookeeper集群中的一个server节点 server后面的.数字(不能重复)是当前server节点在该zk集群中的唯一标识 =后面则是对当前server的说明,用":"分隔开, 第一段是当前server所在机器的主机名 第二段和第三段以及2818端口 2181--->zookeeper服务器开放给client连接的端口 2888--->zookeeper服务器之间进行通信的端口 3888--->zookeeper和外部进程进行通信的端口 5、在dataDir=/home/uplooking/app/zookeeper/data下面创建一个文件myid uplooking01机器对应的server.后面的101 uplooking02机器对应的server.后面的102 uplooking03机器对应的server.后面的103 6、需要将在uplooking01上面的zookeeper拷贝之uplooking02和uplooking03,这里使用scp远程拷贝 scp -r app/zookeeper uplooking@uplooking02:/home/uplooking/app scp -r app/zookeeper uplooking@uplooking03:/home/uplooking/app 在拷贝的过程中需要设置ssh免密码登录 在uplooking02和uplooking03上面生成ssh密钥 ssh-keygen -t rsa 将密钥拷贝授权文件中 uplooking02: ssh-keygen -t rsa ssh-copy-id -i uplooking@uplooking02 uplooking03: ssh-keygen -t rsa ssh-copy-id -i uplooking@uplooking03 uplooking01: ssh-copy-id -i uplooking@uplooking03 7、修改myid文件 [uplooking@uplooking02 ~]$ echo 102 > app/zookeeper/data/myid [uplooking@uplooking03 ~]$ echo 103 > app/zookeeper/data/myid 8、同步环境变量文件 [uplooking@uplooking01 ~]$ scp .bash_profile uplooking@uplooking02:/home/uplooking/ [uplooking@uplooking01 ~]$ scp .bash_profile uplooking@uplooking03:/home/uplooking/ 9、启动 在1、2、3分别执行zkServer.sh start
1、解压 [uplooking@uplooking01 ~]$ tar -zvxf soft/hadoop-2.6.4.tar.gz -C app/ 2、重命名 [uplooking@uplooking01 ~]$ mv app/hadoop-2.6.4/ app/hadoop 3、修改配置文件 hadoop-env.sh、yarn-env.sh、hdfs-site.xml、core-site.xml、mapred-site.xml、yarn-site.xml、slaves 1°、hadoop-env.sh export JAVA_HOME=/opt/jdk 2°、yarn-env.sh export JAVA_HOME=/opt/jdk 3°、slaves uplooking02 uplooking03 4°、hdfs-site.xml5°、core-site.xml dfs.nameservices ns1 dfs.ha.namenodes.ns1 nn1,nn2 dfs.namenode.rpc-address.ns1.nn1 uplooking01:9000 dfs.namenode.http-address.ns1.nn1 uplooking01:50070 dfs.namenode.rpc-address.ns1.nn2 uplooking02:9000 dfs.namenode.http-address.ns1.nn2 uplooking02:50070 dfs.namenode.shared.edits.dir qjournal://uplooking01:8485;uplooking02:8485;uplooking03:8485/ns1 dfs.journalnode.edits.dir /home/uplooking/data/hadoop/journal dfs.namenode.name.dir /home/uplooking/data/hadoop/name dfs.datanode.data.dir /home/uplooking/data/hadoop/data dfs.ha.automatic-failover.enabled true dfs.client.failover.proxy.provider.ns1 org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider dfs.ha.fencing.methods sshfence shell(/bin/true) dfs.ha.fencing.ssh.private-key-files /home/uplooking/.ssh/id_rsa dfs.ha.fencing.ssh.connect-timeout 30000 6°、mapred-site.xml fs.defaultFS hdfs://ns1 hadoop.tmp.dir /home/uplooking/data/hadoop/tmp ha.zookeeper.quorum uplooking01:2181,uplooking02:2181,uplooking03:2181 7°、yarn-site.xml mapreduce.framework.name yarn mapreduce.jobhistory.address uplooking02:10020 mapreduce.jobhistory.webapp.address uplooking02:19888 yarn.app.mapreduce.am.staging-dir /history mapreduce.map.log.level INFO mapreduce.reduce.log.level INFO 4、准备hadoop所需要的几个目录 [uplooking@uplooking01 hadoop]$ mkdir -p /home/uplooking/data/hadoop/journal [uplooking@uplooking01 hadoop]$ mkdir -p /home/uplooking/data/hadoop/name [uplooking@uplooking01 hadoop]$ mkdir -p /home/uplooking/data/hadoop/data [uplooking@uplooking01 hadoop]$ mkdir -p /home/uplooking/data/hadoop/tmp 5、同步到uplooking02和uplooking03 [uplooking@uplooking01 ~]$ scp -r data/hadoop uplooking@uplooking02:/home/uplooking/data/ [uplooking@uplooking01 ~]$ scp -r data/hadoop uplooking@uplooking03:/home/uplooking/data/ [uplooking@uplooking01 ~]$ scp -r app/hadoop uplooking@uplooking02:/home/uplooking/app/ [uplooking@uplooking01 ~]$ scp -r app/hadoop uplooking@uplooking03:/home/uplooking/app/ 6、格式化&启动 1°、启动zk 2°、启动jouralnode hadoop-deamon.sh start journalnode 3°、在uplooking01或者uplooking02中的一台机器上面格式化hdfs hdfs namenode -format 18/03/02 11:16:20 INFO common.Storage: Storage directory /home/uplooking/data/hadoop/name has been successfully formatted. 说明格式化成功 将格式化后的namenode的元数据信息拷贝到另外一台namenode之上就可以了 将uplooking01上面产生的namenode的元数据信息,拷贝到uplooking02上面, scp -r /home/uplooking/data/hadoop/name uplooking@uplooking02:/home/uplooking/data/hadoop/ 4°、格式化zkfc hdfs zkfc -formatZK 实际上是在zookeeper中创建一个目录节点/hadoop-ha/ns1 5°、启动hdfs 在uplooking01机器上面或者uplooking02上面启动、start-dfs.sh 6、启动yarn 在yarn配置的机器上面启动start-yarn.sh 在uplooking02上面启动start-yarn.sh 在uplooking03上面启动脚本 yarn-daemon.sh start resourcemanager(在3上没有resourcemanager进程,需要手动启动一下) (hadoop的bug,在u2上启动yarn后,2上是有resourcemanager进程的,但是3上是没有的,所以3上面是需要手动启动的) 7°、要启动hdfs中某一个节点,使用脚本hadoop-daemon.sh start 节点进程名( Note:在保证已经格式化hdfs和zkfc后,可以直接使用start-dfs.sh start来启动,这时会依次启动:namenode datanode journalnode zkfcStarting namenodes on [uplooking01 uplooking02]uplooking01: starting namenode, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-namenode-uplooking01.outuplooking02: starting namenode, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-namenode-uplooking02.outuplooking03: starting datanode, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-datanode-uplooking03.outuplooking02: starting datanode, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-datanode-uplooking02.outStarting journal nodes [uplooking01 uplooking02 uplooking03]uplooking03: starting journalnode, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-journalnode-uplooking03.outuplooking02: starting journalnode, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-journalnode-uplooking02.outuplooking01: starting journalnode, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-journalnode-uplooking01.out18/03/04 01:00:17 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicableStarting ZK Failover Controllers on NN hosts [uplooking01 uplooking02]uplooking02: starting zkfc, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-zkfc-uplooking02.outuplooking01: starting zkfc, logging to /home/uplooking/app/hadoop/logs/hadoop-uplooking-zkfc-uplooking01.out) 7、访问和验证 1°、访问 web hdfs http://uplooking01:50070 http://uplooking02:50070 其中一个是active,一个是standby yarn http://uplooking02:8088 http://uplooking03:8088 在浏览的时候standby会重定向跳转之active对应的页面 shell 我们是无法操作standby对应的hdfs的,只能操作active的namenode Operation category READ is not supported in state standby 2、ha的验证 NameNode HA 访问: uplooking01:50070 uplooking02:50070 其中一个active的状态,一个是StandBy的状态 当访问standby的namenode时候: Operation category READ is not supported in state standby 主备切换验证: 在uplooking01上kill -9 namenode的进程 这时访问uplooking02:50070发现变成了active的 然后在uplooking01上重新启动namenode,发现启动后状态变成standby的 Yarn HA web访问:默认端口是8088 uplooking02:8088 uplooking03:8088 This is standby RM. Redirecting to the current active RM: http://uplooking02:8088/ 主备切换验证: 在uplooking02上kill -9 resourcemanager的进程 这时可以访问uplooking03:8088 然后在uplooking02上重新启动resourcemanager,再访问时就是跳转到uplooking03:8088 主备切换结论: 原来的主再恢复时,为了系统的稳定性,不会再进行主备的切换。 3、简单操作 cd /home/uplooking/app/hadoop/share/hadoop/mapreduce [uplooking@uplooking01 mapreduce]$ yarn jar hadoop-mapreduce-examples-2.6.4.jar wordcount /hello /output/mr/wc yarn.resourcemanager.ha.enabled true yarn.resourcemanager.cluster-id yrc yarn.resourcemanager.ha.rm-ids rm1,rm2 yarn.resourcemanager.hostname.rm1 uplooking02 yarn.resourcemanager.hostname.rm2 uplooking03 yarn.resourcemanager.zk-address uplooking01:2181,uplooking02:2181,uplooking03:2181 yarn.nodemanager.aux-services mapreduce_shuffle
转载地址:http://vkema.baihongyu.com/