zookeeper集群安装配置

之前介绍了zookeeper基本原理,这篇文章讲zk集群安装

zk service节点列表

192.168.1.1
192.168.1.2
192.168.1.3

zk安装包下载


[192.168.1.1]$ wget http://archive.apache.org/dist/hadoop/zookeeper/zookeeper-3.3.1/zookeeper-3.3.1.tar.gz
sudo tar -zxvf /home/wanghua.wh/zookeeper-3.3.1.tar.gz -C /usr/local/
[192.168.1.1]$ sudo mkdir /usr/local/zookeeper
[192.168.1.1]$ sudo mv /usr/local/zookeeper-3.3.1/ /usr/local/zookeeper
[192.168.1.1]$ cd /usr/local/zookeeper/conf
[192.168.1.1]$ cp zoo_sample.cfg zoo.cfg

zk配置

[192.168.1.1]$ vim zoo.cfg

dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/log
clientPort=2181 
initLimit=10 
syncLimit=5 
tickTime=2000
server.1=192.168.1.1:2888:3888 
server.2=192.168.1.2:2888:3888 
server.3=192.168.1.3:2888:3888

建立配置路径

/usr/local/zookeeper/data 是zk meta信息持久化到磁盘的路径
/usr/local/zookeeper/log  是zk log的存放路径
myid的数值就是server.N的N数字

[192.168.1.1]$ mkdir /usr/local/zookeeper/data
[192.168.1.1]$ mkdir /usr/local/zookeeper/log
[192.168.1.1]$ echo 1 > /usr/local/zookeeper/data/myid

[192.168.1.2]$ mkdir /usr/local/zookeeper/data
[192.168.1.2]$ mkdir /usr/local/zookeeper/log
[192.168.1.2]$ echo 2 > /usr/local/zookeeper/data/myid

[192.168.1.3]$ mkdir /usr/local/zookeeper/data
[192.168.1.3]$ mkdir /usr/local/zookeeper/log
[192.168.1.3]$ echo 3 > /usr/local/zookeeper/data/myid

zk状态控制

集群启动

[192.168.1.1]$ /usr/local/zookeeper/bin/zkServer.sh start
[192.168.1.2]$ /usr/local/zookeeper/bin/zkServer.sh start
[192.168.1.3]$ /usr/local/zookeeper/bin/zkServer.sh start

状态查看

/usr/local/zookeeper/bin/zkServer.sh status
可以查看哪个是leader,剩余的就是follower

zk自带console

[192.168.1.1]$ zkCli.sh -server 192.168.1.1:2181
[zk: 192.168.1.1:2181(CONNECTED) 8] ls /
[zookeeper]
/zookeeper是预保留的

标签:Zookeeper