zookeeper集群安装

2020-12-17  本文已影响0人  ArthurIsUsed

三台设备安装zookeeper集群

Hostname IP Role(随机分配)
els1 172.20.28.150 leader
els2 172.20.28.151 follower
els3 172.20.28.152 follower

zookeeper 集群通常是用来对用户的分布式应用程序提供协调服务的,为了保证数据的一致性, zookeeper 集群进行了三种角色划分:leader、follower、observer分别对应着总统、议员和观察者。

下载zookeeper

[root@els1 install_package]#  wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.5.8/apache-zookeeper-3.5.8.tar.gz

下载安装JDK

[root@els1 lib]# cd /usr/lib/
[root@els1 lib]# mkdir jvm
[root@els1 cd]# cd jvm
[root@els1 jvm]# tar -xzvf jdk-8u181-linux-x64.tar.gz

[root@els1 jvm]# vim ~/.bashrc    # 添加以下内容
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_181
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
[root@els3 jvm]# source ~/.bashrc

修改zookeeper的配置文件

[root@els1 jvm]# cd /opt/zk/zookeeper-3.5.8/conf
[root@els1 conf]# cp zoo_sample.cfg zoo.cfg
[root@els1 conf]# cat zoo.cfg | grep -v "#"
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zk/zkDATA/
clientPort=2181
server.1=172.20.28.150:2888:3888
server.2=172.20.28.151:2888:3888
server.3=172.20.28.152:2888:3888

datadir指定的目录下创建myid文件

[root@els1 conf]# cd /opt/zk/zkDATA
[root@els1 zkDATA]# vim myid
1

为了能够在任意目录启动zookeeper集群,为zookeeper设置环境变量

[root@els1 zkDATA]# vim ~/.bashrc 
export ZK_HOME=/opt/zk/zookeeper-3.5.8
export PATH=$PATH:${ZK_HOME}/bin
[root@els1 zkDATA]# source ~/.bashrc

启动zookeeper

[root@els1 zkDATA]# zkServer.sh  start
ZooKeeper JMX enabled by default
Using config: /opt/zk/zookeeper-3.5.8/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START

查看日志发现报错

[root@els1 logs]# cat zookeeper-root-server-els1.out
Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain

因为下载的3.5.8版本缺少一个jar包,改用线上现有的3.4.9版本正常启动

[root@localhost zookeeper-3.4.9]# ll | grep jar
-rw-rw-r--  1 1001 1001 1368238 Aug 23  2016 zookeeper-3.4.9.jar

[root@els1 bin]# netstat -anpt  |grep 2181
tcp6       0      0 :::2181                 :::*                    LISTEN      22858/java          

[root@els1 zkDATA]# vim ~/.bashrc   # 修改ZK_HOME
export ZK_HOME=/opt/zk/zookeeper-3.4.9
[root@els1 zkDATA]# source ~/.bashrc

[root@els1 bin]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zk/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

其他两台设备也按同样的操作启动设备,检查设备角色如下

[root@els1 bin]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zk/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: follower

[root@els2 zk]# zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /opt/zk/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: leader

[root@els3 zk]# zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /opt/zk/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: follower
上一篇下一篇

猜你喜欢

热点阅读