hadoop2.0集羣搭建詳解

hadoop2.2.0集羣搭建java

    PS:apache提供的hadoop-2.2.0的安裝包是在32位操做系統編譯的,node

           由於hadoop依賴一些C++的本地庫,因此若是在64位的操做上安裝apache

           hadoop-2.2.0就須要從新在64操做系統上從新編譯vim

1.準備工做:(參考僞分佈式搭建)瀏覽器

        1.1修改Linux主機名框架

        1.2修改IPssh

        1.3修改主機名和IP的映射關係分佈式

        1.4關閉防火牆ide

        1.5ssh免登錄oop

        1.6.安裝JDK,配置環境變量等


2.集羣規劃:

            PS:

             在hadoop2.0中一般由兩個NameNode組成,一個處於active狀態,

                    另外一個處於standby狀態。Active NameNode對外提供服務,

                    而Standby NameNode則不對外提供服務,僅同步active namenode

                    的狀態,以便可以在它失敗時快速進行切換。

             hadoop2.0官方提供了兩種HDFS HA的解決方案,一種是NFS,

                    另外一種是QJM。這裏咱們使用簡單的QJM。在該方案中,

                    主備NameNode之間經過一組JournalNode同步元數據信息,

                    一條數據只要成功寫入多數JournalNode即認爲寫入成功。

                    一般配置奇數個JournalNode

             這裏還配置了一個zookeeper集羣,用於ZKFC

                    (DFSZKFailoverController)故障轉移,當Active NameNode掛

                     掉了,會自動切換Standby NameNode爲standby狀態

3.安裝步驟:

     3.1.安裝配置zooekeeper集羣

         3.1.1解壓

         tar -zxvf zookeeper-3.4.5.tar.gz -C /cloud/

     3.1.2修改配置

         cd /cloud/zookeeper-3.4.5/conf/

         cp zoo_sample.cfg zoo.cfg

         vim zoo.cfg

         修改:dataDir=/cloud/zookeeper-3.4.5/tmp

         在最後添加:

             server.1=hadoop01:2888:3888

             server.2=hadoop02:2888:3888

             server.3=hadoop03:2888:3888

         保存退出

         而後建立一個tmp文件夾

             mkdir /cloud/zookeeper-3.4.5/tmp

         再建立一個空文件

             touch /cloud/zookeeper-3.4.5/tmp/myid

         最後向該文件寫入ID

             echo 1 > /cloud/zookeeper-3.4.5/tmp/myid

     3.1.3將配置好的zookeeper拷貝到其餘節點(首先分別在hadoop0二、

            hadoop03根目錄下建立一個cloud目錄:mkdir /cloud)

             scp -r /cloud/zookeeper-3.4.5/ hadoop02:/cloud/

             scp -r /cloud/zookeeper-3.4.5/ hadoop03:/cloud/

    

     注意:修改hadoop0二、hadoop03對應

               /cloud/zookeeper-3.4.5/tmp/myid內容

         hadoop02:

             echo 2 > /cloud/zookeeper-3.4.5/tmp/myid

         hadoop03:

             echo 3 > /cloud/zookeeper-3.4.5/tmp/myid

     3.2.安裝配置hadoop集羣

         3.2.1解壓

         tar -zxvf hadoop-2.2.0.tar.gz -C /cloud/

     3.2.2配置HDFS(hadoop2.0全部的配置文件都在

            $HADOOP_HOME/etc/hadoop目錄下)

     將hadoop添加到環境變量中

         vim /etc/profile

         export JAVA_HOME=/usr/java/jdk1.6.0_45

         export HADOOP_HOME=/cloud/hadoop-2.2.0

         export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin

         cd /cloud/hadoop-2.2.0/etc/hadoop

     3.2.2.1修改hadoo-env.sh

         export JAVA_HOME=/usr/java/jdk1.6.0_45

3,2.2.2修改core-site.xml

     <configuration>

         <!-- 指定hdfs的nameservice爲ns1 -->

         <property>

             <name>fs.defaultFS</name>

             <value>hdfs://ns1</value>

         </property>

     <!-- 指定hadoop臨時目錄 -->

         <property>

             <name>hadoop.tmp.dir</name>

             <value>/cloud/hadoop-2.2.0/tmp</value>

         </property>

         <!-- 指定zookeeper地址 -->

         <property>

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

             <value>

                 hadoop01:2181,hadoop02:2181,hadoop03:2181

            </value>

         </property>

     </configuration>

