【Hadoop离线基础总结】Hadoop High Availability\Hadoop基础环境增强
简单介绍
-
Hadoop HA 概述
HA(High Available) —— 高可用,是保证业务连续性的有效解决方案。一般有两个或两个以上的节点,分为活动节点(Active)及备用节点(Standby)。通常把正在执行业务的称为活动节点,而作为活动节点的一个备份的则称为备用节点。当活动节点出现问题,导致正在运行的业务(任务)不能正常运行时,备用节点此时就会侦测到,并立即接续活动节点来执行业务。从而实现业务的不中断或短暂中断。
Hadoop1.X版本,NN是HDFS集群的单点故障点,每一个集群只有一个NN,如果这个机器或进程不可用,整个集群就无法使用。为了解决这个问题,出现了一堆针对HDFS HA的解决方案(如:Linux HA, VMware FT, shared NAS+NFS, BookKeeper, QJM/Quorum Journal Manager, BackupNode等)。
在HA具体实现方法不同情况下,HA框架的流程是一致的, 不一致的就是如何存储、管理、同步edits编辑日志文件。
在Active NN和Standby NN之间要有个共享的存储日志的地方,Active NN把edit Log写到这个共享的存储日志的地方,Standby NN去读取日志然后执行,这样Active和Standby NN内存中的HDFS元数据保持着同步。一旦发生主从切换Standby NN可以尽快接管Active NN的工作。 -
集群搭建规划
集群搭建
-
第一步:停止服务
要停止hadoop集群的所有服务,包括HDFS、yarn、impala、hive、oozie、hue等
# 停止oozie cd /export/servers/oozie-4.1.0-cdh5.14.0 bin/oozied.sh stop
hue impala hive在进程中杀死即可
cd /export/servers/hadoop-2.6.0-cdh5.14.0 sbin/stop-dfs.sh sbin/stop-yarn.sh sbin/mr-jobhistory-daemon.sh stop historyserver
-
第二步:启动所有节点的ZooKeeper
cd /export/servers/zookeeper-3.4.5-cdh5.14.0 bin/zkServer.sh start
-
第三步:更改配置文件
core-site.xml
<!-- <property> <name>fs.default.name</name> <value>hdfs://192.168.52.100:8020</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/tempDatas</value> </property> <property> <name>io.file.buffer.size</name> <value>4096</value> </property> <property> <name>fs.trash.interval</name> <value>10080</value> </property> --> <property> <name>ha.zookeeper.quorum</name> <value>node01.hadoop.com:2181,node02.hadoop.com:2181,node03.hadoop.com:2181</value> </property> <property> <name>fs.defaultFS</name> <value>hdfs://hann</value> </property> <!-- 缓冲区大小,实际工作中根据服务器性能动态调整 --> <property> <name>io.file.buffer.size</name> <value>4096</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/tempDatas</value> </property> <property> <name>fs.trash.interval</name> <value>10080</value> </property> <property> <name>hadoop.proxyuser.root.hosts</name> <value>*</value> </property> <property> <name>hadoop.proxyuser.root.groups</name> <value>*</value> </property>
hdfs-site.xml
<!-- NameNode存储元数据信息的路径,实际工作中,一般先确定磁盘的挂载目录,然后多个目录用,进行分割 --> <!-- 集群动态上下线 <property> <name>dfs.hosts</name> <value>/export/servers/hadoop-2.7.4/etc/hadoop/accept_host</value> </property> <property> <name>dfs.hosts.exclude</name> <value>/export/servers/hadoop-2.7.4/etc/hadoop/deny_host</value> </property> --> <!-- <property> <name>dfs.namenode.secondary.http-address</name> <value>node01:50090</value> </property> <property> <name>dfs.namenode.http-address</name> <value>node01:50070</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:///export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/namenodeDatas</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:///export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/datanodeDatas</value> </property> <property> <name>dfs.namenode.edits.dir</name> <value>file:///export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/dfs/nn/edits</value> </property> <property> <name>dfs.namenode.checkpoint.dir</name> <value>file:///export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/dfs/snn/name</value> </property> <property> <name>dfs.namenode.checkpoint.edits.dir</name> <value>file:///export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/dfs/nn/snn/edits</value> </property> <property> <name>dfs.replication</name> <value>1</value> </property> <property> <name>dfs.permissions</name> <value>false</value> </property> <property> <name>dfs.blocksize</name> <value>134217728</value> </property> <property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property> <property> <name>dfs.client.read.shortcircuit</name> <value>true</value> </property> <property> <name>dfs.domain.socket.path</name> <value>/var/run/hdfs-sockets/dn</value> </property> <property> <name>dfs.client.file-block-storage-locations.timeout.millis</name> <value>10000</value> </property> <property> <name>dfs.datanode.hdfs-blocks-metadata.enabled</name> <value>true</value> </property> <property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property> --> <property> <name>dfs.nameservices</name> <value>hann</value> </property> <property> <name>dfs.ha.namenodes.hann</name> <value>nn1,nn2</value> </property> <property> <name>dfs.namenode.rpc-address.hann.nn1</name> <value>node01.hadoop.com:8020</value> </property> <property> <name>dfs.namenode.rpc-address.hann.nn2</name> <value>node02.hadoop.com:8020</value> </property> <property> <name>dfs.namenode.servicerpc-address.hann.nn1</name> <value>node01.hadoop.com:8022</value> </property> <property> <name>dfs.namenode.servicerpc-address.hann.nn2</name> <value>node02.hadoop.com:8022</value> </property> <property> <name>dfs.namenode.http-address.hann.nn1</name> <value>node01.hadoop.com:50070</value> </property> <property> <name>dfs.namenode.http-address.hann.nn2</name> <value>node02.hadoop.com:50070</value> </property> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://node01.hadoop.com:8485;node02.hadoop.com:8485;node03.hadoop.com:8485/hann</value> </property> <property> <name>dfs.journalnode.edits.dir</name> <value>/export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/dfs/jn</value> </property> <property> <name>dfs.client.failover.proxy.provider.hann</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> <property> <name>dfs.ha.fencing.methods</name> <value>sshfence</value> </property> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/root/.ssh/id_rsa</value> </property> <property> <name>dfs.ha.automatic-failover.enabled</name> <value>true</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:///export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/namenodeDatas</value> </property> <property> <name>dfs.namenode.edits.dir</name> <value>file:///export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/dfs/nn/edits</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:///export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/datanodeDatas</value> </property> <property> <name>dfs.replication</name> <value>3</value> </property> <property> <name>dfs.permissions</name> <value>false</value> </property> <property> <name>dfs.blocksize</name> <value>134217728</value> </property> <property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property> <property> <name>dfs.client.read.shortcircuit</name> <value>true</value> </property> <property> <name>dfs.domain.socket.path</name> <value>/var/run/hdfs-sockets/dn</value> </property> <property> <name>dfs.client.file-block-storage-locations.timeout.millis</name> <value>10000</value> </property> <property> <name>dfs.datanode.hdfs-blocks-metadata.enabled</name> <value>true</value> </property> <property> <name>dfs.webhdfs.enabled</name> <value>true</value> </property>
mapred-site.xml
<!-- <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> <property> <name>mapreduce.job.ubertask.enable</name> <value>true</value> </property> <property> <name>mapreduce.jobhistory.address</name> <value>node01:10020</value> </property> <property> <name>mapreduce.jobhistory.webapp.address</name> <value>node01:19888</value> </property> --> <!-- <property> <name>mapreduce.map.output.compress</name> <value>true</value> </property> <property> <name>mapreduce.map.output.compress.codec</name> <value>org.apache.hadoop.io.compress.SnappyCodec</value> </property> <property> <name>mapreduce.output.fileoutputformat.compress</name> <value>true</value> </property> <property> <name>mapreduce.output.fileoutputformat.compress.type</name> <value>RECORD</value> </property> <property> <name>mapreduce.output.fileoutputformat.compress.codec</name> <value>org.apache.hadoop.io.compress.SnappyCodec</value> </property> --> <!--指定运行mapreduce的环境是yarn --> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> <!-- MapReduce JobHistory Server IPC host:port --> <property> <name>mapreduce.jobhistory.address</name> <value>node03:10020</value> </property> <!-- MapReduce JobHistory Server Web UI host:port --> <property> <name>mapreduce.jobhistory.webapp.address</name> <value>node03:19888</value> </property> <!-- The directory where MapReduce stores control files.默认 ${hadoop.tmp.dir}/mapred/system --> <property> <name>mapreduce.jobtracker.system.dir</name> <value>/export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/jobtracker</value> </property> <!-- The amount of memory to request from the scheduler for each map task. 默认 1024--> <property> <name>mapreduce.map.memory.mb</name> <value>1024</value> </property> <!-- <property> <name>mapreduce.map.java.opts</name> <value>-Xmx1024m</value> </property> --> <!-- The amount of memory to request from the scheduler for each reduce task. 默认 1024--> <property> <name>mapreduce.reduce.memory.mb</name> <value>1024</value> </property> <!-- <property> <name>mapreduce.reduce.java.opts</name> <value>-Xmx2048m</value> </property> --> <!-- 用于存储文件的缓存内存的总数量,以兆字节为单位。默认情况下,分配给每个合并流1MB,给个合并流应该寻求最小化。默认值100--> <property> <name>mapreduce.task.io.sort.mb</name> <value>100</value> </property> <!-- <property> <name>mapreduce.jobtracker.handler.count</name> <value>25</value> </property>--> <!-- 整理文件时用于合并的流的数量。这决定了打开的文件句柄的数量。默认值10--> <property> <name>mapreduce.task.io.sort.factor</name> <value>10</value> </property> <!-- 默认的并行传输量由reduce在copy(shuffle)阶段。默认值5--> <property> <name>mapreduce.reduce.shuffle.parallelcopies</name> <value>25</value> </property> <property> <name>yarn.app.mapreduce.am.command-opts</name> <value>-Xmx1024m</value> </property> <!-- MR AppMaster所需的内存总量。默认值1536--> <property> <name>yarn.app.mapreduce.am.resource.mb</name> <value>1536</value> </property> <!-- MapReduce存储中间数据文件的本地目录。目录不存在则被忽略。默认值${hadoop.tmp.dir}/mapred/local--> <property> <name>mapreduce.cluster.local.dir</name> <value>/export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/mapreduce/local</value> </property>
yarn-site.xml
<!-- <property> <name>yarn.resourcemanager.hostname</name> <value>node01</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.log-aggregation-enable</name> <value>true</value> </property> <property> <name>yarn.log-aggregation.retain-seconds</name> <value>604800</value> </property> --> <!-- Site specific YARN configuration properties --> <!-- 是否启用日志聚合.应用程序完成后,日志汇总收集每个容器的日志,这些日志移动到文件系统,例如HDFS. --> <!-- 用户可以通过配置"yarn.nodemanager.remote-app-log-dir"、"yarn.nodemanager.remote-app-log-dir-suffix"来确定日志移动到的位置 --> <!-- 用户可以通过应用程序时间服务器访问日志 --> <!-- 启用日志聚合功能,应用程序完成后,收集各个节点的日志到一起便于查看 --> <property> <name>yarn.log-aggregation-enable</name> <value>true</value> </property> <!--开启resource manager HA,默认为false--> <property> <name>yarn.resourcemanager.ha.enabled</name> <value>true</value> </property> <!-- 集群的Id,使用该值确保RM不会做为其它集群的active --> <property> <name>yarn.resourcemanager.cluster-id</name> <value>mycluster</value> </property> <!--配置resource manager 命名--> <property> <name>yarn.resourcemanager.ha.rm-ids</name> <value>rm1,rm2</value> </property> <!-- 配置第一台机器的resourceManager --> <property> <name>yarn.resourcemanager.hostname.rm1</name> <value>node03.hadoop.com</value> </property> <!-- 配置第二台机器的resourceManager --> <property> <name>yarn.resourcemanager.hostname.rm2</name> <value>node02.hadoop.com</value> </property> <!-- 配置第一台机器的resourceManager通信地址 --> <property> <name>yarn.resourcemanager.address.rm1</name> <value>node03.hadoop.com:8032</value> </property> <property> <name>yarn.resourcemanager.scheduler.address.rm1</name> <value>node03.hadoop.com:8030</value> </property> <property> <name>yarn.resourcemanager.resource-tracker.address.rm1</name> <value>node03.hadoop.com:8031</value> </property> <property> <name>yarn.resourcemanager.admin.address.rm1</name> <value>node03.hadoop.com:8033</value> </property> <property> <name>yarn.resourcemanager.webapp.address.rm1</name> <value>node03.hadoop.com:8088</value> </property> <!-- 配置第二台机器的resourceManager通信地址 --> <property> <name>yarn.resourcemanager.address.rm2</name> <value>node02.hadoop.com:8032</value> </property> <property> <name>yarn.resourcemanager.scheduler.address.rm2</name> <value>node02.hadoop.com:8030</value> </property> <property> <name>yarn.resourcemanager.resource-tracker.address.rm2</name> <value>node02.hadoop.com:8031</value> </property> <property> <name>yarn.resourcemanager.admin.address.rm2</name> <value>node02.hadoop.com:8033</value> </property> <property> <name>yarn.resourcemanager.webapp.address.rm2</name> <value>node02.hadoop.com:8088</value> </property> <!--开启resourcemanager自动恢复功能--> <property> <name>yarn.resourcemanager.recovery.enabled</name> <value>true</value> </property> <!--在node3上配置rm1,在node2上配置rm2,注意:一般都喜欢把配置好的文件远程复制到其它机器上,但这个在YARN的另一个机器上一定要修改,其他机器上不配置此项--> <property> <name>yarn.resourcemanager.ha.id</name> <value>rm1</value> <description>If we want to launch more than one RM in single node, we need this configuration</description> </property> <!--用于持久存储的类。尝试开启--> <property> <name>yarn.resourcemanager.store.class</name> <value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value> </property> <property> <name>yarn.resourcemanager.zk-address</name> <value>node01.hadoop.com:2181,node02.hadoop.com:2181,node03.hadoop.com:2181</value> <description>For multiple zk services, separate them with comma</description> </property> <!--开启resourcemanager故障自动切换,指定机器--> <property> <name>yarn.resourcemanager.ha.automatic-failover.enabled</name> <value>true</value> <description>Enable automatic failover; By default, it is enabled only when HA is enabled.</description> </property> <property> <name>yarn.client.failover-proxy-provider</name> <value>org.apache.hadoop.yarn.client.ConfiguredRMFailoverProxyProvider</value> </property> <!-- 允许分配给一个任务最大的CPU核数,默认是8 --> <property> <name>yarn.nodemanager.resource.cpu-vcores</name> <value>4</value> </property> <!-- 每个节点可用内存,单位MB --> <property> <name>yarn.nodemanager.resource.memory-mb</name> <value>512</value> </property> <!-- 单个任务可申请最少内存,默认1024MB --> <property> <name>yarn.scheduler.minimum-allocation-mb</name> <value>512</value> </property> <!-- 单个任务可申请最大内存,默认8192MB --> <property> <name>yarn.scheduler.maximum-allocation-mb</name> <value>512</value> </property> <!--多长时间聚合删除一次日志 此处--> <property> <name>yarn.log-aggregation.retain-seconds</name> <value>2592000</value><!--30 day--> </property> <!--时间在几秒钟内保留用户日志。只适用于如果日志聚合是禁用的--> <property> <name>yarn.nodemanager.log.retain-seconds</name> <value>604800</value><!--7 day--> </property> <!--指定文件压缩类型用于压缩汇总日志--> <property> <name>yarn.nodemanager.log-aggregation.compression-type</name> <value>gz</value> </property> <!-- nodemanager本地文件存储目录--> <property> <name>yarn.nodemanager.local-dirs</name> <value>/export/servers/hadoop-2.6.0-cdh5.14.0/hadoopDatas/yarn/local</value> </property> <!-- resourceManager 保存最大的任务完成个数 --> <property> <name>yarn.resourcemanager.max-completed-applications</name> <value>1000</value> </property> <!-- 逗号隔开的服务列表,列表名称应该只包含a-zA-Z0-9_,不能以数字开始--> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <!--rm失联后重新链接的时间--> <property> <name>yarn.resourcemanager.connect.retry-interval.ms</name> <value>2000</value> </property>
把这四个发送到node02,node03,node02的yarn-site.xml要把yarn.resourcemanager.ha.id的值修改为rm2
scp core-site.xml hdfs-site.xml mapred-site.xml yarn-site.xml node02:$PWD scp core-site.xml hdfs-site.xml mapred-site.xml yarn-site.xml node03:$PWD
-
第四步:启动服务
1.在node01初始化zookeeper
cd /export/servers/hadoop-2.6.0-cdh5.14.0 bin/hdfs zkfc -formatZK
2.启动journalNode,三台机器都要执行
cd /export/servers/hadoop-2.6.0-cdh5.14.0 sbin/hadoop-daemon.sh start journalnode
3.初始化journalNode在node01执行即可
cd /export/servers/hadoop-2.6.0-cdh5.14.0 bin/hdfs namenode -initializeSharedEdits -force
4.在node01启动NameNode
cd /export/servers/hadoop-2.6.0-cdh5.14.0 sbin/hadoop-daemon.sh start namenode
5.在node02启动Namenode
cd /export/servers/hadoop-2.6.0-cdh5.14.0 bin/hdfs namenode -bootstrapStandby sbin/hadoop-daemon.sh start namenode
6.在node01启动所有节点的datanode
cd /export/servers/hadoop-2.6.0-cdh5.14.0 sbin/hadoop-daemons.sh start datanode
7.在node01和node02启动zkfc
cd /export/servers/hadoop-2.6.0-cdh5.14.0 sbin/hadoop-daemon.sh start zkfc
8.在node02和node03启动yarn
cd /export/servers/hadoop-2.6.0-cdh5.14.0 sbin/start-yarn.sh
8.在node03启动jobhistoryserver
cd /export/servers/hadoop-2.6.0-cdh5.14.0 sbin/mr-jobhistory-daemon.sh start historyserver