hadoop2.7.3集羣部署

1、安裝版本:

JDK 1.8.0_111-b14
hadoop hadoop-2.7.3
zookeeper zookeeper-3.5.2

2、安裝步驟:  

    JDK的安裝和集羣的依賴環境配置再也不敘述https://my.oschina.net/u/2500254/blog/806114html

一、hadoop配置

    hadoop配置主要涉及hdfs-site.xml,core-site.xml,mapred-site.xml,yarn-site.xml四個文件。如下詳細介紹每一個文件的配置。java

  1. core-site.xml的配置

    <configuration>
    <property>
          <name>fs.defaultFS</name>
          <value>hdfs://cluster1</value>
          <description>HDFS namenode的邏輯名稱,也就是namenode HA,此值要對應hdfs-site.xml裏的dfs.nameservices</description>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/usr/hadoop/tmp</value>
        <description>hdfs中namenode和datanode的數據默認放置路徑,也能夠在hdfs-site.xml中分別指定</description>
    </property>
    <property>
            <name>ha.zookeeper.quorum</name>
            <value>master:2181,salve1:2181,salve2:2181</value>
            <description>zookeeper集羣的地址和端口,zookeeper集羣的節點數必須爲奇數</description>
    </property>
    </configuration>
  2. hdfs-site.xml的配置(重點配置)

    <configuration>
    <property>
        <name>dfs.name.dir</name>
        <value>/usr/hadoop/hdfs/name</value>
        <description>namenode的數據放置目錄</description>
    </property>
    <property>
        <name>dfs.data.dir</name>
        <value>/usr/hadoop/hdfs/data</value>
        <description>datanode的數據放置目錄</description>
    </property>
    <property>
        <name>dfs.replication</name>
        <value>4</value>
        <description>數據塊的備份數,默認是3</description>
    </property>
    <property>
            <name>dfs.nameservices</name>
            <value>cluster1</value>
            <description>HDFS namenode的邏輯名稱,也就是namenode HA</description>
    </property>
    <property>
            <name>dfs.ha.namenodes.cluster1</name>
            <value>ns1,ns2</value>
            <description>nameservices對應的namenode邏輯名</description>
    </property>
    <property>
            <name>dfs.namenode.rpc-address.cluster1.ns1</name>
            <value>master:9000</value>
            <description>指定namenode(ns1)的rpc地址和端口</description>
    </property>
    <property>
            <name>dfs.namenode.http-address.cluster1.ns1</name>
            <value>master:50070</value>
            <description>指定namenode(ns1)的web地址和端口</description>
    </property>
    <property>
            <name>dfs.namenode.rpc-address.cluster1.ns2</name>
            <value>salve1:9000</value>
            <description>指定namenode(ns2)的rpc地址和端口</description>
    </property>
    <property>
            <name>dfs.namenode.http-address.cluster1.ns2</name>
            <value>salve1:50070</value>
            <description>指定namenode(ns2)的web地址和端口</description>
    </property>
    <property>
            <name>dfs.namenode.shared.edits.dir</name>
            <value>qjournal://master:8485;salve1:8485;salve2:8485/cluster1 </value>
            <description>這是NameNode讀寫JNs組的uri,active NN 將 edit log 寫入這些JournalNode,而 standby NameNode 讀取這些 edit log,並做用在內存中的目錄樹中</description>
    </property>
    <property>
            <name>dfs.journalnode.edits.dir</name>
            <value>/usr/hadoop/journal</value>
            <description>ournalNode 所在節點上的一個目錄,用於存放 editlog 和其餘狀態信息。</description>
    </property>
    <property>  
               <name>dfs.ha.automatic-failover.enabled</name>  
               <value>true</value>
               <description>啓動自動failover。自動failover依賴於zookeeper集羣和ZKFailoverController(ZKFC),後者是一個zookeeper客戶端,用來監控NN的狀態信息。每一個運行NN的節點必需要運行一個zkfc</description>  
    </property>
    <property>
            <name>dfs.client.failover.proxy.provider.cluster1</name>
            <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
            <description>配置HDFS客戶端鏈接到Active NameNode的一個java類</description>
    </property>
    <property>
            <name>dfs.ha.fencing.methods</name>
            <value>sshfence</value>
            <description>解決HA集羣腦裂問題(即出現兩個 master 同時對外提供服務,致使系統處於不一致狀態)。在 HDFS HA中,JournalNode 只容許一個 NameNode 寫數據,不會出現兩個 active NameNode 的問題,
    可是,當主備切換時,以前的 active NameNode 可能仍在處理客戶端的 RPC 請求,爲此,須要增長隔離機制(fencing)將以前的 active NameNode 殺死。經常使用的fence方法是sshfence,要指定ssh通信使用的密鑰dfs.ha.fencing.ssh.private-key-files和鏈接超時時間</description>
    </property>
    <property>
            <name>dfs.ha.fencing.ssh.private-key-files</name>
            <value>/home/hadoop/.ssh/id_rsa</value>
            <description>ssh通信使用的密鑰</description>        
    </property>
    <property>
            <name>dfs.ha.fencing.ssh.connect-timeout</name>
            <value>30000</value>
            <description>鏈接超時時間</description> 
    </property>
    </configuration>

     

  3. mapred-site.xml的配置

    <configuration>
    <property>
            <name>mapreduce.framework.name</name>
            <value>yarn</value>
            <description>指定運行mapreduce的環境是yarn,與hadoop1大相徑庭的地方</description>
    </property>
    <property>
            <name>mapreduce.jobhistory.address</name>
            <value>master:10020</value>
             <description>MR JobHistory Server管理的日誌的存放位置</description>
    </property>
    <property>
            <name>mapreduce.jobhistory.webapp.address</name>
            <value>master:19888</value>
            <description>查看歷史服務器已經運行完的Mapreduce做業記錄的web地址,須要啓動該服務才行</description>
    </property>
    <property>
       <name>mapreduce.jobhistory.done-dir</name>
       <value>/data/hadoop/done</value>
       <description>MR JobHistory Server管理的日誌的存放位置,默認:/mr-history/done</description>
    </property>
    <property>
       <name>mapreduce.jobhistory.intermediate-done-dir</name>
       <value>hdfs://mycluster-pha/mapred/tmp</value>
       <description>MapReduce做業產生的日誌存放位置,默認值:/mr-history/tmp</description>
    </property>
    </configuration>

     

  4. yarn-site.xml的配置

