Hadoop2.5.0完全分布式配置(1主3從)
1、開發配置環境:
具體的就不介紹了,請參考另外一篇文章http://www.baiduhome.net/lib/view/open1409640189307.html
2、Hadoop節點配置
在講解之前,先聲明一點,這篇文章的所有環境都是基于上一篇偽分布的配置文章的基礎上再做配置的,如果你沒有看過我之前的那篇文章,建議你先去閱讀一下。
現在網上比較少新版本的配置教程,那么下面我就來分享一下我自己的實戰經驗,如有不正確的地歡迎指正 :)
首先,我們的節點信息如下:
master 192.168.8.184 slave1 192.168.8.183 slave2 192.168.8.178 slave3 192.168.8.190
我是用虛擬機做的,主節點(Master)配置好后作為模板,其他3個從節點(slave1、slave2、slave3)直接做虛擬機拷貝,其中slave1還兼任了第二namenode節點。因為主節點的配置跟從節點的配置是完全一樣的,拷貝完后只需要做兩件事:修改hostname、重新生成SSH無口令登陸的KEY。拷貝完成后啟動如果網絡有問題,直接百度谷歌就行了。關于修改hostname對應上面的IP修改成相應的名稱就可以了,如192.168.8.184修改成master。而用戶名、密碼完全可以不需要修改,當然你要改也是沒有問題的,節點多了不好記哦。首先,我們先來講一下配置,一共要配置6個文件,分別是core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml、masters、slaves,其中masters文件可能會在配置目錄下不存在,自己新建一個就可以了,詳細配置如下:
core-site.xml:
<configuration> <property> <name>fs.defaultFS</name> <value>hdfs://192.168.8.184:9000</value> <description>same as fs.default.name</description> </property> <property> <name>hadoop.tmp.dir</name> <value>/usr/mywind/tmp</value> <description>A base for other temporary directories.</description> </property> </configuration>
hdfs-site.xml:
<configuration> <property> <name>dfs.namenode.name.dir</name> <value>/usr/mywind/name</value> <description>same as dfs.name.dir</description> </property> <property> <name>dfs.datanode.data.dir</name> <value>/usr/mywind/data</value> <description>Comma separated list of paths on the local filesystem of a DataNode where it should store its blocks.If this is a comma-delimited list of directories, then data will be stored in all named directories, typically on different devices.</description> </property> <property> <name>dfs.blocksize</name> <value>268435456</value> <description>HDFS blocksize of 256MB for large file-systems.</description> </property> <property> <name>dfs.namenode.http-address</name> <value>master:50070</value> <description>The address and the base port where the dfs namenode web ui will listen on.</description> </property> <property> <name>dfs.namenode.secondary.http-address</name> <value>slave1:50090</value> <description>The secondary namenode http server address and port.</description> </property> <property> <name>dfs.replication</name> <value>3</value> <description>same as old frame,recommend set the value as the cluster DataNode host numbers!</description> </property> </configuration>
mapred-site.xml:
<configuration> <!--Configurations for MapReduce Applications --> <property> <name>mapreduce.framework.name</name> <value>yarn</value> <description>Execution framework set to Hadoop YARN.</description> </property><!--Configurations for MapReduce JobHistory Server --> <property> <name>mapreduce.jobhistory.address</name> <value>master:10020</value> <description>MapReduce JobHistory Server host:port.Default port is 10020.</description> </property> <property> <name>mapreduce.jobhistory.webapp.address</name> <value>master:19888</value> <description>MapReduce JobHistory Server Web UI host:port.Default port is 19888.</description> </property>
</configuration></pre>
yarn-site.xml:
<configuration> <!-- Configurations for ResourceManager --> <property> <name>yarn.resourcemanager.address</name> <value>master:8032</value> </property> <property> <name>yarn.resourcemanager.scheduler.address</name> <value>master:8030</value> </property> <property> <name>yarn.resourcemanager.resource-tracker.address</name> <value>master:8031</value> </property> <property> <name>yarn.resourcemanager.admin.address</name> <value>master:8033</value> </property> <property> <name>yarn.resourcemanager.webapp.address</name> <value>master:8088</value> </property><!-- Configurations for NodeManager --> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> <description>Configuration to enable or disable log aggregation.Shuffle service that needs to be set for Map Reduce applications.</description> </property> <property> <name>yarn.nodemanager.aux-services.mapreduce_shuffle.class</name> <value>org.apache.hadoop.mapred.ShuffleHandler</value> </property> </configuration></pre>
masters:
master
slaves:
slave1 slave2 slave3
具體每個參數代表什么意思,直接查官網或者看description信息就可以知道了,根據你自己實際的情況去修改就可以了。我們配置的時候主要是配置了NameNode、DataNode、ResourceManager、Map/Reduce 的JobHistory Server,配置上我已經有注釋加以說明了,看起來會更清晰明了。這里或許有人會疑問,上面的配置好像只指定了NameNode、Secondary NameNode 的,沒有指定DataNode的信息,其實對于DataNode而言,它只需要知道自己從屬哪個NameNode節點就可以了,通過masters、slaves文件可以清晰地定義清楚它們之間的關系,不需要更多的配置,在啟動主節點的時候,主節點會根據這兩個文件定義的關系去啟動子節點(當然,他們之間要實現無口令連接通訊才行)。下面要講解一下SSH的無口令登陸設置。由于從節點(slave1、slave2、slave3)是在主節點那邊直接拷貝過來的,建議重新生成一下KEY:
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
從節點(slave1、slave2、slave3)執行上面的命令重新生成完KEY之后,主節點需要與從節點建立無密碼登陸,那么,就需要把主節點的KEY添加到從節點的授權列表中,這樣主節點才能不需要輸入密碼的情況下連接訪問從節點。步驟如下:
1. 把主節點的公鑰復制到從節點中。
2. 從節點把主節點的公鑰寫入授權列表。
首先,在主節點中切換到/home/a01513目錄下(注意:a01513是我的操作系統用戶名,實際名稱根據你系統的用戶名改成相應的名稱就可以了):
cd /home/a01513然后復制,這里我以slave1節點為例:
scp ~/.ssh/id_rsa.pub a01513@192.168.8.183:/home/a01513/
這里可能要你輸入slave1(192.168.8.183)的主機密碼,輸入就可以了,輸入完成后到slave1節點終端輸入以下命令把主節點的公鑰復制到授權列表:
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys回到主節點終端中輸入:
ssh slave1
如果不需要輸入密碼就連接成功的話,證明你配置對了,恭喜!
如果上面的步驟完成了,那么下面進行格式化文件系統:
hdfs namenode -format
然后啟動HDFS、YARN、JobHistory進程:
start-dfs.sh start-yarn.sh
![]()
注意舊版本的start-all.sh已經被上面兩個腳本替代了,不過好像這命令還可能用,建議還是用上面兩個吧。
mr-jobhistory-daemon.sh start historyserver
關閉也很簡單:
stop-dfs.sh stop-yarn.sh mr-jobhistory-daemon.sh stop historyserver
![]()
至此,我們的完全分布式配置已經大功告成!
來自:http://my.oschina.net/lanzp/blog/347437