一、下载
官网下载链接:https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
二、安装
这里我是在本地(mac)安装滴,也可以在服务器安装,随你啦。
在本地解压至/Users/用户名/app:
tar -zxvf zookeeper-3.4.6.tar.gz -C /Users/huluwa/app
将解压后的文件夹改名:
mv zookeeper-3.4.6/ zookeeper
三、配置(要运行zk就需要此配置)
在安装路径:/Users/huluwa/app/zookeeper/conf中 新建 配置文件zoo.cfg
cp zoo_sample.cfg zoo.cfg
conf中的zoo_sample.cfg是默认的配置文件(以cfg结尾),如果用户没有新建cfg配置文件,就使用默认的。
now,先新建一个文件夹用于配置中的dataDir路径配置。
vim ~/data #路径为 /Users/huluwa/data
接着配置zoo.cfg(主要是配置dataDir):
# 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/data/zookeeper
dataDir=/Users/huluwa/data #其实主要是配置这个参数啦啦啦
# 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
四、配置环境变量
这步可配也可以不配置。配置了就能在全局执行zk的命令了,不然只能进入zk 的安装路径下执行一些命令。
五、启动服务
进入zk安装路径
cd ~/app/zookeeper/
cd bin/
ls
zkCli.sh 客户端执行文件, zkServer.sh 服务端执行文件
ok,let's 启动客户端服务:
./zkServer.sh start
omg! 出现了权限错误:
那我们给这个文件夹赋全部的权限吧!
chmod -R 777 /Users/huluwa/data/zookeeper #777是全部的权限
ok,再一次启动服务端服务:
./zkServer.sh start
六、查看zookeeper运行及状态
安装后,可以看到zookeeper提供了zkCli等工具。
同样,在bin目录下,执行:
./zkCli.sh