<configuration>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
        <description>默認</description>
    </property>
         <property>
        <name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
        <value>org.apache.hadoop.mapred.ShuffleHandler</value>
    </property>
    <property>
        <name>yarn.resourcemanager.address</name>
        <value>master:8032</value>
    </property>
    <property>
        <name>yarn.resourcemanager.scheduler.address</name>
        <value>master:8030</value>
    </property>
    <property>
        <name>yarn.resourcemanager.resource-tracker.address</name>
        <value>master:8031</value>
    </property>
    <property>
        <name>yarn.resourcemanager.admin.address</name>
        <value>master:8033</value>
    </property>
    <property>
        <name>yarn.resourcemanager.webapp.address</name>
        <value>master:8088</value>
    </property>
<property>
    <name>yarn.nodemanager.resource.memory-mb</name>
    <value>1024</value>
    <description>該值配置小於1024時,NM是沒法啓動的!會報錯:
NodeManager from  slavenode2 doesn't satisfy minimum allocations, Sending SHUTDOWN signal to the NodeManager.</description>
  </property>
</configuration>

2.zookeeper配置

    zookeeper的配置主要是zoo.cfg和myid兩個文件node

  1. conf/zoo.cfg配置:先將zoo_sample.cfg改爲zoo.cfg

    cp  zoo_sample.cfg  zoo.cfg
  2. vi zoo.cfg

    dataDir:數據的放置路徑
    
    dataLogDir:log的放置路徑
    initLimit=10
    syncLimit=5
    clientPort=2181
    tickTime=2000
    dataDir=/usr/zookeeper/tmp/data
    dataLogDir=/usr/zookeeper/tmp/log
    server.1=master:2888:3888
    server.2=slave1:2888:3888
    server.3=slave2:2888:3888
  3. 在[master,slave1,slave2]節點的dataDir目錄新建文件myid

vi myid

    master節點編輯:1web

    slave1節點編輯:2apache

    slave2節點編輯:3bootstrap

    以下:api

[hadoop@master data]$ vi myid 

1

3、啓動集羣

 1.zookeeper集羣啓動

    1.啓動zookeeper集羣,在三個節點所有啓動

bin/zkServer.sh start

    2.查看集羣zookeeper狀態:zkServer.sh status,一個learer兩個follower。

[hadoop@master hadoop-2.7.3]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[hadoop@slave1 root]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
[hadoop@slave2 root]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower

    3.驗證zookeeper(非必須): 執行zkCli.sh

