安裝
Homebrew是MacOs系統(tǒng)下一款強大的軟件包管理工具整吆,通過它可以安裝git拱撵、wget等工具,同樣Hadoop的安裝也可以通過它來進(jìn)行:
brew install hadoop
這樣hadoop被安裝在系統(tǒng)的 /usr/local/Cellar/hadoop 目錄之下表蝙。
配置
hadoop安裝后拴测,提供三種運行模式:
獨立模式
偽分布模式
完全分布式
以下是《Hadoop權(quán)威指南》對這三種模式的解釋:
Standalone (or local) mode
There are no daemons running and everything runs in a single JVM. Standalone
mode is suitable for running MapReduce programs during development, since it is
easy to test and debug them.
Pseudodistributed mode
The Hadoop daemons run on the local machine, thus simulating a cluster on a small
scale.
Fully distributed mode
The Hadoop daemons run on a cluster of machines.
在用brew安裝完成后,Hadoop默認(rèn)是獨立模式府蛇,這種模式?jīng)]有開辟守護(hù)進(jìn)程集索,運行與JVM虛擬機上,適合MapReduce的測試與調(diào)試。而偽分布式模式會開辟守護(hù)進(jìn)程务荆,運行效果和在集群上類似妆距,所以這里,我們將在電腦上進(jìn)行偽分布模式的配置函匕。
1.配置文件
在目錄/usr/local/Cellar/hadoop/xxxxx/libexec/etc/hadoop/下進(jìn)行配置:
<?xml version="1.0"?>
<!-- core-site.xml -->
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost/</value>
</property>
</configuration>
<?xml version="1.0"?>
<!-- hdfs-site.xml -->
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
<?xml version="1.0"?>
<!-- mapred-site.xml -->
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
<?xml version="1.0"?>
<!-- yarn-site.xml -->
<configuration>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>localhost</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
需要對core-site.xml娱据、hdfs-site.xml、mapred-site.xml盅惜、yarn-site.xml四個文件添加這些鍵值對中剩。(可以將該文件夾復(fù)制多份,開啟Hadoop時調(diào)用不同的文件下從而可以開啟不同的模式)
2.ssh登陸配置
在偽分布模式下酷窥,Hadoop是需要通過ssh來登陸的咽安,如果配置了ssh秘鑰伴网,登陸就不需要做密碼輸入蓬推。先查看本地目錄~/.ssh/下是否存在id_rsa和id_rsa.pub文件,如果沒有的話澡腾,可以通過:
ssh-keygen -t rsa
進(jìn)行生成沸伏。如果沒有~/.ssh/文件夾,需要先手動創(chuàng)立一下动分,然后在此文件夾下操作毅糟。
為了讓系統(tǒng)接受登陸,需要將共鑰傳入authorized_keys文件:
cat id_rsa.pub >> authorized_keys
最后澜公,在MacOs下姆另,需要在設(shè)置里面打開遠(yuǎn)程登錄權(quán)限,進(jìn)入系統(tǒng)偏好設(shè)置 >> 共享 >> 遠(yuǎn)程登錄坟乾。將其設(shè)置為開啟就可以了迹辐。
通過命令行運行:
ssh localhost
exit
查看能夠登錄成功。
3.格式化namenode節(jié)點
配置的最后一步是格式化namenode節(jié)點甚侣,在命令行運行:
hdfs namenode -format
該操作會對系統(tǒng)臨時文件夾下的目錄進(jìn)行操作明吩,不會對硬盤產(chǎn)生格式化。
啟動與關(guān)閉Hadoop
進(jìn)入 /usr/local/Cellar/hadoop/xxxxxx/sbin/ 目錄
啟動調(diào)用以下腳本:
% start-dfs.sh
% start-yarn.sh
% mr-jobhistory-daemon.sh start historyserver
關(guān)閉調(diào)用以下腳本:
% mr-jobhistory-daemon.sh stop historyserver
% stop-yarn.sh
% stop-dfs.sh
程序默認(rèn)的是調(diào)用hadoop配置文件夾下的配置文件殷费,當(dāng)我們做了多個配置文件夾印荔,可以這樣啟動其他的配置模式。
% start-dfs.sh --config path-to-config-directory
% start-yarn.sh --config path-to-config-directory
% mr-jobhistory-daemon.sh --config path-to-config-directory start historyserver
狀態(tài)查看
Hadoop的運行狀態(tài)怎樣详羡?光啟動和關(guān)閉看不出什么狀況仍律,甚至都不知道有沒有啟動成功。這里有兩種方式可以驗證Hadoop的運行狀況实柠。
1.命令行jps
在命令行輸入jps水泉,可以查看到j(luò)ava進(jìn)程的,當(dāng)沒有啟動Hadoop時,只看得到j(luò)ps一個進(jìn)程茶行。如果啟動成功會多出許多進(jìn)程躯概,同樣,關(guān)閉后這些進(jìn)程就沒有了畔师。
2.網(wǎng)頁
在瀏覽器打開如下鏈接可以進(jìn)入不同的管理界面:
Resource Manager: http://localhost:50070
JobTracker: http://localhost:8088
Specific Node Information: http://localhost:8042