Hadoop分佈式安裝筆記

參考https://blog.csdn.net/hliq5399/article/details/78193113這篇博客,自己用docker安裝了3個容器來模擬了下hadoop分佈式的安裝

Hadoop我用2.8.5的安裝, 解壓放在/hadoop/modules/hadoop-2.8.5,hdfs目錄
JDK1.8

服務器模塊功能規劃如下:

名稱 IP 運行的模塊
bigdata-01.com 172.17.0.2 NamNode,DataNode,NodeManager,HistoryServer
bigdata-02.com 172.17.0.3 DataNode,ResourceManager,NodeManager
bigdata-03.com 172.17.0.4 SecondaryNameNode,DataNode,NodeManager

對應在3臺服務器建好Hadoop用戶,並相互SSH免密登錄。


下面配置3臺服務器保持一致

配置Hostname

/etc/hosts 添加服務器名字路由

172.17.0.2  bigdata-01.com
172.17.0.3  bigdata-02.com
172.17.0.4  bigdata-03.com

配置core-site.xml

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://bigdata-01.com:8020</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/hadoop/data/tmp</value>
    </property>
    <property>
     	<name>dfs.namenode.name.dir</name>
     	<value>file://${hadoop.tmp.dir}/dfs/name</value>
  	</property>
	<property>
     	<name>dfs.datanode.data.dir</name>
     	<value>file://${hadoop.tmp.dir}/dfs/data</value>
  	</property>
</configuration>

配置hdfs-site.xml

<configuration>
    <property>
       <name>dfs.replication</name>
       <value>2</value>
    </property>
    <property>
        <name>dfs.namenode.secondary.http-address</name>
        <value>bigdata-03.com:50090</value>
    </property>
</configuration>

bigdata-03 運行secondary name node,將文件備份設置爲2

配置slaves

/etc/hadoop/slaves文件修改:

bigdata-01.com
bigdata-02.com
bigdata-03.com

配置yarn-site.xml

<configuration>
<!-- Site specific YARN configuration properties -->
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>
    <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>bigdata-02.com</value>
    </property>
    <!-- 是否啓用日誌聚集功能 -->
    <property>
        <name>yarn.log-aggregation-enable</name>
        <value>true</value>
    </property>
    <!-- 在HDFS上最多保存多長時間 -->
    <property>
        <name>yarn.log-aggregation.retain-seconds</name>
        <value>106800</value>
    </property>
</configuration>

配置mapred-site.xml

<configuration>
	<!-- mapreduce.framework.name設置mapreduce任務運行在yarn上 -->
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
    <!-- 設置mapreduce的歷史服務器安裝在BigData01機器上 -->
    <property>
        <name>mapreduce.jobhistory.address</name>
        <value>bigdata-01.com:10020</value>
    </property>
    <!-- web -->
    <property>
        <name>mapreduce.jobhistory.webapp.address</name>
        <value>bigdata-01.com:19888</value>
    </property>
</configuration>              

接下來在NameNode機器上(bigdata01.com)執行格式化:
在這裏插入圖片描述
成功後會生成下圖所示
在這裏插入圖片描述
配置,環境到此完結。接下來按規劃啓動模塊。


啓動hdfs

在bigdata-01機器上運行 sbin/start-dfs.sh
在這裏插入圖片描述
namenode 、secondarynamenode、datanode就分別在3個環境中啓動了

啓動yarn

在bigdata-01機器上運行sbin/start-yarn.sh
在這裏插入圖片描述
nodemanager就在3個環境中啓動

在bigdata-02機器上運行sbin/yarn-daemon.sh start resourcemanager
在這裏插入圖片描述
resourcesmanager在bigdata-02上運行

日誌服務器

在bigdata-01 上運行 sbin/mr-jobhistory-daemon.sh start historyserver
在這裏插入圖片描述


到此各個模塊就在不同容器中運行了。下面做測試,創建一個input目錄,並上傳一個wc.input文件
在bigdata-01.com上運行

bin/hdfs dfs -mkdir /input
bin/hdfs dfs -put /hadoop/data/wc.input /input/wc.input

在這裏插入圖片描述

hdfs web

成功後,可打開bigdata-01的web管理頁面http://192.168.3.14:50070/ (宿主機器端口映射到bigdata-01的端口)查看:
在這裏插入圖片描述
文件有2個備份。

yarn web在這裏插入圖片描述

jobhistory web

在這裏插入圖片描述


環境基本上搭建完畢,接下來關注如何使用,運維方面暫不深究了。通過搭建環境對各個模塊是做什麼用的有個大致的瞭解。

運行example,統計wc.input單詞個數
bin/yarn jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8.5.jar wordcount /input /out
在這裏插入圖片描述
電腦運行效率太差,導致中途有報錯,看了下,大概是網絡連接超時和reduce執行的內存不夠重來,畢竟3個容器運行在一個10年前的筆記本,cpu、mem都不夠,不過總算是執行完畢,運行結果截圖截圖紀念一下:
在這裏插入圖片描述
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章