您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關如何進行HA分布式集群搭建,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
1,防止由于一臺namenode掛掉,集群失敗的情形
2,適合工業生產的需求
1,型號:VMware_workstation_full_12.5.0.11529.exe linux鏡像:CentOS-7-x86_64-DVD-1611.iso
注意點:
1,網絡選擇了橋接模式(可以防止route總變),(臺式機或服務器最好設置自己的本機的ip地址為靜態的ip)
2,安裝過程中選擇了基礎建設模式(infras...),(減少內存的消耗,但又保證基本的環境的模式)
3,用戶名root 密碼 root
4,網絡配置使用了手動網絡固定網絡ip4地址(固定ip)
1,驗證網絡服務:ping <主機ip> 主機 ping <虛擬機ip> ping www.baidu.ok 驗證ok
備份ip地址:cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33.bak
2,防火墻設置:關閉并禁用防火墻
關閉防火墻 systemctl stop firewalld.service(cetos7與前面系列的iptables不同)
禁用防火墻:systemctl disable firewalld.service
查看防火墻狀態:firewall-cmd --state
3,設置hosts,hostname,network
vim /etc/hostname
ha1
vim /etc/hosts
192.168.1.116 ha1
192.168.1.117 ha2
192.168.1.118 ha3
192.168.1.119 ha4
vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=ha1
4,安裝一些必要的包:(不一定全)
yum install -y chkconfig
yum install -y Python
yum install -y bind-utils
yum install -y psmisc
yum install -y libxslt
yum install -y zlib
yum install -y sqlite
yum install -y cyrus-sasl-plain
yum install -y cyrus-sasl-gssapi
yum install -y fuse
yum install -y portmap
yum install -y fuse-libs
yum install -y RedHat-lsb
5,安裝Java和Scala
java版本:jdk-7u80-linux-x64.rpm
scala版本:scala-2.11.6.tgz
驗證是否有java:
rpm -qa|grep java 無
tar -zxf jdk-8u111-linux-x64.tar.gz
tar -zxf scala-2.11.6.tgz
mv jdk1.8.0_111 /usr/java
mv scala-2.11.6 /usr/scala
配置環境變量:
vim /etc/profile
export JAVA_HOME=/usr/java
export SCALA_HOME=/usr/scala
export PATH=$JAVA_HOME/bin:$SCALA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
6,重啟,驗證上述是否設置 ok :重啟 使用vm快照,命名為:初始化ok java,scala,主機名,防火墻,ip
1,集群機準備
連接克隆:對ha1克隆出ha2,ha3,ha4
對ha2,ha3,ha4修改網絡地址,network,防火墻
vim /etc/sysconfig/network-scripts/ifcfg-ens33
116 117/118/119
service network restart
vim /etc/hostname
vim /etc/sysconfig/network
systemctl disable firewalld.service
對ha2,ha3,ha4重啟驗證ip,網絡,防火墻,分別對三臺機快照,命名為:初始化ok java,scala,主機名,防火墻,ip
2,集群框架圖
機子 | Namenode | DataNode | Zookeeper | ZkFC | JournalNode | RM | DM |
Ha1 | 1 |
| 1 | 1 | 1 | 1 |
|
Ha2 | 1 | 1 | 1 | 1 | 1 |
| 1 |
Ha3 |
| 1 | 1 |
| 1 |
| 1 |
Ha4 |
| 1 |
|
|
|
| 1 |
3,ssh通信: ok后 快照 ssh ok
四臺機:
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
ha1下:
scp ~/.ssh/* root@ha2:~/.ssh/
scp ~/.ssh/* root@ha3:~/.ssh/
scp ~/.ssh/* root@ha4:~/.ssh/
驗證:
ssh ha2/ha3/ha4
4,zookeeper集群配置:
1,配置環境變量
zook安裝:
tar -zxf zookeeper-3.4.8.tar.gz
mv zookeeper-3.4.8 /usr/zookeeper-3.4.8
修改配置文件:
export ZK_HOME=/usr/zookeeper-3.4.8
scp /etc/profile root@ha2:/etc/
scp /etc/profile root@ha3:/etc/
source /etc/profile
2,zoo.cfg配置(加粗修改出)
cd /usr/zookeeper-3.4.8/conf
cp zoo_sample.cfg zoo.cfg
內容:
# 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=/opt/zookeeper/datas
dataLogDir=/opt/zookeeper/logs
# 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=ha1:2888:3888
server.2=ha2:2888:3888
server.3=ha3:2888:3888
3,啟動zookeeper集群:
#三臺機(ha1,ha2,ha3)
新建文件夾:
mkdir -p /opt/zookeeper/datas
mkdir -p /opt/zookeeper/logs
cd /opt/zookeeper/datas
vim myid 寫1/2/3
#分發給ha2,ha3(注意ha4不需要)
cd /usr
scp -r zookeeper-3.4.8 root@ha2:/usr
scp -r zookeeper-3.4.8 root@ha3:/usr
#啟動(三臺機)
cd $ZK_HOME/bin
zkServer.sh start
zkServer.sh status 一個leader和連個follower
5,hadoop集群配置
1,配置環境變量:
版本:hadoop-2.7.3.tar.gz
tar -zxf hadoop-2.7.3.tar.gz
mv hadoop2.7.3 /usr/hadoop2.7.3
export JAVA_HOME=/usr/java
export SCALA_HOME=/usr/scala
export HADOOP_HOME=/usr/hadoop-2.7.3
export PATH=$JAVA_HOME/bin:$SCALA_HOME/bin:$HADOOP_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
source /etc/profile
2,hadoop.env.sh配置:
export JAVA_HOME=/usr/java source hadoop.env.sh hadoop version 驗證ok
3,hdfs-site.xml配置:后續修改后發送(scp hdfs-site.xml root@ha4:/usr/hadoop-2.7.3/etc/hadoop/)
vim hdfs-site.xml
<configuration>
<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>ha1:9000</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>ha2:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn1</name>
<value>ha1:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.mycluster.nn2</name>
<value>ha2:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://ha2:8485;ha3:8485;ha4: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>/root/.ssh/id_rsa</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/opt/jn/data</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
</configuration>
4,core-site.xml配置
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://mycluster</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>ha1:2181,ha2:2181,ha3:2181</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/hadoop2</value>
<description>A base for other temporary directories.</description>
</property>
</configuration>
5,yarn-site.xml配置
vim yarn-site.xml
<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.hostname</name>
<value>ha1</value>
</property>
</configuration>
6,mapred-site.xml配置
<configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration>
7,slaves配置:
vim slaves ha2 ha3 ha4
8,分發并啟動:
#分發
scp -r hadoop-2.7.3 root@ha2:/usr/
scp -r hadoop-2.7.3 root@ha3:/usr/
scp -r hadoop-2.7.3 root@ha4:/usr/
#啟動JN(在ha2,ha3,ha4)
cd sbin
./hadoop-daemon.sh start journalnode
[root@ha2 sbin]# jps
JournalNode
Jps
QuorumPeerMain(#zk啟動的線程)
#ha1:namenode格式化
cd bin
./hdfs namenode -format
#zk格式化
./hdfs zkfc -formatZK
#可以查看cd /opt/hadoop2文件來查看元數據是否格式化正常
#ha2:namenode格式化
1,ha1要先啟動namenode:
./hadoop-daemon.sh start namenode
2,ha2下
./hdfs namenode -bootstrapStandby
9,驗證:http://192.168.1.116:50070/驗證 ok 快照 ha模式下的hadoop+zookeeper安裝ok
#hdfs集群驗證
[root@ha1 sbin]# ./stop-dfs.sh
Stopping namenodes on [ha1 ha2]
ha2: no namenode to stop
ha1: stopping namenode
ha2: no datanode to stop
ha3: no datanode to stop
ha4: no datanode to stop
Stopping journal nodes [ha2 ha3 ha4]
ha3: stopping journalnode
ha4: stopping journalnode
ha2: stopping journalnode
Stopping ZK Failover Controllers on NN hosts [ha1 ha2]
ha2: no zkfc to stop
ha1: no zkfc to stop
[root@ha1 sbin]# ./start-dfs.sh
ha1下:
[root@ha1 sbin]# jps
Jps
NameNode
QuorumPeerMain
DFSZKFailoverController
[root@ha2 dfs]# jps
NameNode
DFSZKFailoverController
Jps
DataNode
JournalNode
QuorumPeerMain
[root@ha3 sbin]# jps
QuorumPeerMain
DataNode
JournalNode
Jps
[root@ha4 sbin]# jps
Jps
DataNode
JournalNode
配置yarn和mapred
[root@ha1 sbin]# jps
NameNode
DFSZKFailoverController
Jps
QuorumPeerMain
ResourceManager
[root@ha2 hadoop]# jps
DataNode
NameNode
DFSZKFailoverController
JournalNode
NodeManager
Jps
QuorumPeerMain
[root@ha3 ~]# jps
QuorumPeerMain
DataNode
NodeManager
Jps
JournalNode
[root@ha4 ~]# jps
JournalNode
NodeManager
DataNode
Jps
看完上述內容,你們對如何進行HA分布式集群搭建有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。