==== 准备工作 ==== * 搭建zookeeper。见[[zookeeper搭建]] * 搭建hdfs集群。见[[hadoop2.6集群搭建]] ==== 对配置文件做一些修改 ==== core-site.xml fs.defaultFS hdfs://mycluster //NameNode为集群名称 io.file.buffer.size 131072 ha.zookeeper.quorum master:2181,slave1:2181,slave2:2181 hdfs-site.xml dfs.namenode.name.dir file:///usr/local/hadoop-2.6.0/dfs/name //NameNode节点目录 ,需要提前创建,并可写权限,如果目录不存在,会忽略此配置 dfs.datanode.data.dir file:///usr/local/hadoop-2.6.0/dfs/data //DataNode节点目录 ,需要提前创建,并可写权限,如果目录不存在,会忽略此配置,如果有多个硬盘最好配置多个目录,增加读写速度 dfs.permissions false dfs.hosts.exclude /usr/local/hadoop-2.6.0/exclude dfs.nameservices mycluster Comma-separated list of nameservices. dfs.ha.namenodes.mycluster nn1,nn2 The prefix for a given nameservice, contains a comma-separated list of namenodes for a given nameservice (eg EXAMPLENAMESERVICE). dfs.namenode.rpc-address.mycluster.nn1 master:8020 RPC address for nomenode1 of mycluster dfs.namenode.rpc-address.mycluster.nn2 slave1:8020 RPC address for nomenode2 of mycluster dfs.namenode.http-address.mycluster.nn1 master:50070 The address and the base port where the dfs namenode1 web ui will listen on. dfs.namenode.http-address.mycluster.nn2 slave1:50070 The address and the base port where the dfs namenode2 web ui will listen on. dfs.namenode.shared.edits.dir qjournal://master:8485;slave1:8485;slave2:8485/mycluster A directory on shared storage between the multiple namenodes in an HA cluster. This directory will be written by the active and read by the standby in order to keep the namespaces synchronized. This directory does not need to be listed in dfs.namenode.edits.dir above. It should be left empty in a non-HA cluster. dfs.ha.automatic-failover.enabled true Whether automatic failover is enabled. See the HDFS High Availability documentation for details on automatic HA configuration. dfs.journalnode.edits.dir /usr/local/hadoop-2.6.0/dfs/journal/ dfs.ha.fencing.methods sshfence(hadoop) 在failover期间用来隔离Active Namenode的脚本或者java 类列表。 虽然JNS可以确保集群中只有一个Active Node写入edits,这对保护edits一致性很重要,但是在failover期间,有可能Acitive Node仍然存活,Client可能还与其保持连接提供旧的数据服务,我们可以通过此配置,指定shell脚本或者java程序,SSH到Active NameNode然后Kill Namenode进程。它有两种可选值(具体参见官方文档): 1) sshfence:SSH登录到Active Namenode,并Kill此进程。首先当前机器能够使用SSH登录到远端,前提是已经授权(rsa)。 2) shell:运行shell指令隔离Active Namenode。 dfs.ha.fencing.ssh.private-key-files /home/hadoop/.ssh/id_rsa dfs.client.failover.proxy.provider.mycluster org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider yarn-site.xml yarn.nodemanager.aux-services mapreduce_shuffle yarn.resourcemanager.hostname master mapred-site.xml mapreduce.framework.name yarn //mapreduce的frmawork指定为yarn Execution framework set to Hadoop YARN. mapreduce.task.io.sort.mb 2000 //mapreduce的frmawork指定为yarn Execution framework set to Hadoop YARN. 更多配置,配置含义参见[[http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.3.2/bk_hadoop-ha/content/ha-nn-config-cluster.html|hadoop HA]] ==== 启动 ==== - 首先把各个zookeeper起来 - ./bin/zkServer.sh start (每台机器) - 然后在某一个namenode节点执行如下命令,创建命名空间 - ./bin/hdfs zkfc -formatZK (主namenode) - 在每个节点用如下命令启日志程序 - ./sbin/hadoop-daemon.sh start journalnode (每台机器) - 在主namenode节点用./bin/hadoopnamenode -format格式化namenode和journalnode目录 - ./bin/hadoop namenode -format mycluster (主namenode) - 在主namenode节点启动./sbin/hadoop-daemon.shstart namenode进程 - ./sbin/hadoop-daemon.sh start namenode (主namenode) - 在备节点执行第一行命令,这个是把备namenode节点的目录格式化并把元数据从主namenode节点copy过来,并且这个命令不会把journalnode目录再格式化了!然后用第二个命令启动备namenode进程! - ./bin/hdfs namenode –bootstrapStandby (备namenode) - ./sbin/hadoop-daemon.sh start namenode (备namenode) - 在两个namenode节点都执行以下命令 - ./sbin/hadoop-daemon.sh start zkfc (所有namenode) - 7、在所有datanode节点都执行以下命令启动datanode - ./sbin/hadoop-daemon.sh start datanode (所有datanode) **下次启动的时候,就直接执行以下命令就可以全部启动所有进程和服务了** - 启动zookeeper - ./sbin/start-dfs.sh ==== 测试HDFS的HA功能 ==== 在任意一台namenode机器上通过jps命令查找到namenode的进程号,然后通过kill -9的方式杀掉进程,观察另一个namenode节点是否会从状态standby变成active状态 jps 查看namenode的pid kill -9 xxx 然后查看: http://master:50070/ http://slave1:50070/