Zookeeper-快速入门、服务搭建、集群搭建教程

官网https://zookeeper.apache.org/

zookeeper常用用途:

  • 集群管理,zookeeper作为注册中心,管理服务提供方的ip地址端口号url信息,并在服务消费方请求需要时发送给服务消费方。
  • 配置中心(不过一般用阿波罗apollo或者阿里的Nacos来做)
    • 多个app中的配置是从zookeeper中拉取配置,而不是一个个去手动修改。
    • 消费端从服务端中关注某个ZNode,一旦节点发生数据变更,服务端会向消费端发送Watcher事件进行通知,消费端接受事件后,主动到服务端获取最新的配置数据。
  • 分布式锁
  • 等待

安装

前提:安装zookeeper需要的JDK版本,这里装的是openjdk-8

apt install openjdk-8-jdk

复制示例配置文件zoo_simple.conf到confg/zoo.cfg

cp confg/zoo_simle.conf confg/zoo.cf

修改配置文件,修改如下:(主要修改数据的保存目录,其他看自己的需求修改)

# 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=/apps_data/zookeeper**
# 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

通过自带的脚本启动zookeeper

# 查看帮助
root@swq-virtual-machine:/apps/zookeeper-3.4.13# bash bin/zkServer.sh --help
ZooKeeper JMX enabled by default
Using config: /apps/zookeeper-3.4.13/bin/../conf/zoo.cfg
Usage: bin/zkServer.sh {s
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值