1. 程式人生 > >Hadoop安裝之高可用搭建

Hadoop安裝之高可用搭建

通過前面兩篇文章的搭建,可以發現搭建的NameNode只有一臺,沒有進行備份機,如果NameNode宕機了,那整個叢集也就廢了,所以我們需要在另外的機器上再搭建一個NameNode節點,且使用JournalNode來保證兩臺NameNode中的元資料保持一致,並且還需要通過zookeeper的zkFailoverController守護程序來監控NameNode的健康狀況,一旦其中active的NameNode宕機了,立刻切換到另外一臺NameNode。

叢集執行服務規劃

 

192.168.254.100

192.168.254.110

192.168.254.120

zookeeper

zk

zk

zk

HDFS

JournalNode

JournalNode

JournalNode

NameNode

NameNode

 

ZKFC

ZKFC

 

DataNode

DataNode

DataNode

YARN

 

ResourceManager

ResourceManager

NodeManager

NodeManager

NodeManager

MapReduce

 

 

JobHistoryServer

三臺服務配置主機名:

100為node01

110為node02

120為node03

一:安裝

在100的機器上進行解壓安裝

mkdir -p /export/softwares

mkdir -p /export/servers

cd /export/softwares

tar -zxvf hadoop-2.7.5.tar.gz -C ../servers/

二:修改配置檔案

1)修改core-site.xml

cd /export/servers/hadoop-2.7.5/etc/hadoop

vim core-site.xml

<configuration>

<!-- 指定NameNode的HA高可用的zk地址  -->

<property>

<name>ha.zookeeper.quorum</name>

<value>node01:2181,node02:2181,node03:2181</value>

</property>

 <!-- 指定HDFS訪問的域名地址  -->

<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>

 <!-- 開啟hdfs垃圾箱機制,指定垃圾箱中的檔案七天之後就徹底刪掉

單位為分鐘

 -->

<property>

<name>fs.trash.interval</name>

<value>10080</value>

</property>

</configuration>

2)修改hdfs-site.xml

cd /export/servers/hadoop-2.7.5/etc/hadoop

vim hdfs-site.xml

<configuration>

<!--  指定名稱空間  -->

<property>

<name>dfs.nameservices</name>

<value>ns</value>

</property>

<!--  指定該名稱空間下的兩個機器作為我們的NameNode  -->

<property>

<name>dfs.ha.namenodes.ns</name>

<value>nn1,nn2</value>

</property>

 

<!-- 配置第一臺伺服器的namenode通訊地址  -->

<property>

<name>dfs.namenode.rpc-address.ns.nn1</name>

<value>node01:8020</value>

</property>

<!--  配置第二臺伺服器的namenode通訊地址  -->

<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>

 

<!-- 第一臺伺服器namenode的web訪問地址  -->

<property>

<name>dfs.namenode.http-address.ns.nn1</name>

<value>node01:50070</value>

</property>

<!-- 第二臺伺服器namenode的web訪問地址  -->

<property>

<name>dfs.namenode.http-address.ns.nn2</name>

<value>node02:50070</value>

</property>

 

<!-- journalNode的訪問地址,注意這個地址一定要配置 -->

<property>

<name>dfs.namenode.shared.edits.dir</name>

<value>qjournal://node01:8485;node02:8485;node03:8485/ns1</value>

</property>

<!--  指定故障自動恢復使用的哪個java類 -->

<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>

<!-- journalNode資料存放地址  -->

<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>

<!-- namenode產生的檔案存放路徑 -->

<property>

<name>dfs.namenode.name.dir</name>

<value>file:///export/servers/hadoop-2.7.5/data/dfs/nn/name</value>

</property>

<!-- edits產生的檔案存放路徑 -->

<property>

<name>dfs.namenode.edits.dir</name>

<value>file:///export/servers/hadoop-2.7.5/data/dfs/nn/edits</value>

</property>

<!-- dataNode檔案存放路徑 -->

<property>

<name>dfs.datanode.data.dir</name>

<value>file:///export/servers/hadoop-2.7.5/data/dfs/dn</value>

</property>

<!-- 關閉hdfs的檔案許可權 -->

