ZooKeeper的安装及配置 Mac
一,ZooKeeper安装及配置
1.打开ZooKeeper官网:http://zookeeper.apache.org/
2.点击下载,点击存档(所有版本的信息都在这个目录下)
3.选择所需下载稳定版本 zookeeper-3.4.12.tar.gz
4.下载 zookeeper-3.4.12.tar.gz
5.解压命令:tar -zxvf重命名命令:mv zookeeper-3.4.12 zookeeper
6.移动到/ usr / local文件目录下,命令:
sudo mv zookeeper / usr / local
7.配置环境变量:vim / etc / profile
二,zookeeper 的主要目录结构
LICENSE.txt ivy.xml
NOTICE.txt ivysettings.xml
README.md lib
README_packaging.txt recipes
bin src
build.xml zookeeper-3.4.11.jar
conf zookeeper-3.4.11.jar.asc
contrib zookeeper-3.4.11.jar.md5
dist-maven zookeeper-3.4.11.jar.sha1
docs
bin:一些运行命令
conf:配置文件,zk.cfg需要配置
contrib:附加功能
dist-maven:mvn编译目录
docs:帮助文档
lib:依赖包
recipes:Demo代码
三,配置zoo.cfg
1.官网有如下描述
2.复制配置文件:cp zoo_sample.cfg zoo.cfg
3.客户化配置文件:vim zoo.cfg
tickTime:session超时时间配置
initLimit:集群节点同步时间
syncLimit:集群主节点与从节点发送消息的请求和应答时间
dataDir:默认目录
dataLogDir:日志目录
clientPort::端口号
创建目录DATADIR和dataLogDir
4.启动zookeeper,到zookeeper bin目录下执行./zkServer.sh start进行启动
四. 连接测试:
1. Cli连接:
> cd zookeeper-3.4.12/bin //切换到 bin目录
> ./zkCli.sh -server 127.0.0.1:2181
[zk: 127.0.0.1:2181(CONNECTED) 0] help //输入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: 127.0.0.1:2181(CONNECTED) 2] ls /
[zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 3] create /zk_test my_data
Created /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 4] ls /
[zookeeper, zk_test]
[zk: 127.0.0.1:2181(CONNECTED) 5] get /zk_test
my_data
cZxid = 0x2
ctime = Wed Feb 28 15:18:45 CST 2018
mZxid = 0x2
mtime = Wed Feb 28 15:18:45 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 6] set /zk_test junk
cZxid = 0x2
ctime = Wed Feb 28 15:18:45 CST 2018
mZxid = 0x3
mtime = Wed Feb 28 15:20:23 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 7] get /zk_test
junk
cZxid = 0x2
ctime = Wed Feb 28 15:18:45 CST 2018
mZxid = 0x3
mtime = Wed Feb 28 15:20:23 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 8] delete /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 9] ls
[zk: 127.0.0.1:2181(CONNECTED) 10] ls /
[zookeeper]
2. 停止Server
> ./zkServer.sh stop //停止后,如果CLi没有关闭,将报错
ZooKeeper JMX enabled by default
Using config: zookeeper-3.4.12/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
3. 配置文件说明
文件名可以任意,不是非得改为zoo.cfg
tickTime: zookeeper中使用的基本时间单位, 毫秒
dataDir: 内存数据快照的保存目录;如果没有自定义Log也使用该目录
clientPort: 监听Cli连接的端口号