zookeeper的高可用部署

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zookeeper的高可用部署相关的知识,希望对你有一定的参考价值。

  1. 说明:zookeeper是一个服务注册中心

2. zookeeper的部署

 2.1 三台主机

 192.168.56.15
 192.168.56.16
 192.168.56.17
 [[email protected] ~]# cat /etc/hosts
192.168.56.15 zk01
192.168.56.16 zk02
192.168.56.17 zk03

 2.2 java环境

[[email protected] ~]# java -version 
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
[[email protected] ~]#

 2.3 做成这样的 

[[email protected] ~]# cd  /opt
[[email protected] opt]# ll
total 8
lrwxrwxrwx  1 root root   11 Dec 25 01:24 jdk -> jdk1.7.0_80
drwxr-xr-x  8   10  143 4096 Apr 11  2015 jdk1.7.0_80
drwxr-xr-x  2 root root   61 Dec 25 01:30 tools
lrwxrwxrwx  1 root root   15 Dec 25 01:29 zk01 -> zookeeper-3.4.9
drwxr-xr-x 12 1001 1001 4096 Dec 25 01:39 zookeeper-3.4.9
[[email protected] opt]#

  2.4 修改zookeeper配置文件(zk01)

[[email protected] conf]# pwd
/opt/zk01/conf
cp zoo_sample.cfg  zoo.cfg 

vi zoo.cfg
dataDir=/opt/zk01/datadir
dataLogDir=/opt/zk01/datalog #自己加的
server.1=192.168.56.15:2888:3888
server.2=192.168.56.16:2888:3888
server.3=192.168.56.17:2888:3888
mkdir /opt/zk01/datadir
mkdir /opt/zk01/datalog
[[email protected] datadir]# cat myid 
1
[[email protected] datadir]# pwd
/opt/zk01/datadir
[[email protected] datadir]#

 2.5 修改zookeeper配置文件(zk02)

[[email protected] conf]# pwd
/opt/zk02/conf
cp zoo_sample.cfg  zoo.cfg 

vi zoo.cfg
dataDir=/opt/zk02/datadir
dataLogDir=/opt/zk02/datalog #自己加的
server.1=192.168.56.15:2888:3888
server.2=192.168.56.16:2888:3888
server.3=192.168.56.17:2888:3888
mkdir /opt/zk02/datadir
mkdir /opt/zk02/datalog
[[email protected] datadir]# cat myid 
2
[[email protected] datadir]# pwd
/opt/zk03/datadir
[[email protected] datadir]#

 2.6 修改zookeeper配置文件(zk03)

[[email protected] conf]# pwd
/opt/zk03/conf
cp zoo_sample.cfg  zoo.cfg 

vi zoo.cfg
dataDir=/opt/zk03/datadir
dataLogDir=/opt/zk03/datalog #自己加的
server.1=192.168.56.15:2888:3888
server.2=192.168.56.16:2888:3888
server.3=192.168.56.17:2888:3888
mkdir /opt/zk03/datadir
mkdir /opt/zk03/datalog
[[email protected] datadir]# cat myid 
3
[[email protected] datadir]# pwd
/opt/zk03/datadir
[[email protected] datadir]#

2.7 启动zookeeper服务

按照顺序zk01  zk02 zk03的顺序

依次启动zookeeper服务

[[email protected] bin]# pwd
/opt/zk01/bin
[[email protected] bin]# ./zkServer.sh  start

2.8 验证服务是否正常(每个都要验证下)