<property>

<name>dfs.permissions</name>

<value>false</value>

</property>

<!-- 指定block檔案塊的大小 -->

<property>

<name>dfs.blocksize</name>

<value>134217728</value>

</property>

</configuration>

3)修改yarn-site.xml

cd /export/servers/hadoop-2.7.5/etc/hadoop

vim yarn-site.xml

<configuration>

<!-- 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</value>

</property>

<!-- 配置第二臺機器的resourceManager -->

<property>

        <name>yarn.resourcemanager.hostname.rm2</name>

        <value>node02</value>

</property>

 

<!-- 配置第一臺機器的resourceManager通訊地址 -->

<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.resource-tracker.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>

 

<!-- 配置第二臺機器的resourceManager通訊地址 -->

<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.resource-tracker.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>

<!--開啟resourcemanager自動恢復功能-->

<property>

        <name>yarn.resourcemanager.recovery.enabled</name>

        <value>true</value>

</property>

<!--在node1上配置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>node02:2181,node03:2181,node01: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.7.5/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>

</configuration>

4)修改mapred-site.xml

cd /export/servers/hadoop-2.7.5/etc/hadoop

vim mapred-site.xml

<configuration>

<!--指定執行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.7.5/data/system/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.7.5/data/system/local</value>

</property>

</configuration>

5)修改slaves

cd /export/servers/hadoop-2.7.5/etc/hadoop

vim slaves

node01

node02

node03

6)修改hadoop-env.sh

cd /export/servers/hadoop-2.7.5/etc/hadoop

vim hadoop-env.sh

export JAVA_HOME=/export/servers/jdk1.8.0_141

三:拷貝hadoop到110和120機器上

cd /export/servers

scp -r hadoop-2.7.5/ node02:$PWD

scp -r hadoop-2.7.5/ node03:$PWD

三臺機器100、110、120分別執行

mkdir -p /export/servers/hadoop-2.7.5/data/dfs/nn/name

mkdir -p /export/servers/hadoop-2.7.5/data/dfs/nn/edits

mkdir -p /export/servers/hadoop-2.7.5/data/dfs/nn/name

mkdir -p /export/servers/hadoop-2.7.5/data/dfs/nn/edits

進入110機器,進入hadoop2.7.5中修改yarn-site.xml

<!--在node3上配置rm1,在node2上配置rm2,注意:一般都喜歡把配置好的檔案遠端複製到其它機器上,

但這個在YARN的另一個機器上一定要修改,其他機器上不配置此項

注意我們現在有兩個resourceManager  第三臺是rm1   第二臺是rm2

這個配置一定要記得去node02上面改好

-->

<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

在100機器上執行

cd   /export/servers/hadoop-2.7.5

bin/hdfs zkfc -formatZK

sbin/hadoop-daemons.sh start journalnode

bin/hdfs namenode -format

bin/hdfs namenode -initializeSharedEdits -force

sbin/start-dfs.sh

在110機器上執行

cd   /export/servers/hadoop-2.7.5

bin/hdfs namenode -bootstrapStandby

sbin/hadoop-daemon.sh start namenode

在120機器上執行

cd   /export/servers/hadoop-2.7.5

sbin/start-yarn.sh

在110上執行

cd   /export/servers/hadoop-2.7.5

sbin/start-yarn.sh

檢視resourceManager狀態:

在120上執行

cd   /export/servers/hadoop-2.7.5

bin/yarn rmadmin -getServiceState rm1

110上執行

cd   /export/servers/hadoop-2.7.5

bin/yarn rmadmin -getServiceState rm2

120上啟動jobHistory

cd /export/servers/hadoop-2.7.5

sbin/mr-jobhistory-daemon.sh start historyserver

hdfs狀態檢視

node01機器檢視hdfs狀態

http://192.168.254.100:50070/dfshealth.html#tab-overview

node02機器檢視hdfs狀態

http://192.168.254.110:50070/dfshealth.html#tab-overview

 

yarn叢集訪問檢視

http://node03:8088/cluster

歷史任務瀏覽介面

頁面訪問:

http://192.168.254.120:19888/jobhistory