- mac下zookeeper的安装
首先先现在zookeeper的安装包,下载地址:https://zookeeper.apache.org/releases.html。也可以直接用brew install zookeeper下载
下载好之后解压到指定目录下,下面配置的是集群模式(3节点),所以需要将解压包解压到3个文件夹下。同时需要创建两个文件夹(data和dataLog)
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=/Users/yp-tc-m-7046/Documents/zookeeper/server1/data
dataLogDir=/Users/yp-tc-m-7046/Documents/zookeeper/server1/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=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
因为我们是在单机上创建集群,所有配置文件中clientPort(端口号)不能相同
server.1=X:Y:Z,X是本机IP,mac的话命令行敲ifconfig,Y指该节点与'leader'节点交互时使用的端口号,Z指leader节点失效后用来进行选举的端口号。
在我们创建的data文件夹中创建myid文件,文件中写入server.后面跟的数字(1/2/3),如果是单机模式的话,server这些就不用写了
myid文件不需要后缀名,直接在命令行用touch创建就行。
至此配置文件就完了,然后在命令行启动就好
/Users/yp-tc-m-7046/Documents/zookeeper/server1/zookeeper-3.4.12/bin/zkServer.sh start
/Users/yp-tc-m-7046/Documents/zookeeper/server2/zookeeper-3.4.12/bin/zkServer.sh start
/Users/yp-tc-m-7046/Documents/zookeeper/server3/zookeeper-3.4.12/bin/zkServer.sh start
同时可以使用zkServer.sh status查看当前节点状态(是leader还是follower),如下
ZooKeeper JMX enabled by default
Using config: /Users/yp-tc-m-7046/Documents/zookeeper/server1/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: follower
ZooKeeper JMX enabled by default
Using config: /Users/yp-tc-m-7046/Documents/zookeeper/server3/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: leader
然后调用./zkCli.sh -server ip:端口号调用就可以了