官方文档上这么解释zookeeper,它是一个分布式服务框架,是Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务、状态同步服务、集群管理、分布式应用配置项的管理等。
上面的解释有点抽象,简单来说zookeeper=文件系统+监听通知机制。
一、zookeeper单机部署
1、依赖环境,zookeeper是Java编写的依赖于Java环境
[root@zk01 ~]# yum install install java-1.8.0-openjdk-devel -y
2、下载zookeeper并部署
[root@zk01 ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2.tar.gz
[root@zk01 ~]# tar xf apache-zookeeper-3.6.2.tar.gz
[root@zk01 ~]# mv apache-zookeeper-3.6.2 /data/
[root@zk01 ~]# cd /data/zookeeper-3.6.2
[root@zk01 ~]# cp conf/zoo_sample.cfg conf/zoo.cfg
3、修改zookeeper配置文件
[root@zk01 conf]# vi 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=/data/zookeeper-3.6.2/zookeeper_data
# 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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
4、设置环境变量
[root@zk01 ~]# vi /etc/profile.d/env.sh
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64/jre/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/jre/lib/dt.jar:$JAVA_HOME/lib/tool.jar
export ZOOKEEPER_HOME=/data/zookeeper-3.6.2
export KAFKA_HOME=/data/kafka-2.6.0
export PATH=$PATH:$JAVA_HOME/bin:${ZOOKEEPER_HOME}/bin:${ZOOKEEPER_HOME}/sbin:${KAFKA_HOME}/bin
### 加载环境变量
[root@zk01 conf]# source /etc/profile.d/env.sh
5、启动zookeeper软件
[root@zk01 conf]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /data/zookeeper-3.6.2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
###查看zookeeper运行状态
[root@zk01 conf]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper-3.6.2/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@zk01 conf]# jps
22932 Jps
19413 Kafka
22838 QuorumPeerMain
二、zookeeper集群部署
### 1、规划:
204.13.155.226 zk01 centos7
147.135.114.60 zk02 centos7
80.83.124.76 zk03 centos7
### 2、把规划写入到hosts文件
[root@zk01 conf]# vi /etc/hosts
204.13.155.226 zk01
147.135.114.60 zk02
80.83.124.76 zk03
### 3、修改三台zookeeper服务器的配置文件
[root@zk01 conf]# vi 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=/data/zookeeper-3.6.2/zookeeper_data
# 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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
#加入以下三行:
server.1=zk01:2888:3888
server.2=zk02:2888:3888
server.3=zk03:2888:3888
### 4、启动三台zookeeper服务器并查看状态
[root@zk01 conf]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper-3.6.2/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@zk03 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper-3.6.2/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@zk02 ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/zookeeper-3.6.2/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
可以看出zk02为leader,zk01和zk03为follower状态
还没有任何评论,你来说两句吧