[hadoop@slave1 root]$ zkCli.sh
Connecting to localhost:2181
2016-12-18 02:05:03,115 [myid:] - INFO  [main:Environment@109] - Client environment:zookeeper.version=3.5.2-alpha-1750793, built on 06/30/2016 13:15 GMT
2016-12-18 02:05:03,118 [myid:] - INFO  [main:Environment@109] - Client environment:host.name=salve1
2016-12-18 02:05:03,118 [myid:] - INFO  [main:Environment@109] - Client environment:java.version=1.8.0_111
2016-12-18 02:05:03,120 [myid:] - INFO  [main:Environment@109] - Client environment:java.vendor=Oracle Corporation
2016-12-18 02:05:03,120 [myid:] - INFO  [main:Environment@109] - Client environment:java.home=/usr/local/jdk1.8.0_111/jre
2016-12-18 02:05:03,120 [myid:] - INFO  [main:Environment@109] - Client environment:java.class.path=/usr/local/zookeeper-3.5.2-alpha/bin/../build/classes:/usr/local/zookeeper-3.5.2-alpha/bin/../build/lib/*.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/slf4j-log4j12-1.7.5.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/slf4j-api-1.7.5.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/servlet-api-2.5-20081211.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/netty-3.10.5.Final.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/log4j-1.2.17.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/jline-2.11.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/jetty-util-6.1.26.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/jetty-6.1.26.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/javacc.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/jackson-mapper-asl-1.9.11.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/jackson-core-asl-1.9.11.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../lib/commons-cli-1.2.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../zookeeper-3.5.2-alpha.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.5.2-alpha/bin/../conf:.:/usr/local/jdk1.8.0_111/lib/dt.jar:/usr/local/jdk1.8.0_111/lib/tools.jar:/usr/local/zookeeper-3.5.2-alpha/bin:/usr/local/hadoop-2.7.3/bin
2016-12-18 02:05:03,120 [myid:] - INFO  [main:Environment@109] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:java.io.tmpdir=/tmp
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:java.compiler=<NA>
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:os.name=Linux
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:os.arch=amd64
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:os.version=3.10.0-327.22.2.el7.x86_64
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:user.name=hadoop
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:user.home=/home/hadoop
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:user.dir=/tmp/hsperfdata_hadoop
2016-12-18 02:05:03,121 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.free=52MB
2016-12-18 02:05:03,123 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.max=228MB
2016-12-18 02:05:03,123 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.total=57MB
2016-12-18 02:05:03,146 [myid:] - INFO  [main:ZooKeeper@855] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@593634ad
Welcome to ZooKeeper!
2016-12-18 02:05:03,171 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1113] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2016-12-18 02:05:03,243 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@948] - Socket connection established, initiating session, client: /127.0.0.1:56184, server: localhost/127.0.0.1:2181
2016-12-18 02:05:03,252 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1381] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x200220f5fe30060, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]

2.hadoop集羣啓動

    1.第一次配置啓動

        1.1在三個節點上啓動Journalnode deamons,而後jps,出現JournalNode進程。瀏覽器

sbin/./hadoop-daemon.sh start journalnode
jps

JournalNode

        1.2格式化master上的namenode(任意一個),而後啓動該節點的namenode。服務器

bin/hdfs namenode -format
sbin/hadoop-daemon.sh start namenode

        1.3在另外一個namenode節點slave1上同步master上的元數據信息session

bin/hdfs namenode -bootstrapStandby

         1.4中止hdfs上的全部服務

sbin/stop-dfs.sh

        1.5初始化zkfc

bin/hdfs zkfc -formatZK

        1.6啓動hdfs

sbin/start-dfs.sh

        1.7啓動yarn

sbin/start-yarn.sh

    2.非第一次配置啓動

        2.1直接啓動hdfs和yarn便可,namenode、datanode、journalnode、DFSZKFailoverController都會自動啓動。

        

sbin/start-dfs.sh

 

        2.2啓動yarn

sbin/start-yarn.sh

4、查看各節點的進程

    4.1master

[hadoop@master hadoop-2.7.3]$ jps
26544 QuorumPeerMain
25509 JournalNode
25704 DFSZKFailoverController
26360 Jps
25306 DataNode
25195 NameNode
25886 ResourceManager
25999 NodeManager

    4.2slave1

[hadoop@slave1 root]$ jps
2289 DFSZKFailoverController
9400 QuorumPeerMain
2601 Jps
2060 DataNode
2413 NodeManager
2159 JournalNode
1983 NameNode

    4.3slave2

[hadoop@slave2 root]$ jps
11984 DataNode
12370 Jps
2514 QuorumPeerMain
12083 JournalNode
12188 NodeManager

5、瀏覽器查看

    http://master:8088/cluster/cluster,yarn的資源管理頁面    

    http://master:50070/dfshealth.html#tab-overview ,master節點的hdfs頁面

    http://slave1:50070/dfshealth.html#tab-overview ,slave1節點的hdfs頁面

相關文章
相關標籤/搜索