1、集群规划
| ZooKeeper | NameNode | DataNode | ResourceManager | NodeManage | JN | ZKFC |
---|
master | 1 | 1 | | 1 | | 1 | 1 | node1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | node2 | 1 | | 1 | | 1 | 1 | |
2、前提
1、Zookeeper 集群安装完毕 2、jdk 安装完成等等
3、免密配置
注意:两台NameNode机器 (master、node1)都需要配置免密登录
4、修改hadoop配置文件
4.1、hdfs高可用
1、修改core-site.xml 添加如下配置文件
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://cluster</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/soft/hadoop-2.7.6/tmp</value>
</property>
<property>
<name>fs.trash.interval</name>
<value>1440</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>master:2181,node1:2181,node2:2181</value>
</property>
</configuration>
2、修改hdfs-site.xml文件,添加如下内容
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/usr/local/soft/hadoop-2.7.6/data/namenode</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/usr/local/soft/hadoop-2.7.6/data/datanode</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
<property>
<name>dfs.nameservices</name>
<value>cluster</value>
</property>
<property>
<name>dfs.ha.namenodes.cluster</name>
<value>nn1,nn2</value>
</property>
<property>
<name>dfs.namenode.rpc-address.cluster.nn1</name>
<value>master:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.cluster.nn2</name>
<value>node1:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.cluster.nn1</name>
<value>master:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.cluster.nn2</name>
<value>node1:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://master:8485;node1:8485;node2:8485/cluster</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/usr/local/soft/hadoop-2.7.6/data/journal</value>
</property>
<property>
<name>dfs.client.failover.proxy.provider.cluster</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>
</configuration>
3、将修改后的文件同步到另外两台机器
注意:此时只是core-site.xml与hdfs-site.xml两个配置文件与单namenode的hadoop集群不同,其它配置文件和单节点的相同,已经省略!!!
scp -r /usr/local/soft/hadoop-2.7.6/etc/hadoop/ node1:/usr/local/soft/hadoop-2.7.6/etc/
4、删除之前hadoop的存储文件
rm -rf /usr/local/soft/hadoop-2.7.6/tmp 启动Zookeeper集群,三台机器都要启动 zkServer.sh start
5、启动JN 存储hdfs元数据
三台三台机器 都要执行命令 hadoop-daemon.sh start journalnode jps 查看进程
6、格式化namenode
在一台namenode上面执行,master与node1上都可以,本文选择在master上面执行 hdfs namenode -format 启动当前的namenode hadoop-daemon.sh start namenode
7、执行同步
在没有格式化的namenode 上执行,本文没格式化的namenode 是node1 在node1 上执行 hdfs namenode -bootstrapStandby
8、格式化ZK
在已经启动的namenode 上面执行(master) !!一定要先 把zk集群正常 启动起来 hdfs zkfc -formatZK
9、启动hdfs集群
在启动了namenode 的节点上执行(master ) start-dfs.sh 查看master与node1上的进程
至此,hdfs高可用搭建完成,有两个namenode,一个在master上,另一个在node1上
4.2、yarn高可用
1、修改yarn-site.xml文件,并添加如下内容
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.web-proxy.address</name>
<value>master:8888</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>
<property>
<name>yarn.nodemanager.remote-app-log-dir</name>
<value>/logs</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>2048</value>
</property>
<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>2</value>
</property>
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yarncluster</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>master</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>node1</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm1</name>
<value>master:8088</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm2</name>
<value>node1:8088</value>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>master:2181,node1:2181,node2:2181</value>
</property>
<property>
<name>yarn.resourcemanager.zk-state-store.parent-path</name>
<value>/rmstore</value>
</property>
<property>
<name>yarn.resourcemanager.recovery.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.store.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
</property>
<property>
<name>yarn.nodemanager.recovery.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.nodemanager.address</name>
<value>0.0.0.0:45454</value>
</property>
</configuration>
2、mapred-site.xml文件,并添加如下内容
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>node1:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>node1:19888</value>
</property>
<property>
<name>mapreduce.job.ubertask.enable</name>
<value>true</value>
</property>
<property>
<name>mapreduce.job.ubertask.maxmaps</name>
<value>9</value>
</property>
<property>
<name>mapreduce.job.ubertask.maxreduces</name>
<value>1</value>
</property>
</configuration>
将修改的yarn-site.xml与mapred-site.xml同步到另外两台机器上
scp -r /usr/local/soft/hadoop-2.7.6/etc/hadoop/ node1:/usr/local/soft/hadoop-2.7.6/etc/
3、启动yarn
在master 启动start-yarn.sh
4、在另外一台主节点上启动RM(node1)
yarn-daemon.sh start resourcemanager
至此查看所有进程 jps,与我们集群规划的所有进程一致,Hadoop的HA高可用安装完毕
5、测试高可用
1、在浏览器查看
输入master 与node1 地址, 看到master 处于active 状态 node1 处于standby 状态
2、手动杀死master中的namenode进程
kill -9 2718
3、再次访问wed界面
发现node1 已经处于active 状态了
4、重新启动master上的namenode
hadoop-daemon.sh start namenode 查看master 状态 发现其已经变成standby 状态了
|