3,2.2.3修改hdfs-site.xml

     <configuration>

         <!--指定hdfs的nameservice爲ns1,

         須要和core-site.xml中的保持一致 -->

         <property>

             <name>dfs.nameservices</name>

             <value>ns1</value>

         </property>

         <!-- ns1下面有兩個NameNode,分別是nn1,nn2 -->

         <property>

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

             <value>nn1,nn2</value>

         </property>

         <!-- nn1的RPC通訊地址 -->

         <property>

             <name>

                 dfs.namenode.rpc-address.ns1.nn1

             </name>

             <value>hadoop01:9000</value>

         </property>

         <!-- nn1的http通訊地址 -->

         <property>

             <name>

                 dfs.namenode.http-address.ns1.nn1

             </name>

             <value>hadoop01:50070</value>

         </property>

         <!-- nn2的RPC通訊地址 -->

         <property>

             <name>

                 dfs.namenode.rpc-address.ns1.nn2

             </name>

             <value>hadoop02:9000</value>

         </property>

         <!-- nn2的http通訊地址 -->

         <property>

             <name>

                 dfs.namenode.http-address.ns1.nn2

             </name>

             <value>hadoop02:50070</value>

         </property>

         <!-- 指定NameNode的元數據在

                JournalNode上的存放位置 -->

         <property>

             <name>

                 dfs.namenode.shared.edits.dir

            </name>

             <value>

                 qjournal://hadoop01:8485;hadoop02:8485;hadoop03:8485/ns1

             </value>

         </property>

         <!-- 指定JournalNode在本地磁盤存放數據的位置 -->

         <property>

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

             <value>/cloud/hadoop-2.2.0/journal</value>

         </property>

         <!-- 開啓NameNode失敗自動切換 -->

         <property>

             <name>

                 dfs.ha.automatic-failover.enabled

              </name>

             <value>true</value>

         </property>

         <!-- 配置失敗自動切換實現方式 -->

         <property>

             <name>

                 dfs.client.failover.proxy.provider.ns1

             </name>

             <value>

                org.apache.hadoop.hdfs.server.namenode.ha.

             ConfiguredFailoverProxyProvider

            </value>

         </property>

         <!-- 配置隔離機制 -->

         <property>

             <name>dfs.ha.fencing.methods</name>

             <value>sshfence</value>

         </property>

         <!-- 使用隔離機制時須要ssh免登錄 -->

         <property>

             <name>

                 dfs.ha.fencing.ssh.private-key-files

             </name>

             <value>/root/.ssh/id_rsa</value>

         </property>

     </configuration>

     3.2.2.4修改slaves

     hadoop01

     hadoop02

     hadoop03

     3.2.3配置YARN

         3.2.3.1修改yarn-site.xml

     <configuration>

         <!-- 指定resourcemanager地址 -->

         <property>

             <name>

                 yarn.resourcemanager.hostname

             </name>

             <value>hadoop01</value>

         </property>

         <!-- 指定nodemanager啓動時加載

                 server的方式爲shuffle server -->

         <property>

             <name>

                 yarn.nodemanager.aux-services

             </name>

             <value>mapreduce_shuffle</value>

         </property>

     </configuration>

     3.2.3.2修改mapred-site.xml

         <configuration>

             <!-- 指定mr框架爲yarn方式 -->

             <property>

                 <name>

                      mapreduce.framework.name

                  </name>

                 <value>yarn</value>

             </property>

         </configuration>

     3.2.4將配置好的hadoop拷貝到其餘節點

         scp -r /cloud/hadoop-2.2.0/ hadoo02:/cloud/

         scp -r /cloud/hadoop-2.2.0/ hadoo03:/cloud/

     3.2.5啓動zookeeper集羣

           (分別在hadoop0一、hadoop0二、hadoop03上啓動zk)

         cd /cloud/zookeeper-3.4.5/bin/

         ./zkServer.sh start

         查看狀態:

         ./zkServer.sh status

         (一個leader,兩個follower)

     3.2.6啓動journalnode(在hadoop01上啓動全部journalnode)

         cd /cloud/hadoop-2.2.0

         sbin/hadoop-daemons.sh start journalnode

         (運行jps命令檢驗,多了JournalNode進程)

     3.2.7格式化HDFS

         在hadoop01上執行命令:

         hadoop namenode -format

         格式化後會在根據core-site.xml中的hadoop.tmp.dir

         配置生成個文件,這裏我配置的是/cloud/hadoop-2.2.0/tmp,

         而後將/cloud/hadoop-2.2.0/tmp拷貝到hadoop02的

         /cloud/hadoop-2.2.0/下。

         scp -r tmp/ hadoop02:/cloud/hadoop-2.2.0/

     3.2.8格式化ZK(在hadoop01上執行便可)

         hdfs zkfc -formatZK

     3.2.9啓動HDFS(在hadoop01上執行)

         sbin/start-dfs.sh


     3.3.10啓動YARN(在hadoop01上執行)

         sbin/start-yarn.sh


    到此,hadoop2.2.0配置完畢,能夠統計瀏覽器訪問:

         http://192.168.1.201:50070

         NameNode 'hadoop01:9000' (active)

         http://192.168.1.202:50070

         NameNode 'hadoop02:9000' (standby)

    驗證HDFS HA

         首先向hdfs上傳一個文件

             hadoop fs -put /etc/profile /profile

             hadoop fs -ls /

         而後再kill掉active的NameNode

             kill -9 <pid of NN>

         經過瀏覽器訪問:http://192.168.1.202:50070

             NameNode 'hadoop02:9000' (active)

             這個時候hadoop02上的NameNode變成了active

         在執行命令:

             hadoop fs -ls /

             -rw-r--r--   3 root supergroup       1926 2014-02-06 15:36 /profile

     剛纔上傳的文件依然存在!!!

         手動啓動那個掛掉的NameNode

         sbin/hadoop-daemon.sh start namenode

         經過瀏覽器訪問:http://192.168.1.201:50070

         NameNode 'hadoop01:9000' (standby)

    驗證YARN:

         運行一下hadoop提供的demo中的WordCount程序:

             hadoop jar share/hadoop/mapreduce/hadoop-mapreduce

            -examples-2.2.0.jar wordcount /profile /out

    

OK,大功告成!!!

相關文章
相關標籤/搜索