ZooKeeper最新版本集群和单机模式安装

Zookeeper的搭建方式

  1. 单机模式
  2. 单机伪集群模式 ⼀台服务器上运⾏多个Zookeeper 实例;
  3. 集群模式 Zookeeper运⾏于⼀个集群上,适合⽣产环境,这个计算机集群被称为⼀个“集合体”
  4. 如果在分布式的生产环境中使用ZooKeeper,推荐使用大于3的奇数节点个数搭建集群,这样能提升系统的可用性。

集群模式、伪集群模式安装方式都差不多只是真正的集群模式需要使用不同的IP。单机模式则更简单了,只需要取消掉zoo.cfg配置文件中的集群配置就行。

二、伪集群模式安装

Zookeeper 官网下载安装包

  1. 官网地址:https://zookeeper.apache.org/
  2. 下载页面:https://zookeeper.apache.org/releases.html
  3. 下载最新稳定版本,下载页面上带有 lastest stable release 备注的连接就是最新稳定版。
  4. 有源代码发行版和二进制发行版,直接下载二进制发行版就行image.png

2.1 解压后的目录

[root@localhost zookeeper-3.7.1-01]# ll
总用量 36
drwxr-xr-x. 2 root root  4096 57 2022 bin                 
drwxr-xr-x. 2 root root    70 71 10:40 conf
drwxr-xr-x. 5 root root  4096 57 2022 docs
drwxr-xr-x. 2 root root  4096 629 17:42 lib
-rw-r--r--. 1 root root 11358 57 2022 LICENSE.txt
drwxr-xr-x. 2 root root    88 630 09:51 logs
-rw-r--r--. 1 root root  2084 57 2022 NOTICE.txt
-rw-r--r--. 1 root root  2214 57 2022 README.md
-rw-r--r--. 1 root root  3570 57 2022 README_packaging.md

2.2 从模板创建配置文件

  1. 进入解压目录下的conf目录下,里面包含 zoo_sample.cfg 文件
  2. 将zoo_sample.cfg 改名为 zoo.cfg 因为zookeeper默认加载zoo.cfg文件。如果需要使用其他名称,可以使用如下传递配置文件参数:zkServer.sh start your_config zkServer.sh stop your_config zkServer.sh status your_config

2.3 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= /root/Desktop/studySoftWare/zookeeper-3.7.1-localCluster/zookeeper-3.7.1-01/data

# 配置日志存储路径
dataLogDir= /root/Desktop/studySoftWare/zookeeper-3.7.1-localCluster/zookeeper-3.7.1-01/data/logs

# 客户端通信端口
# the port at which the clients will connect
clientPort=15881

# 集群配置
# server.服务器ID=服务器IP地址:服务器之间通信端⼝:服务器之间投票选举端⼝
server.1=localhost:16881:17881
server.2=localhost:16882:17882
server.3=localhost:16883:17883

# 管理平台端口配置
admin.serverPort:18881


# 最大客户端连接数
# 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.
#
# https://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.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

2.3.1 单机需要的配置

  • dataDir= 数据保存路径
  • dataLogDir= 事务日志文件保存路径
  • clientPort= 供客户端连接的监听端口
  • admin.serverPort=管理平台端口配置,对于3.6以后的版本会默认占用8080启动一个内嵌的管理控制台。可以使用这个配置修改端口。或者启动时添加参数,禁用该控制台。-Dzookeeper.admin.enableServer=false

2.3.3 集群模式额外需要的配置

  1. 集群机器和对应通信端口配置。这些端口就需要和上面的 admin.serverPort 还有clientPort 不同,不然会导致启动失败。单机安装伪集群时,这些端口都不能重复。
# server.服务器ID=服务器IP地址:服务器之间通信端⼝:服务器之间投票选举端⼝
server.1=localhost:16881:17881
server.2=localhost:16882:17882
server.3=localhost:16883:17883
  1. 在配置的dataDir 路径下,根据上面配置的集群服务id新增一个myid的文件,文件内容就是服务器id号即可。
[root@localhost data]# pwd
/studySoftWare/zookeeper-3.7.1-localCluster/zookeeper-3.7.1-01/data
[root@localhost data]# cat myid 
1
[root@localhost data]# 

2.4 启动服务

进入安装目录下的bin目录 ./zkServer start 如果是部署了多个服务的集群,则依次启动每个服务。

  • 20
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值