美文网首页
zookeeper安装配置-Linux

zookeeper安装配置-Linux

作者: 大大大大橙子呦 | 来源:发表于2019-12-04 18:22 被阅读0次

声明:本文是我参考网络学习,总结得出。参考文献见文末。
环境:centos 7 + zookeeper 3.4.9

ZooKeeper服务器是用Java创建的,它在JVM上运行。你需要使用JDK 6或更高版本。
现在,按照以下步骤在你的机器上安装ZooKeeper框架。

  1. 步骤一:确定正确安装java环境,配置环境变量。
  1. 步骤二:
  • 下载zookeeper压缩包,并且拷贝到 /opt 目录下,官网下载入口。我下载的是 zookeeper-3.4.9.tar.gz
  • 进入/opt,然后解压zookeeper-3.4.9.tar.gz到当前目录(/opt目录)
    cd /opt
    tar --zxf zookeeper-3.4.9.tar.gz
    cd zookeeper-3.4.9
    mkdir data
  • 了解核心配置文件
    初次使用 ZooKeeper 时, 需要将 /opt/zookeeper-3.4.9/conf 目录下的 zoo_sample.cfg 重命名为 zoo.cfg ,zoo.cfg 默认配置如下:
# The number of milliseconds of each 
ticktickTime=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=/tmp/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

配置项说明如下:

  • tickTime: ZooKeeper 中使用的基本时间单元, 以毫秒为单位, 默认值是 2000。它用来调节心跳和超时。例如, 默认的会话超时时间是两倍的 tickTime。
  • initLimit: 默认值是 10, 即 tickTime 属性值的 10 倍。它用于配置允许 followers 连接并同步到 leader 的最大时间。如果 ZooKeeper 管理的数据量很大的话可以增加这个值。
  • syncLimit: 默认值是 5, 即 tickTime 属性值的 5 倍。它用于配置leader 和 followers 间进行心跳检测的最大延迟时间。如果在设置的时间内 followers 无法与 leader 进行通信, 那么 followers 将会被丢弃。
  • dataDir: ZooKeeper 用来存储内存数据库快照的目录, 并且除非指定其它目录, 否则数据库更新的事务日志也将会存储在该目录下。建议配置 dataLogDir 参数来指定 ZooKeeper 事务日志的存储目录。
  • clientPort: 服务器监听客户端连接的端口, 也即客户端尝试连接的端口, 默认值是 2181。
  • maxClientCnxns: 在 socket 级别限制单个客户端与单台服务器之前的并发连接数量, 可以通过 IP 地址来区分不同的客户端。它用来防止某种类型的 DoS 攻击, 包括文件描述符耗尽。默认值是 60。将其设置为 0 将完全移除并发连接数的限制。
  • autopurge.snapRetainCount: 配置 ZooKeeper 在自动清理的时候需要保留的数据文件快照的数量和对应的事务日志文件, 默认值是 3。
  • autopurge.purgeInterval: 和参数 autopurge.snapRetainCount 配套使用, 用于配置 ZooKeeper 自动清理文件的频率, 默认值是 1, 即默认开启自动清理功能, 设置为 0 则表示禁用自动清理功能。
  1. 步骤三:单机模式
  • zoo.cfg配置
ticketTime=2000
clientPort=2181
dataDir=/opt/zookeeper/data
dataLogDir=/opt/zookeeper/logs
  • 启动 ZooKeeper 服务
    bin/zkServer.sh start
    可以收到如下相应:
[root@localhost zookeeper-3.4.9]# bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost zookeeper-3.4.9]# 
  • 启动 CLI
    bin/zkCli.sh
    控制台输出很多内容:
Connecting to localhost:2181
...省略...
Welcome to ZooKeeper!
...省略...
WATCHER::
WatchedEvent state:SyncConnected type: None path:null
[zk: localhost:2181(CONNECTED) 0]
  • 停止ZooKeeper服务器
    连接服务器并执行所有操作后,可以使用以下命令停止zookeeper服务器。
    bin/zkServer.sh stop
  1. 步骤四:集群模式
    见文末第二个链接吧。

参考文献:

  1. https://www.w3cschool.cn/zookeeper/zookeeper_installation.html

  2. https://www.jianshu.com/p/de90172ea680

相关文章

网友评论

      本文标题:zookeeper安装配置-Linux

      本文链接:https://www.haomeiwen.com/subject/lcilgctx.html