第四課:Yarn和Map/Reduce配置啟動和原理講解
前三節課主要講了hdfs,hdfs就是一個分魚展的大硬盤
分:分塊
魚:冗余
展:動態擴展
接下來講雲計算,也可以理解為分布式計算,其設計原則:
移動計算,而不是移動數據
前面說過,hadoop由hdfs,yarn,map/reduce組成,
而yarn(Yet Another Resource Negotiator)是資源調度系統,yarn調配的是內存和cpu,不參入計算。
map/reduce是計算引擎。
(1)配置yarn
yarn由一臺resourceManager和n臺dataManager組成,resourceManager管理著n臺dataManager,
resourceManager原則上應該和namenode分開,單獨在一個節點上,現在是在做實驗,為了演示方便,
才放在一起的,而dataManager可以和datanode放在一起,這樣dataManager和數據離的近一點,
當然也可以不放在一起。
要啟動yarn系統,需要先配置一些參數:
a)配置yarn-size.xml
resourceManager和dataManager每一個節點都需要配置yarn-size.xml,配置如下:
<?xml version="1.0"?> <configuration> <property> <name>yarn.resourcemanager.hostname</name> <value>master</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name> <value>org.apache.hadoop.mapred.ShuffleHandler</value> </property> </configuration>
b) 配置mapred-site.xml
只需要在master的/usr/local/hadoop/etc/hadoop目錄下,
復制mapred-site.xml.template,即執行命令
[root@master hadoop]# cp mapred-site.xml.template mapred-site.xml
編輯mapred-site.xml,vim mapred-site.xml:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration>
這是配置map/reduce在哪個系統上運行,這裏配置的yarn,也可以配置其他的。
(2)啟動yarn
[root@master hadoop]# start-yarn.sh
使用jps查看啟動情況
啟動成功後,可在瀏覽器上查看web界面
(3)運行一個map/reduce示例程序
要先把hdfs也啟動起來:
[root@master hadoop]# start-dfs.sh
上傳一個文件到hdfs的/input目錄上
#在namenode的根目錄上創建input目錄 [root@master hadoop]# hadoop fs -mkdir /input #上傳一個測試文件到hadoop的/input目錄上 [root@master hadoop]# hadoop fs -put /root/input.txt /input
input.txt的內容如下:
find /usr/local/hadoop -name *example*.jar 查找示例程序文件
通過hadoop jar xxx.jar wordcount /input /output來運行示例程序
執行結果為:
第四課:Yarn和Map/Reduce配置啟動和原理講解