高可用分布式
大数据处理技术 - apache hadoop 三种架构介绍 (高可用分布式环境介绍以及安装) 高可用分布式环境搭建(适用于工作当中正式环境搭建)
实现 namenode 高可用,ResourceManager 的高可用
集群运行服务规划 服务器 IP 192.168.52.100 192.168.52.110 192.168.52.120 zookeeper zk zk zk HDFS JournalNode JournalNode JournalNode NameNode NameNode ZKFC ZKFC DataNode DataNode DataNode YARN ResourceManager ResourceManager NodeManager NodeManager NodeManager MapReduce JobHistoryServer
安装包解压 停止之前的 hadoop 集群的所有服务,并删除所有机器的 hadoop 安装包, 第一台机器执行以下命令
cd /export/servers/hadoop-2.7.5sbin/stop-dfs.sh sbin/stop-yarn.sh sbin/mr-jobhistory-daemon.sh stop historyserver
cd /export/servers/rm -rf hadoop-2.7.5/
然后重新解压 hadoop 压缩包 解压压缩包 第一台机器执行以下命令进行解压
cd /export/softwarestar -zxvf hadoop-2.7.5.tar.gz -C ../servers/
配置文件的修改 修改 core-site.xml 第一台机器执行以下命令
cd /export/servers/hadoop-2.7.5/etc/hadoopvim core-site.xml
core-site.xml <configuration > <property > <name > ha.zookeeper.quorum</name > <value > node01:2181,node02:2181,node03:2181</value > </property > <property > <name > fs.defaultFS</name > <value > hdfs://ns</value > </property > <property > <name > hadoop.tmp.dir</name > <value > /export/servers/hadoop-2.7.5/data/tmp</value > </property > <property > <name > fs.trash.interval</name > <value > 10080</value > </property > </configuration >
修改 hdfs-site.xml 第一台机器执行以下命令
cd /export/servers/hadoop-2.7.5/etc/hadoopvim hdfs-site.xml
hdfs-site.xml <configuration > <property > <name > dfs.nameservices</name > <value > ns</value > </property > <property > <name > dfs.ha.namenodes.ns</name > <value > nn1,nn2</value > </property > <property > <name > dfs.namenode.rpc-address.ns.nn1</name > <value > node01:8020</value > </property > <property > <name > dfs.namenode.rpc-address.ns.nn2</name > <value > node02:8020</value > </property > <property > <name > dfs.namenode.servicerpc-address.ns.nn1</name > <value > node01:8022</value > </property > <property > <name > dfs.namenode.servicerpc-address.ns.nn2</name > <value > node02:8022</value > </property > <property > <name > dfs.namenode.http-address.ns.nn1</name > <value > node01:50070</value > </property > <property > <name > dfs.namenode.http-address.ns.nn2</name > <value > node02:50070</value > </property > <property > <name > dfs.namenode.shared.edits.dir</name > <value > qjournal://node01:8485;node02:8485;node03:8485/ns1</value > </property > <property > <name > dfs.client.failover.proxy.provider.ns</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.journalnode.edits.dir</name > <value > /export/servers/hadoop-2.7.5/data/dfs/jn</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.7.5/data/dfs/nn/name</value > </property > <property > <name > dfs.namenode.edits.dir</name > <value > file:///export/servers/hadoop-2.7.5/data/dfs/nn/edits</value > </property > <property > <name > dfs.datanode.data.dir</name > <value > file:///export/servers/hadoop-2.7.5/data/dfs/dn</value > </property > <property > <name > dfs.permissions</name > <value > false</value > </property > <property > <name > dfs.blocksize</name > <value > 134217728</value > </property > </configuration >
修改 yarn-site.xml 注意 node03 与 node02 配置不同
第一台机器执行以下命令
cd /export/servers/hadoop-2.7.5/etc/hadoopvim yarn-site.xml
yarn-site.xml <configuration > <property > <name > yarn.log-aggregation-enable</name > <value > true</value > </property > <property > <name > yarn.resourcemanager.ha.enabled</name > <value > true</value > </property > <property > <name > yarn.resourcemanager.cluster-id</name > <value > mycluster</value > </property > <property > <name > yarn.resourcemanager.ha.rm-ids</name > <value > rm1,rm2</value > </property > <property > <name > yarn.resourcemanager.hostname.rm1</name > <value > node03</value > </property > <property > <name > yarn.resourcemanager.hostname.rm2</name > <value > node02</value > </property > <property > <name > yarn.resourcemanager.address.rm1</name > <value > node03:8032</value > </property > <property > <name > yarn.resourcemanager.scheduler.address.rm1</name > <value > node03:8030</value > </property > <property > <name > yarn.resourcemanager.resourcetracker.address.rm1</name > <value > node03:8031</value > </property > <property > <name > yarn.resourcemanager.admin.address.rm1</name > <value > node03:8033</value > </property > <property > <name > yarn.resourcemanager.webapp.address.rm1</name > <value > node03:8088</value > </property > <property > <name > yarn.resourcemanager.address.rm2</name > <value > node02:8032</value > </property > <property > <name > yarn.resourcemanager.scheduler.address.rm2</name > <value > node02:8030</value > </property > <property > <name > yarn.resourcemanager.resourcetracker.address.rm2</name > <value > node02:8031</value > </property > <property > <name > yarn.resourcemanager.admin.address.rm2</name > <value > node02:8033</value > </property > <property > <name > yarn.resourcemanager.webapp.address.rm2</name > <value > node02:8088</value > </property > <property > <name > yarn.resourcemanager.recovery.enabled</name > <value > true</value > </property > <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:2181,node02:2181,node03:2181</value > <description > For multiple zk services, separate them with comma</description > </property > <property > <name > yarn.resourcemanager.ha.automaticfailover.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 > <property > <name > yarn.nodemanager.resource.cpu-vcores</name > <value > 4</value > </property > <property > <name > yarn.nodemanager.resource.memory-mb</name > <value > 512</value > </property > <property > <name > yarn.scheduler.minimum-allocation-mb</name > <value > 512</value > </property > <property > <name > yarn.scheduler.maximum-allocation-mb</name > <value > 512</value > </property > <property > <name > yarn.log-aggregation.retain-seconds</name > <value > 2592000</value > </property > <property > <name > yarn.nodemanager.log.retain-seconds</name > <value > 604800</value > </property > <property > <name > yarn.nodemanager.log-aggregation.compressiontype</name > <value > gz</value > </property > <property > <name > yarn.nodemanager.local-dirs</name > <value > /export/servers/hadoop-2.7.5/yarn/local</value > </property > <property > <name > yarn.resourcemanager.max-completed-applications</name > <value > 1000</value > </property > <property > <name > yarn.nodemanager.aux-services</name > <value > mapreduce_shuffle</value > </property > <property > <name > yarn.resourcemanager.connect.retry-interval.ms</name > <value > 2000</value > </property > </configuration >
修改 mapred-site.xml cd /export/servers/hadoop-2.7.5/etc/hadoopvim mapred-site.xml
mapred-site.xml <configuration > <property > <name > mapreduce.framework.name</name > <value > yarn</value > </property > <property > <name > mapreduce.jobhistory.address</name > <value > node03:10020</value > </property > <property > <name > mapreduce.jobhistory.webapp.address</name > <value > node03:19888</value > </property > <property > <name > mapreduce.jobtracker.system.dir</name > <value > /export/servers/hadoop2.7.5/data/system/jobtracker</value > </property > <property > <name > mapreduce.map.memory.mb</name > <value > 1024</value > </property > <property > <name > mapreduce.reduce.memory.mb</name > <value > 1024</value > </property > <property > <name > mapreduce.task.io.sort.mb</name > <value > 100</value > </property > <property > <name > mapreduce.task.io.sort.factor</name > <value > 10</value > </property > <property > <name > mapreduce.reduce.shuffle.parallelcopies</name > <value > 25</value > </property > <property > <name > yarn.app.mapreduce.am.command-opts</name > <value > -Xmx1024m</value > </property > <property > <name > yarn.app.mapreduce.am.resource.mb</name > <value > 1536</value > </property > <property > <name > mapreduce.cluster.local.dir</name > <value > /export/servers/hadoop-2.7.5/data/system/local</value > </property > </configuration >
修改 slaves 第一台机器执行以下命令
cd /export/servers/hadoop-2.7.5/etc/hadoopvim slaves
slaves 修改 hadoop-env.sh 第一台机器执行以下命令
cd /export/servers/hadoop-2.7.5/etc/hadoopvim hadoop-env.sh
hadoop-env.sh export JAVA_HOME=/export/servers/jdk1.8.0_141
集群启动过程 将第一台机器的安装包发送到其他机器上 第一台机器执行以下命令
cd /export/serversscp -r hadoop-2.7.5/ node02:$PWD scp -r hadoop-2.7.5/ node03:$PWD
三台机器上共同创建目录 三台机器执行以下命令
mkdir -p /export/servers/hadoop-2.7.5/data/dfs/nn/namemkdir -p /export/servers/hadoop-2.7.5/data/dfs/nn/editsmkdir -p /export/servers/hadoop-2.7.5/data/dfs/nn/namemkdir -p /export/servers/hadoop-2.7.5/data/dfs/nn/edits
更改 node02 的 rm2 第二台机器执行以下命令
cd /export/servers/hadoop-2.7.5/etc/hadoopvim yarn-site.xml
yarn-site.xml <property > <name > yarn.resourcemanager.ha.id</name > <value > rm2</value > <description > If we want to launch more than one RM in single node, we need this configuration</description > </property >
启动 HDFS 过程 node01 机器执行以下命令
cd /export/servers/hadoop-2.7.5bin/hdfs zkfc -formatZK sbin/hadoop-daemons.sh start journalnode bin/hdfs namenode -format bin/hdfs namenode -initializeSharedEdits -force sbin/start-dfs.sh
node02 上面执行
cd /export/servers/hadoop-2.7.5bin/hdfs namenode -bootstrapStandby sbin/hadoop-daemon.sh start namenode
启动 yarn 过程 node03 上面执行
cd /export/servers/hadoop-2.7.5sbin/start-yarn.sh
node02 上执行
cd /export/servers/hadoop-2.7.5sbin/start-yarn.sh
查看 resourceManager 状态 node03 上面执行
cd /export/servers/hadoop-2.7.5bin/yarn rmadmin -getServiceState rm1
node02 上面执行
cd /export/servers/hadoop-2.7.5bin/yarn rmadmin -getServiceState rm2
启动 jobHistory node03 机器执行以下命令启动 jobHistory
cd /export/servers/hadoop-2.7.5sbin/mr-jobhistory-daemon.sh start historyserver