1、创建目录
mkdir /opt/zk/
2、下载
wget -P /opt/zk/ http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.5.6/apache-zookeeper-3.5.6-bin.tar.gz
3、解压
进入zk目录并解压
cd /opt/zk
tar -xf apache-zookeeper-3.5.6-bin.tar.gz
4、创建三个文件夹
mkdir 2180 2181 2182
mkdir 2180/data 2181/data 2182/data
mkdir 2180/logs 2181/logs 2182/logs
touch 2180/data/myid 2181/data/myid 2182/data/myid
echo 1 > 2180/data/myid
echo 2 > 2181/data/myid
echo 3 > 2182/data/myid
5、修改配置文件
5.1 拷贝一份配置文件
cp apache-zookeeper-3.5.6-bin/conf/zoo_sample.cfg zoo.cfg
5.2 编辑 zoo.cfg
vim zoo.cfg
把
dataDir=/tmp/zookeeper
clientPort=2180
注释掉
并在文件最后添加
clientPort=2180
dataDir=/opt/zk/2180/data
dataLogDir=/opt/zk/2180/logs
server.1=localhost:2187:2887
server.2=localhost:2188:2888
server.3=localhost:2189:2889
5.3 复制 三个配置文件
cp zoo.cfg 2180.cfg
cp zoo.cfg 2181.cfg
cp zoo.cfg 2182.cfg
5.4、修改复制好的两个配置文件 2181.cfg 和 2182.cfg
把其中的 2180 分别更改为 2181 和 2182
例如:2182.cfg配置如下
# 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=/tmp/zookeeper
# 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
clientPort=2182
dataDir=/opt/zk/2182/data
dataLogDir=/opt/zk/2180/logs
server.1=localhost:2187:2887
server.2=localhost:2188:2888
server.3=localhost:2189:2889
6、启动服务
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh start /opt/zk/2180.cfg
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh start /opt/zk/2181.cfg
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh start /opt/zk/2182.cfg
7、查看其三个的启动状态
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh status /opt/zk/2180.cfg
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh status /opt/zk/2181.cfg
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh status /opt/zk/2182.cfg
我们可以看到只有其中一个是leader
Mode: leader
8、启动zk客户端登录
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkCli.sh -server localhost:2180,localhost:2181,localhost:2182
8.1 查看zk中的节点信息
ls /
8、停止服务
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh stop /opt/zk/2180.cfg
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh stop /opt/zk/2181.cfg
/opt/zk/apache-zookeeper-3.5.6-bin/bin/zkServer.sh stop /opt/zk/2182.cfg

