1.1、服務器規劃java
Hadoop2 HA Cluster | |||||
Host | IP | NameNode | JournalNode | FailoverController | DataNode |
nn1 | 192.168.50.221 | Y | Y | Y | N |
nn2 | 192.168.50.222 | Y | Y | Y | N |
dn1 | 192.168.50.225 | N | Y |
N | Y |
dn2 | 192.168.50.226 | N | N | N | Y |
dn3 | 192.168.50.227 | N | N | N | Y |
ZooKeeper機器部署,請看ZooKeeper哪一篇,作HADOOP的HA,須要提早部署ZKnode
1.2、軟件版本web
Linux: CentOS2.6.32-431.el6.x86_64shell
Hadoop:2.6.0(建議升級爲2.7.1+)express
ZooKeeper:3.4.6apache
JDK/JRE: 1.7.0_75 (64bit)bootstrap
第一步臨時修改vim
#hostname nn1安全
第二步修改永久修改,防止下次重啓後被重置服務器
修改/etc/sysconfig/network中的hostname
NETWORKING=yes
HOSTNAME= NameNode1
第三步作DNS映射,能夠直接訪問主機名則訪問的部本機IP地址
修改/etc/hosts文件
在最後增長一行,如
192.168.50.221 nn1
第四步重啓電腦
重啓後,ping nn1
若是能ping成功則配置完成
其餘機器依次配置便可
命令:service iptables stop
同時關閉防火牆自啓動服務:chkconfig iptables off
查看是否關閉了自啓動:chkconfig --list | grep iptables ,若是所有是off則表示都關閉了
查看狀態:service iptables status
# service iptables status
Firewall is stopped.
3、設置ssh
修改/etc/ssh/sshd_config root賬戶修改
#vim /etc/ssh/sshd_config
取消以下注釋
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
修改後,重啓ssh: service sshd restart
切換到普通用戶下進行設置
生成SSH通信密鑰,有這個證書後,hadoop啓動時就能夠免密碼登陸了
a、先在每臺機器上面執行ssh-keygen -t rsa -P "",密碼都爲空,主要是每次hadoop啓動時須要認證,若是有密碼每次都須要輸入,實在麻煩,因此密碼留空,回車便可,執行後,將產生兩個文件,位於~/.ssh文件夾中
b、而後相互執行 ssh-copy-id userName@machineName,此功能能夠快速把本身的公鑰發給對方,並自動追加
[root@nn1 ~]# ssh nn1
進入後,exit退出SSH便可
這裏注意,有時候仍是須要你輸入密碼,這裏有多是authorized_keys的權限問題,咱們進一步設置權限,chmod 600 authorized_keys便可
若是對於其餘計算機則須要把你的公鑰發送給對方,你就能夠無密碼登陸了,認證了
參見:《Zookeeper部署文檔.doc》
3.1、初始化系統配置
3.1.1、建立應用賬戶和組(可選,建議新建一個專門的用戶)
爲了系統安全建議每一個對外應用都建立單獨的賬戶和組,具體建立方法請網上搜索。
#新建組
[root@nn2 ~]# groupadd bdata
#添加用戶和分組
[root@nn2 ~]# useradd -g bdata bdata
#設置密碼
[root@nn2 ~]# passwd bdata
Changing password for user bdata.
New password:
BAD PASSWORD: it does not contain enough DIFFERENT characters
BAD PASSWORD: is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
3.1.2、修改hosts映射
#vim /etc/hosts
192.168.50.221 nn1
192.168.50.222 nn2
192.168.50.223 HMaster1
192.168.50.224 HMaster2
192.168.50.225 dn1
192.168.50.226 dn2
192.168.50.227 dn3
192.168.50.225 jn1
192.168.50.226 jn2
192.168.50.227 jn3
192.168.50.228 Zookeeper1
192.168.50.229 Zookeeper2
192.168.50.230 Zookeeper3
3.1.2、安裝JDK/JRE
HADOOP2是使用JAVA語言開發的軟件,因此必需要安裝JRE或JDK才能夠運行,爲了測試方便建議安裝JDK(生產環境安裝JRE便可),JDK安裝步驟(略)
3.2、安裝HADOOP2
3.2.1、單機安裝HADOOP2
下載地址:
http://mirrors.cnnic.cn/apache/hadoop/common/hadoop-2.6.0/hadoop-2.6.0.tar.gz
官方提供的發佈包是基於32位系統編譯的,Hadoop依賴的so庫也是32位版本,所以在64位操做系統部署會提示一些警告信息,建議下載源碼包自行編譯64位版本HADOOP2。
配置環境變動
export HADOOP_HOME=/hom/bdata/software/hadoop-2.6.0
export PATH=.:$PATH:$HADOOP_HOME/bin
配置$HADOOP_HOME/etc/hadoop/core-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<!-- 配置HDFS集羣名稱及HDFS存儲的路徑 -->
<name>fs.defaultFS</name>
<value>hdfs://dfscluster</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/home/bdata/datadir/hadoopinfo/journal</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<!-- zookeeper集羣地址列表,以逗號分隔 -->
<value>Zookeeper1:2181,Zookeeper2:2181,Zookeeper3:2181</value>
</property>
</configuration>
配置$HADOOP_HOME/etc/hadoop/hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<!-- HDFS冗餘數量 -->
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<!-- HDFS集羣名稱,必須與core-site.xml中的名稱一致 -->
<name>dfs.nameservices</name>
<value>dfscluster</value>
</property>
<property>
<!--
dfs.ha.namenodes.[nameservices id]
hdfs namenode集羣列表
-->
<name>dfs.ha.namenodes.dfscluster</name>
<value>nn1,nn2</value>
</property>
<property>
<!--
namenode rpc端口
dfs.namenode.rpc-address.[nameservices id].[host id]
-->
<name>dfs.namenode.rpc-address.dfscluster.nn1</name>
<!-- hostname/IP -->
<value>nn1:9000</value>
</property>
<property>
<name>dfs.namenode.rpc-address.dfscluster.nn2</name>
<value>nn2:9000</value>
</property>
<property>
<!--
namenode http端口(Web後臺訪問端口)
dfs.namenode.http-address.[nameservices id].[host id]
-->
<name>dfs.namenode.http-address.dfscluster.nn1</name>
<value>nn1:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.dfscluster.nn2</name>
<value>nn2:50070</value>
</property>
<property><!-- 毫秒,最大時間,超事後客戶端會斷開和服務器的鏈接,默認1000ms,網絡很差的狀況下,能夠設置大一些 --> <name>ipc.client.connection.maxidletime </name> <value>1000</value> </property>
<!-- 客戶端鏈接重試次數(在網絡狀況很差的狀況下,有必要設置大一些,默認是10次,每次1000ms) --> <property>
<name>ipc.client.connect.max.retries</name>
<value>30</value>
</property>
<property>
<!--
QJM實現Hadoop HA
配置JournalNode集羣列表以分號分隔
qjournal://[hostname/IP:port];[hostname/IP:port]/[nameservices id]
-->
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://jn1:8485;jn2:8485;jn3:8485/dfscluster</value>
</property>
<property>
<!-- 客戶端檢查到namenode失效自動切換 -->
<name>dfs.client.failover.proxy.provider.dfscluster</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<property>
<!--
namenode切換時須要把fence standby的節點(禁止寫入EditLog)
有兩種方式實現:
1、使用Hadoop使用Java實現的方式(推薦)
2、編寫shell腳本
-->
<name>dfs.ha.fencing.methods</name>
<value>sshfence</value>
</property>
<property>
<!-- 配置本地私鑰地址(配置SSH無密碼登陸時生成的私鑰) -->
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/bdata/.ssh/id_rsa</value>
</property>
<property>
<!-- 配置sshfence超時時間單位毫秒 -->
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>10000</value>
</property>
<property>
<!-- 是否啓用Failover自動切換(true:啓用false:禁用) -->
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<property>
<!-- 指定namespace存入目錄 -->
<name>dfs.namenode.name.dir</name>
<value>/home/bdata/datadir/hadoop/name</value>
</property>
<property>
<!-- 指定datanode數據存放目錄 -->
<name>dfs.datanode.data.dir</name>
<value>/home/bdata/datadir/hadoop/data</value>
</property>
</configuration>
單節點配置,下面有HA的配置方式,若是不使用資源管理器,能夠不配置
#vim yarn-site.xml
<property>
<name>yarn.resourcemanager.hostname</name>
<value>nn1</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>nn1:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>nn1:8031</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>nn1:8032</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>nn1:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>nn1:8001</value>
</property>
YARN HA配置,若是不使用資源管理器,能夠不配置
#vim yarn-site.xml
<?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 -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
<description>啓用Yarn的HA配置方式</description>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yarn-ha</value>
<description>配置HA的集羣名稱,在ZK中顯示也爲該名稱</description>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
<description>設置HA多個RM的名稱,便於下面引用配置</description>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>nn1</value>
<description>配置rm1對應的主機</description>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>nn2</value>
<description>配置RM2對應的主機名稱</description>
</property>
<!-- 啓用RM重啓的功能-->
<property>
<name>yarn.resourcemanager.recovery.enabled</name>
<value>true</value>
<description>啓用RM重啓的功能,默認爲false</description>
</property>
<property>
<name>yarn.resourcemanager.store.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
<description>用於狀態存儲的類,採用ZK存儲狀態類</description>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>dn1:2181,dn2:2181,dn3:2181</value>
<description>因爲數據須要存儲在ZK中,經過ZK來選舉active,因此這裏須要配置ZK的地址</description>
</property>
<!-- 配置通信的地址和端口,有多少個RM就配置多少組property -->
<!-- RM1-->
<property>
<name>yarn.resourcemanager.scheduler.address.rm1</name>
<value>nn1:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address.rm1</name>
<value>nn1:8031</value>
</property>
<property>
<name>yarn.resourcemanager.address.rm1</name>
<value>nn1:8032</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address.rm1</name>
<value>nn1:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm1</name>
<value>nn1:8001</value>
<description>提供給web頁面訪問的地址,能夠查看任務情況等信息</description>
</property>
<!-- RM2 -->
<property>
<name>yarn.resourcemanager.scheduler.address.rm2</name>
<value>nn2:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address.rm2</name>
<value>nn2:8031</value>
</property>
<property>
<name>yarn.resourcemanager.address.rm2</name>
<value>nn2:8032</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address.rm2</name>
<value>nn2:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm2</name>
<value>nn2:8001</value>
</property></configuration>
添加數據從節點#vim slavesdn1dn2dn3
修改hadoop-env.sh,JAVA_HOME地址export JAVA_HOME=/usr/java/jdk1.7.0_45
3.2.2、集羣安裝Hadoop
把配置好的hadoop複製到其它節點,這裏bdata表明用戶
scp -r hadoop bdata@NameNode1:/home/bdata/stoftware/
scp -r hadoop bdata@DataNode1:/home/bdata/stoftware/
scp -r hadoop bdata@DataNode2:/home/bdata/stoftware/
scp -r hadoop bdata@DataNode3:/home/bdata/stoftware/
3.2.3、啓動Hadoop集羣
一、啓動zookeeper集羣(必須提早所有啓動)
#zkServer.sh start
二、格式化zookeeper(與zookeeper創建聯繫,只有首次啓動須要執行這一步)
# hdfs zkfc -formatZK
3、啓動全部JournalNode(首次只能單臺啓動)
#hadoop-daemon.sh start journalnode #啓動全部journalnode
4、格式化主NameNode節點
#hdfs namenode -format //在主namenode上執行格式化命令(保證zookeeper已經啓動)
5、啓動首個NameNode節點
#hadoop-daemon.sh start namenode //啓動主namenode(保證journalnode已經啓動,而且是格式化的節點上)
6、同步主NameNode數據到備NameNode上
#hdfs namenode -bootstrapStandby //備用namenode同步主namenode數據,在備節點上啓動
7、關閉HDFS集羣
#stop-dfs.sh
8、啓動HDFS集羣
#start-dfs.sh
啓動後查看相應日誌檢查啓動是否正常,也可經過JPS查看對應的進程是否啓動
單獨啓動某個進程
hadoop-daemon.sh start journalnode //啓動journalnode
hadoop-daemon.sh start namenode //啓動namenode
hadoop-daemon.sh start datanode //啓動datanode
hadoop-daemon.sh start zkfc //啓動DFSZKFailoverController
1、關閉HDFS集羣
#stop-dfs.sh
2、啓動HDFS集羣
#start-dfs.sh
1、啓動Yarn HA
主啓動全部節點,可是第二個RM節點須要手動啓動
#./start-yarn.sh
手動啓動standy的RM節點,該節點必須手動啓動
#./yarn-daemon.sh start resourcemanager
單獨啓動某一個節點的方式
RM節點
#./yarn-daemon.sh start resourcemanager
NM節點
#./yarn-daemon.sh start nodemanager
2、中止Yarn HA
主啓動全部節點,可是第二個RM節點須要手動啓動
#./stop-yarn.sh
手動啓動standy的RM節點,該節點必須手動啓動
#./yarn-daemon.sh stop resourcemanager
單獨啓動某一個節點的方式
RM節點
#./yarn-daemon.sh stop resourcemanager
NM節點
#./yarn-daemon.sh stop nodemanager
三、查看任務
yarn application -list
四、中止任務
yarn application -kill <Application ID>
五、查看狀態
yarn application -status <Application ID>
3.3、Hadoop集羣異常處理
3.3.1、啓動指定節點
集羣可能由於各類異常致使部分節點失效,須要重啓部分節點,相應命令以下:
hadoop-daemon.sh start journalnode //啓動journalnode
hadoop-daemon.sh start namenode //啓動namenode
hadoop-daemon.sh start datanode //啓動datanode
hadoop-daemon.sh start zkfc //啓動DFSZKFailoverController
3.3.2、從新格式化/清空HDFS數據及元數據(慎用)
hdfs zkfc -formatZK
hadoop-daemon.sh start journalnode #啓動全部journalnode
hdfs namenode -format //在主namenode上執行格式化命令(保證zookeeper已經啓動)
hadoop-daemon.sh start namenode //啓動主namenode(保證journalnode已經啓動)
hdfs namenode -bootstrapStandby //備用namenode同步主namenode數據
hadoop-daemon.sh start namenode //啓動備用namenode
hadoop-daemon.sh start datanode //啓動datanode