IP | hostname | 進程 |
192.168.30.141 | s141 | nn1(namenode),zkfc(DFSZKFailoverController),zk(QuorumPeerMain) |
192.168.30.142 | s142 | dn(datanode), jn(journalnode),zk(QuorumPeerMain) |
192.168.30.143 | s143 | dn(datanode), jn(journalnode),zk(QuorumPeerMain) |
192.168.30.144 | s144 | dn(datanode), jn(journalnode) |
192.168.30.145 | s145 | dn(datanode) |
192.168.30.146 | s146 | nn2(namenode),zkfc(DFSZKFailoverController) |
各個機器 jps進程:
由于本人使用的是vmware虛擬機,所以在配置好一臺機器后,使用克隆,克隆出剩余機器,并修改hostname和IP,這樣每臺機器配置就都統(tǒng)一了每臺機器配置添加hdfs用戶及用戶組,配置jdk環(huán)境,安裝hadoop,本次搭建高可用集群在hdfs用戶下,可以參照:centos7搭建hadoop2.10偽分布模式
下面是安裝高可用集群的一些步驟和細(xì)節(jié):
1.設(shè)置每臺機器的hostname 和 hosts
修改hosts文件,hosts設(shè)置有后可以使用hostname訪問機器,這樣比較方便,修改如下:
127.0.0.1 locahost 192.168.30.141 s141 192.168.30.142 s142 192.168.30.143 s143 192.168.30.144 s144 192.168.30.145 s145 192.168.30.146 s146
2.設(shè)置ssh無密登錄,由于s141和s146都為namenode,所以要將這兩臺機器無密登錄到所有機器,最好hdfs用戶和root用戶都設(shè)置無密登錄
我們將s141設(shè)置為nn1,s146設(shè)置為nn2,就需要s141、s146能夠通過ssh無密登錄到其他機器,這樣就需要在s141和s146機器hdfs用戶下生成密鑰對,并將s141和s146公鑰發(fā)送到其他機器放到~/.ssh/authorized_keys文件中,更確切的說要將公鑰添加的所有機器上(包括自己)
在s141和s146機器上生成密鑰對:
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
將id_rsa.pub文件內(nèi)容追加到s141-s146機器的/home/hdfs/.ssh/authorized_keys中,現(xiàn)在其他機器暫時沒有authorized_keys文件,我們就將id_rsa.pub更名為authorized_keys即可,如果其他機器已存在authorized_keys文件可以將id_rsa.pub內(nèi)容追加到該文件后,遠(yuǎn)程復(fù)制可以使用scp命令:
s141機器公鑰復(fù)制到其他機器
scp id_rsa.pub hdfs@s141:/home/hdfs/.ssh/id_rsa_141.pub scp id_rsa.pub hdfs@s142:/home/hdfs/.ssh/id_rsa_141.pub scp id_rsa.pub hdfs@s143:/home/hdfs/.ssh/id_rsa_141.pub scp id_rsa.pub hdfs@s144:/home/hdfs/.ssh/id_rsa_141.pub scp id_rsa.pub hdfs@s145:/home/hdfs/.ssh/id_rsa_141.pub scp id_rsa.pub hdfs@s146:/home/hdfs/.ssh/id_rsa_141.pub
s146機器公鑰復(fù)制到其他機器
scp id_rsa.pub hdfs@s141:/home/hdfs/.ssh/id_rsa_146.pub scp id_rsa.pub hdfs@s142:/home/hdfs/.ssh/id_rsa_146.pub scp id_rsa.pub hdfs@s143:/home/hdfs/.ssh/id_rsa_146.pub scp id_rsa.pub hdfs@s144:/home/hdfs/.ssh/id_rsa_146.pub scp id_rsa.pub hdfs@s145:/home/hdfs/.ssh/id_rsa_146.pub scp id_rsa.pub hdfs@s146:/home/hdfs/.ssh/id_rsa_146.pub
在每臺機器上可以使用cat將秘鑰追加到authorized_keys文件
cat id_rsa_141.pub >> authorized_keys cat id_rsa_146.pub >> authorized_keys
此時authorized_keys文件權(quán)限需要改為644(注意,經(jīng)常會因為這個權(quán)限問題導(dǎo)致ssh無密登錄失敗)
chmod 644 authorized_keys
3.配置hadoop配置文件(${hadoop_home}/etc/hadoop/)
配置細(xì)節(jié):
注意:s141和s146具有完全一致的配置,尤其是ssh.
1) 配置nameservice
[hdfs-site.xml] <property> <name>dfs.nameservices</name> <value>mycluster</value> </property>
2) dfs.ha.namenodes.[nameservice ID]
[hdfs-site.xml] <!-- myucluster下的名稱節(jié)點兩個id --> <property> <name>dfs.ha.namenodes.mycluster</name> <value>nn1,nn2</value> </property>
3) dfs.namenode.rpc-address.[nameservice ID].[name node ID]
[hdfs-site.xml] 配置每個nn的rpc地址。 <property> <name>dfs.namenode.rpc-address.mycluster.nn1</name> <value>s141:8020</value> </property> <property> <name>dfs.namenode.rpc-address.mycluster.nn2</name> <value>s146:8020</value> </property>
4) dfs.namenode.http-address.[nameservice ID].[name node ID]
配置webui端口
[hdfs-site.xml] <property> <name>dfs.namenode.http-address.mycluster.nn1</name> <value>s141:50070</value> </property> <property> <name>dfs.namenode.http-address.mycluster.nn2</name> <value>s146:50070</value> </property>
5) dfs.namenode.shared.edits.dir
名稱節(jié)點共享編輯目錄.選擇三臺journalnode節(jié)點,這里選擇s142、s143、s144三臺機器
[hdfs-site.xml] <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://s142:8485;s143:8485;s144:8485/mycluster</value> </property>
6) dfs.client.failover.proxy.provider.[nameservice ID]
配置一個HA失敗轉(zhuǎn)移的java類(改配置是固定的),client使用它判斷哪個節(jié)點是激活態(tài)。
[hdfs-site.xml] <property> <name>dfs.client.failover.proxy.provider.mycluster</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property>
7) dfs.ha.fencing.methods
腳本列表或者java類,在容災(zāi)保護激活態(tài)的nn.
[hdfs-site.xml] <property> <name>dfs.ha.fencing.methods</name> <value>sshfence</value> </property> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/home/hdfs/.ssh/id_rsa</value> </property>
8) fs.defaultFS
配置hdfs文件系統(tǒng)名稱服務(wù)。這里的mycluster為上面配置的dfs.nameservices
[core-site.xml] <property> <name>fs.defaultFS</name> <value>hdfs://mycluster</value> </property>
9) dfs.journalnode.edits.dir
配置JN存放edit的本地路徑。
[hdfs-site.xml] <property> <name>dfs.journalnode.edits.dir</name> <value>/home/hdfs/hadoop/journal</value> </property>
完整配置文件:
core-site.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://mycluster/</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/home/hdfs/hadoop</value> </property> </configuration>
hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>dfs.replication</name> <value>3</value> </property> <property> <name>dfs.hosts</name> <value>/opt/soft/hadoop/etc/dfs.include.txt</value> </property> <property> <name>dfs.hosts.exclude</name> <value>/opt/soft/hadoop/etc/dfs.hosts.exclude.txt</value> </property> <property> <name>dfs.nameservices</name> <value>mycluster</value> </property> <property> <name>dfs.ha.namenodes.mycluster</name> <value>nn1,nn2</value> </property> <property> <name>dfs.namenode.rpc-address.mycluster.nn1</name> <value>s141:8020</value> </property> <property> <name>dfs.namenode.rpc-address.mycluster.nn2</name> <value>s146:8020</value> </property> <property> <name>dfs.namenode.http-address.mycluster.nn1</name> <value>s141:50070</value> </property> <property> <name>dfs.namenode.http-address.mycluster.nn2</name> <value>s146:50070</value> </property> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://s142:8485;s143:8485;s144:8485/mycluster</value> </property> <property> <name>dfs.client.failover.proxy.provider.mycluster</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> <property> <name>dfs.ha.fencing.methods</name> <value>sshfence</value> </property> <property> <name>dfs.ha.fencing.ssh.private-key-files</name> <value>/home/hdfs/.ssh/id_rsa</value> </property> <property> <name>dfs.journalnode.edits.dir</name> <value>/home/hdfs/hadoop/journal</value> </property> </configuration>
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>
yarn-site.xml
<?xml version="1.0"?> <configuration> <!-- Site specific YARN configuration properties --> <property> <name>yarn.resourcemanager.hostname</name> <value>s141</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> </configuration>
4. 部署細(xì)節(jié)
1)在jn節(jié)點分別啟動jn進程(s142,s143,s144)
hadoop-daemon.sh start journalnode
2)啟動jn之后,在兩個NN之間進行disk元數(shù)據(jù)同步
a)如果是全新集群,先format文件系統(tǒng),只需要在一個nn上執(zhí)行。
[s141|s146]
hadoop namenode -format
b)如果將非HA集群轉(zhuǎn)換成HA集群,復(fù)制原NN的metadata到另一個NN上.
1.步驟一
在s141機器上,將hadoop數(shù)據(jù)復(fù)制到s146對應(yīng)的目錄下
scp -r /home/hdfs/hadoop/dfs hdfs@s146:/home/hdfs/hadoop/
2.步驟二
在新的nn(未格式化的nn,我這里是s146)上運行以下命令,實現(xiàn)待命狀態(tài)引導(dǎo)。注意:需要s141namenode為啟動狀態(tài)(可以執(zhí)行:hadoop-daemon.sh start namenode )。
hdfs namenode -bootstrapStandby
如果沒有啟動s141名稱節(jié)點,就會失敗,如圖:
啟動s141名稱節(jié)點后,在s141上執(zhí)行命令
hadoop-daemon.sh start namenode
然后在執(zhí)行待命引導(dǎo)命令,注意:提示是否格式化,選擇N,如圖:
3. 步驟三
在其中一個NN上執(zhí)行以下命令,完成edit日志到j(luò)n節(jié)點的傳輸。
hdfs namenode -initializeSharedEdits
如果執(zhí)行過程中報:java.nio.channels.OverlappingFileLockException 錯誤:
說明namenode在啟動中,需要停掉namenode節(jié)點(hadoop-daemon.sh stop namenode)
執(zhí)行完后查看s142,s143,s144是否有edit數(shù)據(jù),這里查看生產(chǎn)了mycluster目錄,里面有編輯日志數(shù)據(jù),如下:
4.步驟四
啟動所有節(jié)點.
在s141上啟動名稱節(jié)點和所有數(shù)據(jù)節(jié)點:
hadoop-daemon.sh start namenode hadoop-daemons.sh start datanode
在s146上啟動名稱節(jié)點
hadoop-daemon.sh start namenode
此時在瀏覽器中訪問http://192.168.30.141:50070/和http://192.168.30.146:50070/你會發(fā)現(xiàn)兩個namenode都為standby
這時需要手動使用命令將其中一個切換為激活態(tài),這里將s141(nn1)設(shè)置為active
hdfs haadmin -transitionToActive nn1
此時s141就為active
hdfs haadmin常用命令:
至此手動容災(zāi)高可用配置完成,但是這種方式不智能,不能夠自動感知容災(zāi),所以下面介紹自動容災(zāi)配置
5.自動容災(zāi)配置
需要引入zookeeperquarum 和 zk 容災(zāi)控制器(ZKFC)兩個組件
搭建zookeeper集群,選擇s141,s142,s143三臺機器,下載 zookeeper:http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.5.6
1) 解壓zookeeper:
tar -xzvf apache-zookeeper-3.5.6-bin.tar.gz -C /opt/soft/zookeeper-3.5.6
2) 配置環(huán)境變量,在/etc/profile中添加zk環(huán)境變量,并重新編譯/etc/profile文件
3) 配置zk配置文件,三臺機器配置文件統(tǒng)一
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/home/hdfs/zookeeper # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.1=s141:2888:3888 server.2=s142:2888:3888 server.3=s143:2888:3888
4)分別
在s141的/home/hdfs/zookeeper(在zoo.cfg配置文件中配置的dataDir路徑)目錄下創(chuàng)建myid文件,值為1(對應(yīng)zoo.cfg配置文件中的server.1)
在s142的/home/hdfs/zookeeper(在zoo.cfg配置文件中配置的dataDir路徑)目錄下創(chuàng)建myid文件,值為2(對應(yīng)zoo.cfg配置文件中的server.2)
在s143的/home/hdfs/zookeeper(在zoo.cfg配置文件中配置的dataDir路徑)目錄下創(chuàng)建myid文件,值為3(對應(yīng)zoo.cfg配置文件中的server.3)
5) 分別在每臺機器上啟動zk
zkServer.sh start
啟動成功會出現(xiàn)zk進程:
配置hdfs相關(guān)配置:
1)停止hdfs所有進程
stop-all.sh
2)配置hdfs-site.xml,啟用自動容災(zāi).
[hdfs-site.xml] <property> <name>dfs.ha.automatic-failover.enabled</name> <value>true</value> </property>
3) 配置core-site.xml,指定zk的連接地址.
<property> <name>ha.zookeeper.quorum</name> <value>s141:2181,s142:2181,s143:2181</value> </property>
4) 分發(fā)以上兩個文件到所有節(jié)點。
5) 在其中的一臺NN(s141),在ZK中初始化HA狀態(tài)
hdfs zkfc -formatZK
出現(xiàn)如下結(jié)果說明成功:
也可去zk中查看:
6) 啟動hdfs集群
start-dfs.sh
查看各個機器進程:
啟動成功,再看一下webui
s146為激活態(tài)
s141為待命態(tài)
至此hadoop 自動容災(zāi)HA搭建完成
總結(jié)
以上所述是小編給大家介紹的centos7搭建hadoop2.10高可用(HA),希望對大家有所幫助!
標(biāo)簽:資陽 混顯 滄州 三沙 賀州 延安 亳州 丹東
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《centos7搭建hadoop2.10高可用(HA)》,本文關(guān)鍵詞 centos7,搭建,hadoop2.10,高可用,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。