zookeeper安装及环境变量设置

时间:2022-07-29 19:18:57

下载

首先去官网下载(自行选择版本):
http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.11/
然后执行tar -zxvf解压

对于后台安装,可以直接使用如下命令。一般建议使用root安装,放到系统目录。

su -
cd /usr/local
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
tar xvfz zookeeper-3.4..tar.gz

环境变量

建议设置环境变量,把zookeeper目录增加到PATH里,这样后续使用客户端连接不需要cd 到安装目录

vi /etc/profile
export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.11
export PATH=$PATH:$ZOOKEEPER_HOME/bin

启动

进入conf目录,拷贝zoo_simple.cfg成zoo.cfg。

直接执行脚本启动服务器:

zkServer.sh start

然后执行脚本启动客户端:

zkCli.sh

在命令行中输入help,得到结果:

[zk: localhost:(CONNECTED) ] help
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port
[zk: localhost:(CONNECTED) ]

停止

zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4./bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

zookeeper server自启动

通过/etc/init.d目录,增加你自己的脚本实现自启动。可以参考这篇文章:linux系统增加开机启动服务/应用

cd /etc/init.d
vi start_zk.sh

把如下脚本放到start_zk.sh保存

/usr/local/zookeeper-3.4./zkServer.sh start
root@jacob-PC:~# chkconfig --add customize.sh
insserv: warning: script 'K01customize.sh' missing LSB tags and overrides
insserv: warning: script 'customize.sh' missing LSB tags and overrides
customize.sh :off :off :on :on :on :on :off
root@jacob-PC:~# chkconfig customize.sh on
insserv: warning: script 'K01customize.sh' missing LSB tags and overrides
insserv: warning: script 'customize.sh' missing LSB tags and overrides

额外说明

官方提供的版本就包括了Linux和windows的版本,windows的服务启停采用zkServer.cmd,客户端启停zkCli.cmd