安装java环境,并配置好java相关的环境变量$JAVA_HOME。
1、下载并解压最新稳定的zookeeper文件
wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
tar -zxvf zookeeper-3.4.6.tar.gz
可执行文件都在bin/目录下,配置都在conf/目录下
2、生成配置文件
conf/目录下有个zoo_sample.cfg,是样板配置文件
复制一份成zoo.cfg
里面有两个比较重要的配置:
dataDir=/home/gradven/zookeeper-3.4.6/data # 数据存放位置,可根据需要修改
clientPort=2181 # 服务监听端口,可根据需要修改。
3、启动服务
bin/zkServer.sh start
如果未启动成功,一个检查JAVA_HOME是否正确设置,二个看端口是否冲突
4、启动客户端测试
启动命令:
bin/zkCli.sh -server 127.0.0.1:2181
显示根目录下、文件:
ls /
创建文件,并设置初始内容:
[zk: 127.0.0.1:2181(CONNECTED) 1] create /treeroot hello
Created /treeroot
[zk: 127.0.0.1:2181(CONNECTED) 2] get /treeroot
hello
cZxid = 0x2
ctime = Tue Oct 20 00:30:34 CST 2015
mZxid = 0x2
mtime = Tue Oct 20 00:30:34 CST 2015
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 3] delete /treeroot
[zk: 127.0.0.1:2181(CONNECTED) 4]
退出客户端:
quit
查看zookeeper的状态
[email protected]:~/zookeeper-3.4.6$ bin/zkServer.sh status
JMX enabled by default
Using config: /home/gradven/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
重启zookeeper 命令
[email protected]:~/zookeeper-3.4.6$ bin/zkServer.sh status
JMX enabled by default
Using config: /home/gradven/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
[email protected]:~/zookeeper-3.4.6$ bin/zkServer.sh restart
JMX enabled by default
Using config: /home/gradven/zookeeper-3.4.6/bin/../conf/zoo.cfg
JMX enabled by default
Using config: /home/gradven/zookeeper-3.4.6/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
JMX enabled by default
Using config: /home/gradven/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED