天天看點

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

前言:

本篇文章針對于2020秋季學期的複習操作,一是對該學期的鞏固,二是讓老師知道他的努力沒有白費,同時,在此感謝徐老師對我們的精心教導…

本次需要用到的材料

  • Notepad++

    官網

    我網盤也有→https://pan.baidu.com/s/1PIkQ0eJafbYGv4J5FhIoxQ

    →t123

本篇任務

  • 任務1:安裝僞分布式更新版

    HDFS→ NameNode,DataNode,SecondaryNameNode

    Yarn→ ResourceManager,NodeManager

  • 任務2:搭建完全分布式版的Hadoop叢集(重點★)

    →簡單版的完全分布式

    前提

  • 打開虛拟機并用finalShell連接配接
  • 啟動僞分布式叢集并檢視程序等相關情況
    大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
    大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

↓ 插播兩個小知識 ↓

根據日志資訊來排錯

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

檢視hdfs上的資源最終存儲在linux系統哪個位置

[root@Mymaster logs]# cd /tmp/hadoop-root/dfs/data/current/
[root@Mymaster current]# ll
總用量 4
drwx------ 4 root root  54 1月  14 11:34 BP-2100367676-192.168.8.201-1610540476704
-rw-r--r-- 1 root root 229 1月  14 11:34 VERSION
[root@Mymaster current]# cd BP-2100367676-192.168.8.201-1610540476704/
[root@Mymaster BP-2100367676-192.168.8.201-1610540476704]# ll
總用量 4
drwxr-xr-x 4 root root  64 1月  13 20:52 current
-rw-r--r-- 1 root root 166 1月  13 20:24 scanner.cursor
drwxr-xr-x 2 root root   6 1月  14 11:34 tmp
[root@Mymaster BP-2100367676-192.168.8.201-1610540476704]# cd current/
[root@Mymaster current]# ll
總用量 8
-rw-r--r-- 1 root root  19 1月  13 20:52 dfsUsed
drwxr-xr-x 3 root root  21 1月  13 20:39 finalized
drwxr-xr-x 2 root root   6 1月  13 20:48 rbw
-rw-r--r-- 1 root root 132 1月  14 11:34 VERSION
[root@Mymaster current]# cd finalized/subdir0/subdir0/
[root@Mymaster subdir0]# ll
總用量 16
-rw-r--r-- 1 root root 31 1月  13 20:39 blk_1073741825
-rw-r--r-- 1 root root 11 1月  13 20:39 blk_1073741825_1001.meta
-rw-r--r-- 1 root root 43 1月  13 20:48 blk_1073741826
-rw-r--r-- 1 root root 11 1月  13 20:48 blk_1073741826_1002.meta
[root@Mymaster subdir0]# cat blk_1073741825
dfsa
ddasf
dfsf
dfsaa
sdfs
aaa
[root@Mymaster subdir0]# hdfs dfs -cat /input/*
dfsa
ddasf
dfsf
dfsaa
sdfs
aaa
[root@Mymaster subdir0]# pwd
/tmp/hadoop-root/dfs/data/current/BP-2100367676-192.168.8.201-1610540476704/current/finalized/subdir0/subdir0
[root@Mymaster subdir0]# 
           

僞分布式更新版

大緻步驟

建議:

删除之前安裝的hadoop僞分布式普通版

前提:

①JDK

②上傳,解壓,重命名

正式實施:

①修改配置檔案

hdfs → core-site.xml, hdfs-site.xml

yarn → yarn-site.xml, mapred-site.xml

shell → hadoop-env.sh,yarn-env.sh

②格式化NameNode

hdfs dfs -format

③啟動hadoop僞分布式叢集

start-dfs.sh → HDFS

( NameNode,DataNode,SecondaryNameNode )

start-yarn.sh → Yarn

( ResourceManager,NodeManager)

上述兩個shell腳本作用等價于:start-all.sh

④确認程序數:

>jps

NameNode

DataNode

SecondaryNameNode

ResourceManager

NodeManager

驗證:

hdfs→

①目錄的建立

②上傳

③下載下傳

監控:http://mymaster:50070

yarn(wordcount案例,源和目的地都在hdfs之上) →

yarn jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduce-example-2.7.6.jar wordcount /intput /output

監控:http://mymaster:8080

實操開始

一、關閉叢集并删除之前的hadoop分布式叢集

