ZK zookeeper单机安装与配置

1 资源

资源信息 版本号 备注
服务器 Centos7 IP: 192.168.51.4
JRE 1.8 如果已安装请忽略
zookeeper 3.4.10

JRE-1.8 下载

zookeeper-3.4.10 下载

2 JDK安装

zookeeper是需要依赖于JDK环境的,如果未安装,可参考博文:

Centos7 离线安装和配置jre1.8

3 zookeeper安装与配置

3.1 上传服务器

将文件上传到服务器的 /opt/module/software 目录

[root@localhost ~]# cd /opt/module/software/
[root@localhost software]# ll
总用量 323500
-rw-r--r--. 1 root   root    34961231 3月  23 14:43 zookeeper-3.4.10.tar.gz.zip

3.2 安装

3.2.1 解压到指定目录

[root@localhost software]# unzip zookeeper-3.4.10.tar.gz.zip 
Archive:  zookeeper-3.4.10.tar.gz.zip
  inflating: zookeeper-3.4.10.tar.gz 
[root@localhost software]# tar -zxvf zookeeper-3.4.10.tar.gz -C /opt/module/

3.2.2 修改配置

[root@localhost software]# cd /opt/module/zookeeper-3.4.10/conf/
[root@localhost conf]# mv zoo_sample.cfg zoo.cfg
[root@localhost conf]# vi /opt/module/zookeeper-3.4.10/conf/zoo.cfg

修改内容

dataDir=/opt/module/zookeeper-3.4.10/zkData

创建目录

[root@localhost conf]# mkdir /opt/module/zookeeper-3.4.10/zkData -p

3.2.3 配置参数解读

# The number of milliseconds of each tick
# 心跳 2000ms
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
# Leader和Follow刚开始通信的时候,初始化最大的延迟时间:10个心跳,一个心跳2000毫秒,20秒,超过说明连接不上
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
# 集群正常启动后,Leader和Follow通信的最大延迟时间: 5 * 2000 毫秒
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
# 日志和数据存储路径
dataDir=/opt/module/zookeeper-3.4.10/zkData
dataLogDir=/opt/module/zookeeper-3.4.10/zkData/log
# the port at which the clients will connect
# 客户端访问服务的端口号  IP + clientPort
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
# 限制连接到zk客户端的数量,根据IP来区分不同的客户端。默认不开启,不限制连接数量
#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
# Jetty使用的端口号
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

1.clientPort =2181:客户端连接端口

客户端连接server的端口,即对外服务端口,默认端口为2181

2.dataDir : 存储快照文件snapshot的目录

简单说是 数据文件目录+数据持久化路径,默认情况下,事务日志也会存储在这里。建议同时配置参数dataLogDir, 事务日志的写性能直接影响zk性能。

扫描二维码关注公众号,回复: 12927435 查看本文章

3.dataLogDir: 事务日志输出目录

尽量给事务日志的输出配置单独的磁盘或是挂载点,这将极大的提升ZK性能。

4.initLimit = 10

Leader和Follow刚开始通信的时候,初始化最大的延迟时间:10个心跳,一个心跳2000毫秒,20秒,超过说明连接不上

5.tickTime =2000:通信心跳数

Zookeeper服务器与客户端心跳时间,单位毫秒。

Zookeeper使用的基本时间,服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个tickTime时间就会发送一个心跳,时间单位为毫秒。

它用于心跳机制,并且设置最小的session超时时间为两倍心跳时间。(session的最小超时时间是2*tickTime)

**6.syncLimit = 5 **

集群中Leader与Follower之间的最大响应时间单位,假如响应超过syncLimit * tickTime,Leader认为Follwer死掉,从服务器列表中删除Follwer。目前配置的是Leader和Follow通信最大延迟时间: 5 * 2000 毫秒

3.4 测试启动

3.4.1 启动 Zookeeper

[root@localhost software]# cd /opt/module/zookeeper-3.4.10/bin
[root@localhost bin]# ./zkServer.sh start

3.4.2 查看进程

[root@localhost bin]# jps
72935 QuorumPeerMain
72955 Jps

3.4.3 查看状态

[root@localhost bin]# /opt/module/zookeeper-3.4.10/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: standalone

3.4.4 客户端

[root@localhost zookeeper-3.4.10]# /opt/module/zookeeper-3.4.10/bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] 

退出

[zk: localhost:2181(CONNECTED) 0] quit

3.4.5 停止 Zookeeper

[root@localhost zookeeper-3.4.10]# /opt/module/zookeeper-3.4.10/bin/zkServer.sh stop

4 相关信息

  • 博文不易,辛苦各位猿友点个关注和赞,感谢

猜你喜欢

转载自blog.csdn.net/qq_15769939/article/details/115262156
zk
今日推荐