
啟用HDFS文件系統(tǒng)之前,需要對其進行格式化;格式化只需做一次
在192.168.31.130上執(zhí)行如下命令
cd /opt/linuxsir/hadoop/bin
./hdfs namenode -format
rm -rf /opt/linuxsir/hadoop/logs/*.*
ssh root@192.168.31.132 rm -rf /opt/linuxsir/hadoop/logs/*.*
ssh root@192.168.31.133 rm -rf /opt/linuxsir/hadoop/logs/*.*
cd /opt/linuxsir/hadoop/sbin
./start-all.sh
\如果要停止,請執(zhí)行如下命令
cd /opt/linuxsir/hadoop/sbin
./stop-all.sh
clear
cd /opt/linuxsir/hadoop/sbin
./start-dfs.sh
./start-yarn.sh
\如果要停止,請執(zhí)行如下命令,即分開停止HDFS和YARN
cd /opt/linuxsir/hadoop/sbin
./stop-yarn.sh
./stop-dfs.sh
現(xiàn)在,可以在三個節(jié)點上,查看進程,驗證Hadoop是否成功啟動
[root@hd-master bin]# jps
6262 NameNode
28630 Jps
6455 SecondaryNameNode
6618 ResourceManager
[root@hd-master bin]# ssh root@192.168.31.132 jps
3431 NodeManager
20697 Jps
3311 DataNode
[root@hd-master bin]# ssh root@192.168.31.133 jps
3313 DataNode
3431 NodeManager
20295 Jps
到目前為止,啟動HDFS和YARN以后,各個節(jié)點的進程,如下圖所示
層級 | hd-master | hd-slave1 | hd-slave2 |
---|---|---|---|
hdfs層 | NameNode、Secondary、NameNode | DataNode | DataNode |
Yarn層 | ResourceManager | NodeManager | NodeManager |
hardware各個節(jié)點 | 192.168.31.131 | 192.168.31.132 | 192.168.31.133 |
在hd-master上運行如下命令,報告HDFS的基本信息
cd /opt/linuxsir/hadoop
./bin/hdfs dfsadmin -report
[root@hd-master bin]# cd /opt/linuxsir/hadoop
[root@hd-master hadoop]# ./bin/hdfs dfsadmin -report
Configured Capacity: 63116517376 (58.78 GB)
Present Capacity: 52430880768 (48.83 GB)
DFS Remaining: 52430462976 (48.83 GB)
DFS Used: 417792 (408 KB)
DFS Used%: 0.00%
Under replicated blocks: 2
Blocks with corrupt replicas: 0
Missing blocks: 0
Missing blocks (with replication factor 1): 0
-------------------------------------------------
Live datanodes (2):
Name: 192.168.31.133:50010 (hd-slave2)
Hostname: hd-slave2
Decommission Status : Normal
Configured Capacity: 31558258688 (29.39 GB)
DFS Used: 208896 (204 KB)
Non DFS Used: 5349883904 (4.98 GB)
DFS Remaining: 26208165888 (24.41 GB)
DFS Used%: 0.00%
DFS Remaining%: 83.05%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
Last contact: Fri Oct 11 01:29:14 PDT 2024
Name: 192.168.31.132:50010 (hd-slave1)
Hostname: hd-slave1
Decommission Status : Normal
Configured Capacity: 31558258688 (29.39 GB)
DFS Used: 208896 (204 KB)
Non DFS Used: 5335752704 (4.97 GB)
DFS Remaining: 26222297088 (24.42 GB)
DFS Used%: 0.00%
DFS Remaining%: 83.09%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
Last contact: Fri Oct 11 01:29:14 PDT 2024
如果Hadoop啟動出問題,可以通過查看日志來尋找原因。每次啟動Hadoop,應該首先清空三個節(jié)點的logs目錄,方便尋找錯誤。
當啟動出錯,可以到相應節(jié)點上,查看日志文件。哪個節(jié)點啟動出錯,就看哪個節(jié)點的日志文件。由于有無密碼ssh登錄,可以通過主節(jié)點登錄到其它節(jié)點,去查看所有節(jié)點的日志文件。
日志文件分別在hd-master、hd-slave1、hd-slave2的/opt/linuxsir/hadoop/logs目錄下。
啟動Hadoop之前,刪除log文件
如果啟動出問題,log文件里就是最新的出錯信息
rm -rf /opt/linuxsir/hadoop/logs/*.*
ssh root@192.168.31.132 rm -rf /opt/linuxsir/hadoop/logs/*.*
ssh root@192.168.31.133 rm -rf /opt/linuxsir/hadoop/logs/*.*
若干web管理界面,列表如下
訪問NameNode管理頁面,監(jiān)控文件系統(tǒng)。 http://192.168.31.131:50070/
訪問ResourceManager(整個Cluster)管理頁面,監(jiān)控集群狀況。 http://192.168.31.131:9099/ 這個端口缺省是8088,由于端口沖突,改成9099, 參考yarn-site.xml
MapReduce JobHistory Server的管理頁面,查看MapReduce作業(yè)提交歷史;需要事先啟動JobHistory Server。 http://192.168.31.131:19888/
cd /opt/linuxsir/hadoop/bin
hdfs dfsadmin -safemode leave
\ 用戶可以通過dfsadmin -safemode value 來操作安全模式,參數(shù)value的說明如下:
\ enter - 進入安全模式
\ leave - 強制NameNode離開安全模式
\ get - 返回安全模式是否開啟的信息
\ wait - 等待,一直到安全模式結束
cd /opt/linuxsir/hadoop/bin
./hdfs dfs -rm -r /input \ 遞歸式刪除目錄
./hdfs dfs -mkdir /input \ 創(chuàng)建目錄
./hdfs dfs -chmod a+rwx /input \ 授權
./hdfs dfs -mkdir /output \ 創(chuàng)建目錄
./hdfs dfs -copyFromLocal /opt/linuxsir/test.txt /input \ 拷貝文件到HDFS
\ 或者./hdfs dfs -put /opt/linuxsir/test.txt /input
./hdfs dfs -cat /input/test.txt | head \ 顯示文件的頭幾行
注意,需要事先啟動HDFS和YARN
cd /opt/linuxsir/hadoop/bin
./hdfs dfs -cat /input/test.txt
./hadoop jar /opt/linuxsir/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /input/test.txt /output
./hdfs dfs -ls /output
./hdfs dfs -cat /output/part-r-00000
為了運行wordcount,必須保證hdfs分布式文件系統(tǒng)的/output不存在。如果存在可以把它刪除,命令如下
cd /opt/linuxsir/hadoop/bin
./hdfs dfs -ls /output
./hdfs dfs -rm /output/*
./hdfs dfs -rmdir /output
在hd-master節(jié)點上,配置History Server
1、在.../etc/hadoop/mapred-site.xml中配置以下內容
<property>
<name>mapreduce.jobhistory.address</name>
<value>hd-master:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hd-master:19888</value>
</property>
2、把hd-master的新配置分發(fā)到所有節(jié)點即hd-slave1和hd-slave2。
clear
scp /opt/linuxsir/hadoop/etc/hadoop/mapred-site.xml hd-slave1:/opt/linuxsir/hadoop/etc/hadoop
scp /opt/linuxsir/hadoop/etc/hadoop/mapred-site.xml hd-slave2:/opt/linuxsir/hadoop/etc/hadoop
3、啟動服務,在hd-master這臺服務器上執(zhí)行以下語句。 注意,需要事先啟動HDFS和YARN
cd /opt/linuxsir/hadoop/sbin
mr-jobhistory-daemon.sh start historyserver
clear
jps
ssh root@192.168.31.132 jps
ssh root@192.168.31.133 jps
訪問MapReduce JobHistory Server
http://192.168.31.131:19888/
為了順利運行該實例,需要編輯/opt/linuxsir/hadoop/etc/hadoop/hdfs-site.xml配置文件,添加如下配置
<!-- for windows access linux HDFS -->
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
這里分享一個你一定用得到的小程序——CDA數(shù)據(jù)分析師考試小程序。
它是專為CDA數(shù)據(jù)分析認證考試報考打造的一款小程序??梢詭湍憧焖賵竺荚?、查成績、查證書、查積分,通過該小程序,考生可以享受更便捷的服務。
掃碼加入CDA小程序,與圈內考生一同學習、交流、進步!
數(shù)據(jù)分析咨詢請掃描二維碼
若不方便掃碼,搜微信號:CDAshujufenxi
SQL Server 中 CONVERT 函數(shù)的日期轉換:從基礎用法到實戰(zhàn)優(yōu)化 在 SQL Server 的數(shù)據(jù)處理中,日期格式轉換是高頻需求 —— 無論 ...
2025-09-18MySQL 大表拆分與關聯(lián)查詢效率:打破 “拆分必慢” 的認知誤區(qū) 在 MySQL 數(shù)據(jù)庫管理中,“大表” 始終是性能優(yōu)化繞不開的話題。 ...
2025-09-18CDA 數(shù)據(jù)分析師:表結構數(shù)據(jù) “獲取 - 加工 - 使用” 全流程的賦能者 表結構數(shù)據(jù)(如數(shù)據(jù)庫表、Excel 表、CSV 文件)是企業(yè)數(shù)字 ...
2025-09-18DSGE 模型中的 Et:理性預期算子的內涵、作用與應用解析 動態(tài)隨機一般均衡(Dynamic Stochastic General Equilibrium, DSGE)模 ...
2025-09-17Python 提取 TIF 中地名的完整指南 一、先明確:TIF 中的地名有哪兩種存在形式? 在開始提取前,需先判斷 TIF 文件的類型 —— ...
2025-09-17CDA 數(shù)據(jù)分析師:解鎖表結構數(shù)據(jù)特征價值的專業(yè)核心 表結構數(shù)據(jù)(以 “行 - 列” 規(guī)范存儲的結構化數(shù)據(jù),如數(shù)據(jù)庫表、Excel 表、 ...
2025-09-17Excel 導入數(shù)據(jù)含缺失值?詳解 dropna 函數(shù)的功能與實戰(zhàn)應用 在用 Python(如 pandas 庫)處理 Excel 數(shù)據(jù)時,“缺失值” 是高頻 ...
2025-09-16深入解析卡方檢驗與 t 檢驗:差異、適用場景與實踐應用 在數(shù)據(jù)分析與統(tǒng)計學領域,假設檢驗是驗證研究假設、判斷數(shù)據(jù)差異是否 “ ...
2025-09-16CDA 數(shù)據(jù)分析師:掌控表格結構數(shù)據(jù)全功能周期的專業(yè)操盤手 表格結構數(shù)據(jù)(以 “行 - 列” 存儲的結構化數(shù)據(jù),如 Excel 表、數(shù)據(jù) ...
2025-09-16MySQL 執(zhí)行計劃中 rows 數(shù)量的準確性解析:原理、影響因素與優(yōu)化 在 MySQL SQL 調優(yōu)中,EXPLAIN執(zhí)行計劃是核心工具,而其中的row ...
2025-09-15解析 Python 中 Response 對象的 text 與 content:區(qū)別、場景與實踐指南 在 Python 進行 HTTP 網(wǎng)絡請求開發(fā)時(如使用requests ...
2025-09-15CDA 數(shù)據(jù)分析師:激活表格結構數(shù)據(jù)價值的核心操盤手 表格結構數(shù)據(jù)(如 Excel 表格、數(shù)據(jù)庫表)是企業(yè)最基礎、最核心的數(shù)據(jù)形態(tài) ...
2025-09-15Python HTTP 請求工具對比:urllib.request 與 requests 的核心差異與選擇指南 在 Python 處理 HTTP 請求(如接口調用、數(shù)據(jù)爬取 ...
2025-09-12解決 pd.read_csv 讀取長浮點數(shù)據(jù)的科學計數(shù)法問題 為幫助 Python 數(shù)據(jù)從業(yè)者解決pd.read_csv讀取長浮點數(shù)據(jù)時的科學計數(shù)法問題 ...
2025-09-12CDA 數(shù)據(jù)分析師:業(yè)務數(shù)據(jù)分析步驟的落地者與價值優(yōu)化者 業(yè)務數(shù)據(jù)分析是企業(yè)解決日常運營問題、提升執(zhí)行效率的核心手段,其價值 ...
2025-09-12用 SQL 驗證業(yè)務邏輯:從規(guī)則拆解到數(shù)據(jù)把關的實戰(zhàn)指南 在業(yè)務系統(tǒng)落地過程中,“業(yè)務邏輯” 是連接 “需求設計” 與 “用戶體驗 ...
2025-09-11塔吉特百貨孕婦營銷案例:數(shù)據(jù)驅動下的精準零售革命與啟示 在零售行業(yè) “流量紅利見頂” 的當下,精準營銷成為企業(yè)突圍的核心方 ...
2025-09-11CDA 數(shù)據(jù)分析師與戰(zhàn)略 / 業(yè)務數(shù)據(jù)分析:概念辨析與協(xié)同價值 在數(shù)據(jù)驅動決策的體系中,“戰(zhàn)略數(shù)據(jù)分析”“業(yè)務數(shù)據(jù)分析” 是企業(yè) ...
2025-09-11Excel 數(shù)據(jù)聚類分析:從操作實踐到業(yè)務價值挖掘 在數(shù)據(jù)分析場景中,聚類分析作為 “無監(jiān)督分組” 的核心工具,能從雜亂數(shù)據(jù)中挖 ...
2025-09-10統(tǒng)計模型的核心目的:從數(shù)據(jù)解讀到?jīng)Q策支撐的價值導向 統(tǒng)計模型作為數(shù)據(jù)分析的核心工具,并非簡單的 “公式堆砌”,而是圍繞特定 ...
2025-09-10