服務(wù)器
本篇介紹在centos7中搭建hadoop2.10高可用集群,首先準(zhǔn)備6臺(tái)機(jī)器:2臺(tái)nn(namenode);4臺(tái)dn(datanode);3臺(tái)jns(journalnodes)
ip
hostname
進(jìn)程
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)
各個(gè)機(jī)器 jps進(jìn)程:
由于本人使用的是vmware虛擬機(jī),所以在配置好一臺(tái)機(jī)器后,使用克隆,克隆出剩余機(jī)器,并修改hostname和ip,這樣每臺(tái)機(jī)器配置就都統(tǒng)一了每臺(tái)機(jī)器配置添加hdfs用戶及用戶組,配置jdk環(huán)境,安裝hadoop,本次搭建高可用集群在hdfs用戶下,可以參照:centos7搭建hadoop2.10偽分布模式
下面是安裝高可用集群的一些步驟和細(xì)節(jié):
1.設(shè)置每臺(tái)機(jī)器的hostname 和 hosts
修改hosts文件,hosts設(shè)置有后可以使用hostname訪問機(jī)器,這樣比較方便,修改如下:
127.0.0.1 locahost192.168.30.141 s141192.168.30.142 s142192.168.30.143 s143192.168.30.144 s144192.168.30.145 s145192.168.30.146 s1462.設(shè)置ssh無密登錄,由于s141和s146都為namenode,所以要將這兩臺(tái)機(jī)器無密登錄到所有機(jī)器,最好hdfs用戶和root用戶都設(shè)置無密登錄
我們將s141設(shè)置為nn1,s146設(shè)置為nn2,就需要s141、s146能夠通過ssh無密登錄到其他機(jī)器,這樣就需要在s141和s146機(jī)器hdfs用戶下生成密鑰對(duì),并將s141和s146公鑰發(fā)送到其他機(jī)器放到~/.ssh/authorized_keys文件中,更確切的說要將公鑰添加的所有機(jī)器上(包括自己)
在s141和s146機(jī)器上生成密鑰對(duì):
ssh-keygen -t rsa -p \\\'\\\' -f ~/.ssh/id_rsa將id_rsa.pub文件內(nèi)容追加到s141-s146機(jī)器的/home/hdfs/.ssh/authorized_keys中,現(xiàn)在其他機(jī)器暫時(shí)沒有authorized_keys文件,我們就將id_rsa.pub更名為authorized_keys即可,如果其他機(jī)器已存在authorized_keys文件可以將id_rsa.pub內(nèi)容追加到該文件后,遠(yuǎn)程復(fù)制可以使用scp命令:
s141機(jī)器公鑰復(fù)制到其他機(jī)器
scp id_rsa.pub hdfs@s141:/home/hdfs/.ssh/id_rsa_141.pubscp id_rsa.pub hdfs@s142:/home/hdfs/.ssh/id_rsa_141.pubscp id_rsa.pub hdfs@s143:/home/hdfs/.ssh/id_rsa_141.pubscp id_rsa.pub hdfs@s144:/home/hdfs/.ssh/id_rsa_141.pubscp id_rsa.pub hdfs@s145:/home/hdfs/.ssh/id_rsa_141.pubscp id_rsa.pub hdfs@s146:/home/hdfs/.ssh/id_rsa_141.pubs146機(jī)器公鑰復(fù)制到其他機(jī)器
scp id_rsa.pub hdfs@s141:/home/hdfs/.ssh/id_rsa_146.pubscp id_rsa.pub hdfs@s142:/home/hdfs/.ssh/id_rsa_146.pubscp id_rsa.pub hdfs@s143:/home/hdfs/.ssh/id_rsa_146.pubscp id_rsa.pub hdfs@s144:/home/hdfs/.ssh/id_rsa_146.pubscp id_rsa.pub hdfs@s145:/home/hdfs/.ssh/id_rsa_146.pubscp id_rsa.pub hdfs@s146:/home/hdfs/.ssh/id_rsa_146.pub在每臺(tái)機(jī)器上可以使用cat將秘鑰追加到authorized_keys文件
cat id_rsa_141.pub >> authorized_keyscat id_rsa_146.pub >> authorized_keys此時(shí)authorized_keys文件權(quán)限需要改為644(注意,經(jīng)常會(huì)因?yàn)檫@個(gè)權(quán)限問題導(dǎo)致ssh無密登錄失敗)
chmod 644 authorized_keys3.配置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é)點(diǎn)兩個(gè)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]配置每個(gè)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é)點(diǎn)共享編輯目錄.選擇三臺(tái)journalnode節(jié)點(diǎn),這里選擇s142、s143、s144三臺(tái)機(jī)器
[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]
配置一個(gè)ha失敗轉(zhuǎn)移的java