本節內容:java
主機名 | IP地址 | 操做系統版本 | 安裝軟件 |
hadoop16 | 172.16.206.16 | CentOS 7.2 | JDK1.七、hadoop-2.7.2 |
hadoop26 | 172.16.206.26 | CentOS 7.2 | JDK1.七、hadoop-2.7.2 |
hadoop27 | 172.16.206.27 | CentOS 7.2 | JDK1.七、hadoop-2.7.二、Zookeeper |
hadoop28 | 172.16.206.28 | CentOS 7.2 | JDK1.七、hadoop-2.7.二、Zookeeper |
hadoop29 | 172.16.206.29 | CentOS 7.2 | JDK1.七、hadoop-2.7.二、Zookeeper |
因爲機器資源緊張,將NameNode和ResourceManager安裝在一臺機器上。在hadoop16主機上安裝NameNode和ResourceManager使其處於active狀態,在hadoop26上安裝NameNode和ResourceManager使其處於standby狀態。node
環境拓撲:linux
因爲是實驗環境,因此將NameNode和ResourceManager放在了一塊兒,生產環境下應該將NameNode和ResourceManager放在單獨的機器上。shell
Hadoop2.0官方提供了兩種HDFS HA的解決方案,一種是NFS,另外一種是QJM。這兩種共享數據的方案,NFS是操做系統層面的,JournalNode是hadoop層面的,這裏咱們使用簡單的QJM集羣進行數據共享。在該方案中,主備NameNode之間經過一組JournalNode同步元數據信息,一條數據只要成功寫入多數JournalNode即認爲寫入成功。一般配置奇數個JournalNode。apache
另外還配置了一個zookeeper集羣(27,28,29主機),用於ZKFC(DFSZKFailoverController)故障轉移,當Active NameNode掛掉了,會自動切換Standby NameNode和ResourceManager爲standby狀態。同時27,28,29主機做爲DataNode節點。bootstrap
在集羣各節點,編輯hosts文件,配置好各節點主機名和ip地址的對應關係:vim
# vim /etc/hosts 172.16.206.16 hadoop16 172.16.206.26 hadoop26 172.16.206.27 hadoop27 172.16.206.28 hadoop28 172.16.206.29 hadoop29
Hadoop Java Versions
Version 2.7 and later of Apache Hadoop requires Java 7. It is built and tested on both OpenJDK and Oracle (HotSpot)'s JDK/JRE. <br />
Earlier versions (2.6 and earlier) support Java 6.centos
# mkdir /usr/java # tar zxf /usr/local/jdk-7u80-linux-x64.gz -C /usr/java/ # vim /etc/profile export JAVA_HOME=/usr/java/jdk1.7.0_80 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar # source /etc/profile
對於Redhat/CentOS系列的,安裝系統時通常都會默認安裝openssh軟件,裏面包含了ssh客戶端和ssh服務端,因此先檢查下這個軟件包是否安裝了:api
# yum list all openssh
若是沒有安裝,安裝:bash
# yum install -y openssh
在檢查rsync軟件包是否安裝:
# yum list all rsync
採用NTP(Network Time Protocol)方式來實現, 選擇一臺機器, 做爲集羣的時間同步服務器, 而後分別配置服務端和集羣其餘機器。我這裏以hadoop16機器時間爲準,其餘機器同這臺機器時間作同步。
1. NTP服務端
(1)安裝ntp服務
# yum install ntp -y
(2)配置/etc/ntp.conf,這邊採用本地機器做爲時間的原點
註釋server列表:
server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst
添加以下內容:
server 127.127.1.0 prefer fudge 127.127.1.0 stratum 8 logfile /var/log/ntp.log
(3)啓動ntpd服務
# systemctl start ntpd
(4)查看ntp服務狀態
# systemctl status ntpd
(5)加入開機啓動
# systemctl enable ntpd
2. NTP客戶端
(1)安裝ntp
# yum install ntpdate
(2)配置crontab任務主動同步
# crontab -e */10 * * * * /usr/sbin/ntpdate 172.16.206.16;hwclock -w
對於Zookeeper集羣的話,官方推薦的最小節點數爲3個。
1. 安裝配置zk
(1)配置zk節點的hosts文件
配置zk節點的hosts文件:配置3臺機器的ip地址和主機名的對應關係。上面已經作過了。這裏選擇3檯安裝zk:hadoop27,hadoop28,hadoop29。
(2)解壓安裝配置第一臺zk
# cd /usr/local/ # tar zxf zookeeper-3.4.6.tar.gz # cd zookeeper-3.4.6 建立快照日誌存放目錄: # mkdir dataDir 建立事務日誌存放目錄: # mkdir dataLogDir
注意:若是不配置dataLogDir,那麼事務日誌也會寫在dataDir目錄中。這樣會嚴重影響zk的性能。由於在zk吞吐量很高的時候,產生的事務日誌和快照日誌太多。
# cd conf # mv zoo_sample.cfg zoo.cfg # vim zoo.cfg # 存放數據文件 dataDir=/usr/local/zookeeper-3.4.6/dataDir # 存放日誌文件 dataLogDir=/usr/local/zookeeper-3.4.6/dataLogDir # zookeeper cluster,2888爲選舉端口,3888爲心跳端口 server.1=hadoop27:2888:3888 server.2=hadoop28:2888:3888 server.3=hadoop29:2888:3888
在咱們配置的dataDir指定的目錄下面,建立一個myid文件,裏面內容爲一個數字,用來標識當前主機,conf/zoo.cfg文件中配置的server.X中X爲何數字,則myid文件中就輸入這個數字:
hadoop27主機:
# echo "1" > /usr/local/zookeeper-3.4.6/dataDir/myid
(3)遠程複製第一臺的zk到另外兩臺上,並修改myid文件爲2和3
# cd /usr/local/ # scp -rp zookeeper-3.4.6 root@172.16.206.28:/usr/local/ # echo "2" > /usr/local/zookeeper-3.4.6/dataDir/myid # scp -rp zookeeper-3.4.6 root@172.16.206.29:/usr/local/ # echo "3" > /usr/local/zookeeper-3.4.6/dataDir/myid
2. 啓動和關閉Zookeeper
在ZooKeeper集羣的每一個結點上,執行啓動ZooKeeper服務的腳本,以下所示:
[root@hadoop27 ~]# /usr/local/zookeeper-3.4.6/bin/zkServer.sh start [root@hadoop28 ~]# /usr/local/zookeeper-3.4.6/bin/zkServer.sh start [root@hadoop29 ~]# /usr/local/zookeeper-3.4.6/bin/zkServer.sh start
中止zk的命令:
# /usr/local/zookeeper-3.4.6/bin/zkServer.sh stop
3. 測試zk集羣
能夠經過ZooKeeper的腳原本查看啓動狀態,包括集羣中各個結點的角色(或是Leader,或是Follower):
[root@hadoop27 ~]# /usr/local/zookeeper-3.4.6/bin/zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg Mode: follower [root@hadoop28 ~]# /usr/local/zookeeper-3.4.6/bin/zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg Mode: leader [root@hadoop29 ~]# /usr/local/zookeeper-3.4.6/bin/zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg Mode: follower
經過上面狀態查詢結果可見,hadoop28是集羣的Leader,其他的兩個結點是Follower。
另外,能夠經過客戶端腳本,鏈接到ZooKeeper集羣上。對於客戶端來講,ZooKeeper是一個總體,鏈接到ZooKeeper集羣實際上感受在獨享整個集羣的服務,因此,你能夠在任何一個結點上創建到服務集羣的鏈接。
[root@hadoop29 ~]# /usr/local/zookeeper-3.4.6/bin/zkCli.sh -server hadoop27:2181 Connecting to localhost:2181 2016-07-18 21:26:57,647 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT 2016-07-18 21:26:57,650 [myid:] - INFO [main:Environment@100] - Client environment:host.name=hadoop29 2016-07-18 21:26:57,650 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_80 2016-07-18 21:26:57,652 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2016-07-18 21:26:57,652 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/java/jdk1.7.0_80/jre 2016-07-18 21:26:57,652 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper-3.4.6/bin/../build/classes:/usr/local/zookeeper-3.4.6/bin/../build/lib/*.jar:/usr/local/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.4.6/bin/../conf:.:/usr/java/jdk1.7.0_80/lib/dt.jar:/usr/java/jdk1.7.0_80/lib/tools.jar 2016-07-18 21:26:57,652 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2016-07-18 21:26:57,653 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2016-07-18 21:26:57,653 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2016-07-18 21:26:57,653 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2016-07-18 21:26:57,653 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2016-07-18 21:26:57,653 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-431.el6.x86_64 2016-07-18 21:26:57,653 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2016-07-18 21:26:57,653 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2016-07-18 21:26:57,653 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/root 2016-07-18 21:26:57,654 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@279ac931 [root@hadoop29 ~]# /usr/local/zookeeper-3.4.6/bin/zkCli.sh -server hadoop27:2181 Connecting to hadoop27:2181 2016-07-18 21:29:48,216 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT 2016-07-18 21:29:48,219 [myid:] - INFO [main:Environment@100] - Client environment:host.name=hadoop29 2016-07-18 21:29:48,219 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.7.0_80 2016-07-18 21:29:48,221 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2016-07-18 21:29:48,221 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/java/jdk1.7.0_80/jre 2016-07-18 21:29:48,221 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper-3.4.6/bin/../build/classes:/usr/local/zookeeper-3.4.6/bin/../build/lib/*.jar:/usr/local/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/usr/local/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/usr/local/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/usr/local/zookeeper-3.4.6/bin/../conf:.:/usr/java/jdk1.7.0_80/lib/dt.jar:/usr/java/jdk1.7.0_80/lib/tools.jar 2016-07-18 21:29:48,221 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2016-07-18 21:29:48,221 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2016-07-18 21:29:48,221 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2016-07-18 21:29:48,221 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2016-07-18 21:29:48,221 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2016-07-18 21:29:48,222 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-431.el6.x86_64 2016-07-18 21:29:48,222 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2016-07-18 21:29:48,222 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2016-07-18 21:29:48,222 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/root 2016-07-18 21:29:48,223 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=hadoop27:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@194d62f1 Welcome to ZooKeeper! 2016-07-18 21:29:48,245 [myid:] - INFO [main-SendThread(hadoop27:2181):ClientCnxn$SendThread@975] - Opening socket connection to server hadoop27/172.16.206.27:2181. Will not attempt to authenticate using SASL (unknown error) 2016-07-18 21:29:48,249 [myid:] - INFO [main-SendThread(hadoop27:2181):ClientCnxn$SendThread@852] - Socket connection established to hadoop27/172.16.206.27:2181, initiating session JLine support is enabled [zk: hadoop27:2181(CONNECTING) 0] 2016-07-18 21:29:48,356 [myid:] - INFO [main-SendThread(hadoop27:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server hadoop27/172.16.206.27:2181, sessionid = 0x155fc2e082e0000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: hadoop27:2181(CONNECTED) 0]
輸入quit,能夠退出。
4. 腳本按期清理zk快照和日誌文件
正常運行過程當中,ZK會不斷地把快照數據和事務日誌輸出到dataDir和dataLogDir這兩個目錄,而且若是沒有人爲操做的話,ZK本身是不會清理這些文件的。
我這裏採用腳本切割。將腳本上傳到/usr/local/zookeeper-3.4.6/目錄下。腳本內容以下:
#!/bin/bash ###Description:This script is used to clear zookeeper snapshot file and transaction logs. ###Written by: jkzhao - jkzhao@wisedu.com ###History: 2016-04-08 First release. # Snapshot file dir. dataDir=/usr/local/zookeeper-3.4.6/dataDir/version-2 # Transaction logs dir. dataLogDir=/usr/local/zookeeper-3.4.6/dataLogDir/version-2 # Reserved 5 files. COUNT=5 ls -t $dataDir/snapshot.* | tail -n +$[$COUNT+1] | xargs rm -f ls -t $dataLogDir/log.* | tail -n +$[$COUNT+1] | xargs rm -f
# chmod +x clean_zklog.sh
# crontab -e 0 0 * * 0 /usr/local/zookeeper-3.4.6/clean_zklog.sh
全部zk節點都得配置腳本和週期性任務。
# groupadd hadoop # useradd -g hadoop hadoop # echo "wisedu" | passwd --stdin hadoop &> /dev/null
全部節點都得添加hadoop用戶。
這裏的主節點指的是NameNode,ResourceManager。配置hadoop16主機(Active)登陸hadoop16,hadoop26,hadoop27,hadoop28,hadoop29主機免密碼。還要配置hadoop26主機(Standby)登陸hadoop16,hadoop26,hadoop27,hadoop28,hadoop29主機免密碼。 (也能夠不配置,每一個節點一個一個啓動服務,最好不要這樣作)。
hadoop用戶登陸shell:
1. 配置hadoop16主機(Active)登陸hadoop16,hadoop26,hadoop27,hadoop28,hadoop29主機免密碼
[hadoop@hadoop16 ~]$ ssh-keygen -t rsa -P '' [hadoop@hadoop16 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop16 [hadoop@hadoop16 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop26 [hadoop@hadoop16 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop27 [hadoop@hadoop16 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop28 [hadoop@hadoop16 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop29
2. 配置hadoop26主機(Standby)登陸hadoop16,hadoop26,hadoop27,hadoop28,hadoop29主機免密碼
[hadoop@hadoop26 ~]$ ssh-keygen -t rsa -P '' [hadoop@hadoop26 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop16 [hadoop@hadoop26 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop26 [hadoop@hadoop26 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop27 [hadoop@hadoop26 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop28 [hadoop@hadoop26 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@hadoop29
1. 安裝配置master節點(hadoop16主機)
(1)將安裝包上傳至/usr/local目錄下並解壓
[root@hadoop16 ~]# cd /usr/local/ [root@hadoop16 local]# tar zxf hadoop-2.7.2.tar.gz [root@hadoop16 local]# ln -sv hadoop-2.7.2 hadoop [root@hadoop16 local]# cd hadoop [root@hadoop16 hadoop]# mkdir logs [root@hadoop16 hadoop]# chmod g+w logs [root@hadoop16 hadoop]# chown -R hadoop:hadoop ./* [root@hadoop16 hadoop]# chown -R hadoop:hadoop /usr/local/hadoop-2.7.2
(2)配置hadoop環境變量
[root@hadoop16 hadoop]# vim /etc/profile # HADOOP export HADOOP_HOME=/usr/local/hadoop export PATH=$PATH:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin
(3)修改文件hadoop-env.sh
Hadoop的各守護進程依賴於JAVA_HOME環境變量,可在這兩個文件中配置特定的JAVA環境。此處僅須要修改hadoop-env.sh文件。此外,Hadoop大多數守護進程默認使用的堆大小爲1GB,但現實應用中,可能須要對其各種進程的堆內存大小作出調整,這隻須要編輯這兩個文件中的相關環境變量值便可,例如HADOOP_HEAPSIZE、HADOOP_JOB_HISTORY_HEAPSIZE、JAVA_HEAP_SIZE和YARN_HEAP_SIZE等。
hadoop用戶登陸shell,或者root用戶登陸,su - hadoop。
[hadoop@hadoop16 ~]$ vim /usr/local/hadoop/etc/hadoop/hadoop-env.sh
(4)修改配置文件
hadoop用戶登陸shell,或者root用戶登陸,su - hadoop。
[hadoop@hadoop16 ~]$ cd /usr/local/hadoop/etc/hadoop/
修改core-site.xml:該文件包含了NameNode主機地址以及其監聽RPC端口等信息,對於僞分佈式模式的安裝來講,其主機地址是localhost;對於徹底分佈式中master節點的主機名稱或者ip地址;若是配置NameNode是HA,指定HDFS的nameservice爲一個自定義名稱,而後在hdfs-site.xml配置NameNode節點的主機信息。NameNode默認的RPC端口是8020。
<configuration> <!-- 指定hdfs的nameservice爲ns1 --> <property> <name>fs.defaultFS</name> <value>hdfs://ns1</value> </property> <!-- 指定hadoop臨時目錄 --> <property> <name>hadoop.tmp.dir</name> <value>/usr/local/hadoop/tmp</value> </property> <!-- 指定zookeeper地址 --> <property> <name>ha.zookeeper.quorum</name> <value>hadoop27:2181,hadoop28:2181,hadoop29:2181</value> </property> </configuration>
修改hdfs-site.xml:該文件主要用於配置HDFS相關的屬性,例如複製因子(即數據塊的副本數)、NN和DN用於存儲數據的目錄等。數據塊的副本數對於僞分佈式的Hadoop應該爲1,徹底分佈式模式下默認數據副本是3份。在這個配置文件中還能夠配置NN和DN用於存儲的數據的目錄。
<configuration> <!--指定hdfs的nameservice爲ns1,須要和core-site.xml中的保持一致 --> <property> <name>dfs.nameservices</name> <value>ns1</value> </property> <!-- ns1下面有兩個NameNode,分別是nn1,nn2 --> <property> <name>dfs.ha.namenodes.ns1</name> <value>nn1,nn2</value> </property> <!-- nn1的RPC通訊地址 --> <property> <name>dfs.namenode.rpc-address.ns1.nn1</name> <value>hadoop16:9000</value> </property> <!-- nn1的http通訊地址 --> <property> <name>dfs.namenode.http-address.ns1.nn1</name> <value>hadoop16:50070</value> </property> <!-- nn2的RPC通訊地址 --> <property> <name>dfs.namenode.rpc-address.ns1.nn2</name> <value>hadoop26:9000</value> </property> <!-- nn2的http通訊地址 --> <property> <name>dfs.namenode.http-address.ns1.nn2</name> <value>hadoop26:50070</value> </property> <!-- 指定NameNode的元數據在JournalNode上的存放位置 --> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://hadoop27:8485;hadoop28:8485;hadoop29:8485/ns1</value> </property> <!-- 指定JournalNode在本地磁盤存放數據的位置 --> <property> <name>dfs.journalnode.edits.dir</name> <value>/usr/local/hadoop/journaldata</value> </property> <!-- 開啓NameNode失敗自動切換 --> <property> <name>dfs.ha.automatic-failover.enabled</name> <value>true</value> </property> <!-- 配置失敗自動切換實現方式 --> <property> <name>dfs.client.failover.proxy.provider.ns1</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> <!-- 配置隔離機制方法,多個機制用換行分割,即每一個機制暫用一行--> <property> <name>dfs.ha.fencing.methods</name> <value> sshfence shell(/bin/true) </value> </property> <!-- 使用sshfence隔離機制時須要ssh免登錄 --> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/home/hadoop/.ssh/id_rsa</value> </property> <!-- 配置sshfence隔離機制超時時間 --> <property> <name>dfs.ha.fencing.ssh.connect-timeout</name> <value>30000</value> </property> </configuration>
注意:若是須要其它用戶對hdfs有寫入權限,還須要在hdfs-site.xml添加一項屬性定義。
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
修改mapred-site.xml:該文件用於配置集羣的MapReduce framework,此處應該指定yarn,另外的可用值還有local和classic。mapred-site.xml默認是不存在,但有模塊文件mapred-site.xml.template,只須要將其複製mapred-site.xml便可。
[hadoop@hadoop16 hadoop]$ cp mapred-site.xml.template mapred-site.xml [hadoop@hadoop16 hadoop]$ vim mapred-site.xml <configuration> <!-- 指定mr框架爲yarn方式 --> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration>
修改yarn-site.xml:該文件用於配置YARN進程及YARN的相關屬性。首先須要指定ResourceManager守護進程的主機和監聽的端口,對於僞分佈式模型來來說,其主機爲localhost,默認的端口是8032;其次須要指定ResourceManager使用的scheduler,以及NodeManager的輔助服務。
<configuration> <!-- 開啓RM高可用 --> <property> <name>yarn.resourcemanager.ha.enabled</name> <value>true</value> </property> <!-- 指定RM的cluster id --> <property> <name>yarn.resourcemanager.cluster-id</name> <value>yrc</value> </property> <!-- 指定RM的名字 --> <property> <name>yarn.resourcemanager.ha.rm-ids</name> <value>rm1,rm2</value> </property> <!-- 分別指定RM的地址 --> <property> <name>yarn.resourcemanager.hostname.rm1</name> <value>hadoop16</value> </property> <property> <name>yarn.resourcemanager.hostname.rm2</name> <value>hadoop26</value> </property> <!-- 指定zk集羣地址 --> <property> <name>yarn.resourcemanager.zk-address</name> <value>hadoop27:2181,hadoop28:2181,hadoop29:2181</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> </configuration>
修改slaves:該文件存儲了當前集羣的全部slave節點的列表,對於僞分佈式模型,其文件內容僅應該是你localhost,這也的確是這個文件的默認值。
[hadoop@hadoop16 hadoop]$ vim slaves
hadoop27
hadoop28
hadoop29
Hadoop啓動後,會把進程的PID號存儲在一個文件中,這樣執行stop-dfs腳本時就能夠按照進程PID去關閉進程了。而這個默認路徑就是/tmp,/tmp目錄下的文件系統會按期清理,因此須要修改pid存放的路徑:
[hadoop@hadoop16 ~]$ cd /usr/local/hadoop/sbin/ [hadoop@hadoop16 sbin]$ vim hadoop-daemon.sh HADOOP_PID_DIR=/usr/local/hadoop
[hadoop@hadoop16 ~]$ cd /usr/local/hadoop/sbin/ [hadoop@hadoop16 sbin]$ vim yarn-daemon.sh YARN_PID_DIR=/usr/local/hadoop
【注意】:每一個節點的這兩個文件都得修改。
(5)安裝配置其餘節點
這裏因爲實驗節點數目少,沒有使用ansible等自動化工具。
重複操做解壓、配置環境變量,參照前面。
Hadoop集羣的各節點配置文件都是同樣的,咱們能夠將master節點上的配置文件scp到其餘節點上:
[hadoop@hadoop16 ~]$ scp -p /usr/local/hadoop/etc/hadoop/* hadoop@hadoop26:/usr/local/hadoop/etc/hadoop/ [hadoop@hadoop16 ~]$ scp -p /usr/local/hadoop/etc/hadoop/* hadoop@hadoop27:/usr/local/hadoop/etc/hadoop/ [hadoop@hadoop16 ~]$ scp -p /usr/local/hadoop/etc/hadoop/* hadoop@hadoop28:/usr/local/hadoop/etc/hadoop/ [hadoop@hadoop16 ~]$ scp -p /usr/local/hadoop/etc/hadoop/* hadoop@hadoop29:/usr/local/hadoop/etc/hadoop/
注意:請嚴格按照下面的步驟啓動。
1. 啓動Zookeeper集羣
分別在hadoop2七、hadoop2八、hadoop29上啓動zk,前面已經啓動好了,再也不重複。
2. 啓動journalnode
hadoop用戶登陸shell,分別在在hadoop2七、hadoop2八、hadoop29上執行:
[hadoop@hadoop27 ~]$ /usr/local/hadoop/sbin/hadoop-daemon.sh start journalnode
運行jps命令檢驗,hadoop2七、hadoop2八、hadoop29上多了JournalNode進程。
3. 格式化HDFS
在HDFS的NN啓動以前須要先初始化其用於存儲數據的目錄,能夠在hdfs-site.xml配置文件中使用dfs.namenode.name.dir屬性定義HDFS元數據持久存儲路徑,默認爲${hadoop.tmp.dir}/dfs/name,這裏是存放在JournalNode中;dfs.datanode.data.dir屬性定義DataNode用於存儲數據塊的目錄路徑,默認爲${hadoop.tmp.dir}/dfs/data。若是指定的目錄不存在,格式化命令會自動建立之;若是事先存在,請確保其權限設置正確,此時格式化操做會清除其內部的全部數據並從新創建一個新的文件系統。
在hadoop16(Active)上執行命令:
[hadoop@hadoop16 ~]$ hdfs namenode -format
格式化後會在根據core-site.xml中的hadoop.tmp.dir配置生成個文件,這裏我配置的是/usr/local/hadoop/tmp。
啓動hadoop16主機上的NameNode:
[hadoop@hadoop16 ~]$ hadoop-daemon.sh start namenode
而後在hadoop26(Standby)主機上執行以下命令,同步hadoop16主機上的NameNode元數據信息:
[hadoop@hadoop26 ~]$ hdfs namenode –bootstrapStandby
同步完成後,中止hadoop16主機上的NameNode:
[hadoop@hadoop16 ~]$ hadoop-daemon.sh stop namenode
這裏若是不啓動Active的NameNode,就在Standby主機上同步,會報以下的錯誤:
這是由於沒有啓動active namenode,由於standby namenode是經過active namenode的9000端口通信的。若active namenode沒有啓動,則9000沒有程序監聽提供服務。
固然也能夠不啓動Active NameNode就進行同步元數據信息,就是直接用命令拷貝Active主機上的元數據信息目錄到Standby主機上,可是不建議這麼作:
[hadoop@hadoop16 hadoop]$ scp -r tmp/ hadoop@hadoop26:/usr/local/hadoop
4. 啓動HDFS(在hadoop16上執行)
[hadoop@hadoop16 ~]$ /usr/local/hadoop/sbin/start-dfs.sh
能夠在各主機執行jps,查看啓動的進程:
5. 啓動YARN
注意:仍是在hadoop16上執行start-yarn.sh,這是由於沒有把namenode和resourcemanager分開,生產環境須要把他們分開,他們分開了就要分別在不一樣的機器上啓動。
啓動yarn(在hadoop16上):
[hadoop@hadoop16 ~]$ /usr/local/hadoop/sbin/start-yarn.sh
啓動yarn standby(在hadoop26上):
[hadoop@hadoop26 ~]$ /usr/local/hadoop/sbin/yarn-daemon.sh start resourcemanager
中止HDFS集羣:
[hadoop@hadoop16 ~]$ stop-dfs.sh
中止YARN集羣:
[hadoop@hadoop16 ~]$ stop-yarn.sh
中止ResourceManager(Standby):
[hadoop@hadoop26 ~]$ yarn-daemon.sh stop resourcemanager