[root@Mymaster subdir0]# jps
19441 DataNode
19221 NameNode
19701 SecondaryNameNode
43831 Jps
[root@Mymaster subdir0]# stop-dfs.sh 
Stopping namenodes on [Mymaster]
Mymaster: stopping namenode
localhost: stopping datanode
Stopping secondary namenodes [0.0.0.0]
0.0.0.0: stopping secondarynamenode
[root@Mymaster subdir0]# cd
[root@Mymaster ~]# cd /opt/
[root@Mymaster opt]# rm -rf hadoop/
[root@Mymaster opt]# ll
總用量 0
drwxr-xr-x 8   10  143 255 9月  23 2016 jdk
drwxr-xr-x 2 root root  67 1月  13 16:59 soft
[root@Mymaster opt]# 
           

二再次安裝hadoop→同樣的解壓重命名

[root@Mymaster opt]# cd soft/
[root@Mymaster soft]# tar -zxvf hadoop-2.7.6.tar.gz -C ../
...
[root@Mymaster soft]# cd ..
[root@Mymaster opt]# ll
總用量 0
drwxr-xr-x 9 20415  101 149 4月  18 2018 hadoop-2.7.6
drwxr-xr-x 8    10  143 255 9月  23 2016 jdk
drwxr-xr-x 2 root  root  67 1月  13 16:59 soft
[root@Mymaster opt]# mv hadoop-2.7.6/ hadoop
[root@Mymaster opt]# ll
總用量 0
drwxr-xr-x 9 20415  101 149 4月  18 2018 hadoop
drwxr-xr-x 8    10  143 255 9月  23 2016 jdk
drwxr-xr-x 2 root  root  67 1月  13 16:59 soft
           

三、建立資料存儲目錄

我的設計:

  1. NameNode 資料存放目錄: /opt/hadoop-repo/name
  2. SecondaryNameNode 資料存放目錄: /opt/hadoop-repo/secondary
  3. DataNode 資料存放目錄: /opt/hadoop-repo/data
  4. 臨時資料存放目錄: /opt/hadoop-repo/tmp
[root@Mymaster opt]# mkdir -p /opt/hadoop-repo/name
[root@Mymaster opt]# mkdir -p /opt/hadoop-repo/secondary
[root@Mymaster opt]# mkdir -p /opt/hadoop-repo/data
[root@Mymaster opt]# mkdir -p /opt/hadoop-repo/tmp
           

插播小插曲之notepad++

安裝(略)

設定成中文(建議英文)

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

接下來是下載下傳一個好用的插件→NppFTP

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

使用NppFTP連接配接我們的Mymaster遠端虛拟機

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

輸入密碼→是

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

回到正題

四、配置hadoop參數

hadoop-env.sh、yarn-env.sh

1)、配置hadoop-env.sh

(腳本檔案:/etc/profile.d/bigdata.sh中已經配置了名為JAVA_HOME的環境變量,此處不用配置了。)

export JAVA_HOME=/opt/jdk

2)、配置yarn-env.sh

(若是已經配置好了JAVA_HOME環境變量,該shell腳本不用修改)

export JAVA_HOME=/opt/jdk

core-site.xml

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" ?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<!-- 指定HDFS老大(namenode)的通信位址 -->
	<property>
		<name>fs.defaultFS</name>
		<value>hdfs://Mymaster:8020</value>
	</property>
	<!-- 指定hadoop運作時産生檔案的存儲路徑 -->
	<property>
		<name>hadoop.tmp.dir</name>
		<value>file:///opt/hadoop-repo/tmp</value>
	</property>
</configuration>

           

修改完記得ctrl+s儲存!!!

同樣注意英文和中文空格的問題!!!

hdfs-site.xml

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" ?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<property>  
		<name>dfs.namenode.name.dir</name>  
		<value>file:///opt/hadoop-repo/name</value>  
	</property>
	<property> 
		<name>dfs.datanode.data.dir</name>  
		<value>file:///opt/hadoop-repo/data</value>  
	</property>
	<property>
		<name>dfs.namenode.checkpoint.dir</name>
		<value>file:///opt/hadoop-repo/secondary</value>
	</property>
	<!-- secondaryName http位址 -->
	<property>
		<name>dfs.namenode.secondary.http-address</name>
		<value>Mymaster:9001</value>
	</property>
	<!-- 資料備份數量-->
	<property>
		<name>dfs.replication</name>
		<value>1</value>
	</property>
	<!-- 運作通過web通路hdfs, 50070-->
	<property> 
		<name>dfs.webhdfs.enabled</name>  
		<value>true</value>  
	</property>
	<!-- 剔除權限控制 -->
	<property>
		<name>dfs.permissions</name>
		<value>false</value>
	</property>

</configuration>

           

yarn-site.xml

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
<?xml version="1.0"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>