[[email protected] bin]# ./zkCli.sh   -server 192.168.56.15:2181
正常状态
[[email protected] bin]# ./zkCli.sh   -server 192.168.56.15:2181
Connecting to 192.168.56.15:2181
2016-12-25 02:11:10,892 [myid:] - INFO  [main:[email protected]] - Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT
2016-12-25 02:11:10,900 [myid:] - INFO  [main:[email protected]] - Client environment:host.name=zk01
2016-12-25 02:11:10,900 [myid:] - INFO  [main:[email protected]] - Client environment:java.version=1.7.0_80
2016-12-25 02:11:10,905 [myid:] - INFO  [main:[email protected]] - Client environment:java.vendor=Oracle Corporation
2016-12-25 02:11:10,905 [myid:] - INFO  [main:[email protected]] - Client environment:java.home=/opt/jdk1.7.0_80/jre
2016-12-25 02:11:10,906 [myid:] - INFO  [main:[email protected]] - Client environment:java.class.path=/opt/zk01/bin/../build/classes:/opt/zk01/bin/../build/lib/*.jar:/opt/zk01/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zk01/bin/../lib/slf4j-api-1.6.1.jar:/opt/zk01/bin/../lib/netty-3.10.5.Final.jar:/opt/zk01/bin/../lib/log4j-1.2.16.jar:/opt/zk01/bin/../lib/jline-0.9.94.jar:/opt/zk01/bin/../zookeeper-3.4.9.jar:/opt/zk01/bin/../src/java/lib/*.jar:/opt/zk01/bin/../conf:.:/opt/jdk/lib:/opt/jdk/jre/lib:/opt/jdk/lib/tools.jar
2016-12-25 02:11:10,906 [myid:] - INFO  [main:[email protected]] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2016-12-25 02:11:10,906 [myid:] - INFO  [main:[email protected]] - Client environment:java.io.tmpdir=/tmp
2016-12-25 02:11:10,907 [myid:] - INFO  [main:[email protected]] - Client environment:java.compiler=<NA>
2016-12-25 02:11:10,907 [myid:] - INFO  [main:[email protected]] - Client environment:os.name=Linux
2016-12-25 02:11:10,907 [myid:] - INFO  [main:[email protected]] - Client environment:os.arch=amd64
2016-12-25 02:11:10,908 [myid:] - INFO  [main:[email protected]] - Client environment:os.version=3.10.0-514.2.2.el7.x86_64
2016-12-25 02:11:10,908 [myid:] - INFO  [main:[email protected]] - Client environment:user.name=root
2016-12-25 02:11:10,908 [myid:] - INFO  [main:[email protected]] - Client environment:user.home=/root
2016-12-25 02:11:10,909 [myid:] - INFO  [main:[email protected]] - Client environment:user.dir=/opt/zookeeper-3.4.9/bin
2016-12-25 02:11:10,918 [myid:] - INFO  [main:[email protected]] - Initiating client connection, connectString=192.168.56.15:2181 sessionTimeout=30000 [email protected]
Welcome to ZooKeeper!
2016-12-25 02:11:10,969 [myid:] - INFO  [main-SendThread(192.168.56.15:2181):[email protected]] - Opening socket connection to server 192.168.56.15/192.168.56.15:2181. Will not attempt to authenticate using SASL (unknown error)
2016-12-25 02:11:10,975 [myid:] - INFO  [main-SendThread(192.168.56.15:2181):[email protected]] - Socket connection established to 192.168.56.15/192.168.56.15:2181, initiating session
JLine support is enabled
2016-12-25 02:11:11,018 [myid:] - INFO  [main-SendThread(192.168.56.15:2181):[email protected]] - Session establishment complete on server 192.168.56.15/192.168.56.15:2181, sessionid = 0x15931f6222c0002, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: 192.168.56.15:2181(CONNECTED) 0]

2.9查看每个服务器的状态信息

[[email protected] bin]# ./zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /opt/zk01/bin/../conf/zoo.cfg
Mode: follower
[[email protected] bin]#
[[email protected] bin]# ./zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /opt/zk02/bin/../conf/zoo.cfg
Mode: leader
[[email protected] bin]# 
[[email protected] bin]# ./zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /opt/zk03/bin/../conf/zoo.cfg
Mode: follower
[[email protected] bin]#

2.10 端口简介:

zookeepr 客户端的调用的端口是2181 在zoo.cfg中 
server.1=192.168.56.15:2888:3888
2888 follower和 leader之间的通讯的端口
3888 是如果leader当机了 zookeeper服务器之间的选举的端口


本文出自 “砖家博客” 博客,请务必保留此出处http://wsxxsl.blog.51cto.com/9085838/1885812

以上是关于zookeeper的高可用部署的主要内容,如果未能解决你的问题,请参考以下文章

ActiveMQ+ZooKeeper搭建高可用集群

zookeeper安装

基于zookeeper的高可用集群

用Zookeeper来实现SparkSql的高可用

zookeeper(单机伪集群集群)部署

zookeeper(单机伪集群集群)部署