服務(wù)器
本篇介紹在centos7中搭建hadoop2.10高可用集群,首先準備6臺機器:2臺nn(namenode);4臺dn(datanode);3臺jns(journalnodes)
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偽分布模式
下面是安裝高可用集群的一些步驟和細節(jié):
1.設(shè)置每臺機器的hostname 和 hosts
修改hosts文件,hosts設(shè)置有后可以使用hostname訪問機器,這樣比較方便,修改如下:
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,所以要將這兩臺機器無密登錄到所有機器,最好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)容追加到該文件后,遠程復(fù)制可以使用scp命令:
s141機器公鑰復(fù)制到其他機器
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機器公鑰復(fù)制到其他機器
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在每臺機器上可以使用cat將秘鑰追加到authorized_keys文件
cat id_rsa_141.pub >> authorized_keyscat id_rsa_146.pub >> authorized_keys此時authorized_keys文件權(quán)限需要改為644(注意,經(jīng)常會因為這個權(quán)限問題導(dǎo)致ssh無密登錄失敗)
chmod 644 authorized_keys3.配置hadoop配置文件(${hadoop_home}/etc/hadoop/)
配置細節(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