<!-- Site specific YARN configuration properties -->
	<!-- reducer取資料的方式是mapreduce_shuffle -->
	<property>
		<name>yarn.nodemanager.aux-services</name>
		<value>mapreduce_shuffle</value>
	</property>
	<!-- 指定YARN的老大(ResourceManager)的位址 -->
	<property>
		<name>yarn.resourcemanager.hostname</name>
		<value>Mymaster</value>
	</property> 
	<!-- 常識:同一個程序,協定不同,端口号也不同。如:NameNode程序,hdfs協定:8020, htt協定:50070-->
	<property>  
		<name>yarn.resourcemanager.address</name>  
		<value>Mymaster:8032</value>  
	</property>  
	<property>  
		<name>yarn.resourcemanager.scheduler.address</name>  
		<value>Mymaster:8030</value>  
	</property>  
	<property>  
		<name>yarn.resourcemanager.resource-tracker.address</name>  
		<value>Mymaster:8031</value>  
	</property>  
	<property>  
		<name>yarn.resourcemanager.admin.address</name>  
		<value>Mymaster:8033</value>  
	</property>
	<!-- http://master:8088 -->
	<property> 
		<name>yarn.resourcemanager.webapp.address</name>  
		<value>Mymaster:8088</value>  
	</property>
	<property>
		<name>yarn.log-aggregation-enable</name>  
		<value>true</value>  
	</property>

</configuration>

           

mapred-site.xml

哎,好像沒有mapred-site.xml!!!

這裡需要修改一下檔案名,并且必須修改!!

選中右鍵

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

去點字尾

.template

→ok

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" ?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<!-- 通知架構MR使用YARN ,也就是“指定mr運作在yarn上”-->
	<property>
		<name>mapreduce.framework.name</name>
		<value>yarn</value>
	</property> 
	<!-- 曆史job的通路位址-->
	<property>  
		<name>mapreduce.jobhistory.address</name>  
		<value>Mymaster:10020</value>  
	</property>
	<!-- 曆史job的通路web位址-->
	<property>  
		<name>mapreduce.jobhistory.webapp.address</name>  
		<value>Mymaster:19888</value>  
	</property>
	<!-- 控制日志資訊輸出的級别 -->
	<property>
		<name>mapreduce.map.log.level</name>
		<value>INFO</value>
	</property>
	<property>
		<name>mapreduce.reduce.log.level</name>
		<value>INFO</value>
	</property>

</configuration>

           

完畢!!!

五、格式化NN,這個操作過了應該很容易

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

這裡我們可以看一下NN程序進行格式化後中繼資料檔案的内幕

我們上面設計的配置檔案NN中繼資料儲存在/opt/hadoop-repo/name/下

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

我們的hadoop-repo/name/建立的時候是沒有加東西的那麼這個就是NN格式化自動建立的!!

進去看看有什麼

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

注意:出現上述亂碼,需要關閉目前連接配接視窗;新開視窗重連master。

NN格式化内幕就說到這裡了

六、啟動hadoop僞分布式叢集

為了防止出錯我們先分開啟動

start-dfs.sh 
           
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

這裡如果某一個程序沒有起來可以單開試試,不行的話就得檢測你的配置等等了,還有就是玩壞了想重新來的要先删除NN的中繼資料啦!

hadoop-daemon.sh start namenode
hadoop-daemon.sh start DataNode
hadoop-daemon.sh start SecondaryNameNode
           
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
yarn-daemon.sh start ResourceManager
yarn-daemon.sh start SecondaryNameNode
           

所有一起的指令

[root@Mymaster ~]# stop-all.sh 
[root@Mymaster ~]# start-all.sh 
           
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

沒有問題!!!

七、驗證hadoop僞分布式叢集能夠正常使用

第1步:驗證hdfs的可用性

http://mymaster:50070

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

上傳檢視沒有問題!!

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

下載下傳也沒問題!!!

第2步:驗證yarn的可用性

通過browser能夠通路ResourceManager程序

http://mymaster:8088/

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

将應用送出到遠端hadoop僞分布式叢集中去運作

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

沒有問題!!!

重新整理ResourceManager程序browser

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

我們再運作一次看一下運作中的界面

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版
大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

到了這裡一個更新版的hadoop僞分布式叢集就完成了

那麼我們說過了,這個嬌妻不好哄,不要一激動就直接關機了,必須先關叢集,必須先關叢集,必須先關叢集!!!

大資料學習之hadoop僞分布式更新版的搭建前提僞分布式更新版

那麼,本次複習就到此結束了!!!

編寫于2021-1-14

繼續閱讀