zookeeper入门简介

1、安装(Linux,集群,3台机器

  1. java环境,安装jdk,至少需要1.6版本
  2. 下载zookeeper,进入zookeeper/conf目录,拷贝zoo_sample.cfg,重命名为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=/usr/local/zookeeper-3.4.6/data
dataLogDir=/usr/local/zookeeper-3.4.6/dataLog
# 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
server.1=192.168.236.128:2888:3888
server.3=192.168.236.130:2888:3888
server.5=192.168.236.137:2888:3888

然后在dataDir对应的目录中,新建myid文件填入ID值,对应如下图server后面的数字

完了之后通过bin目录下面的zkServer.sh脚本可以开启和关闭服务,通过ps命令可以验证zk开启成功,通过bin目录下面的zkCli.sh脚本可以开启zk的命令终端,然后使用zk命令操作

Java API操作

    原文作者:妄语生
    原文地址: https://www.jianshu.com/p/80df79dbff3d
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