一,下载zookeeper到/opt目录下
二,解压
Bash
tar -zxvf zookeeper-3.4.14.tar.gz
三,拷贝一份zookeeper
Bash
cp zookeeper-3.4.14 zookeeper1
四,配置zookeeper
拷贝配置文件
cd /opt/zookeeper1/conf
cp zoo_sample.cfg zoo.cfg
编辑配置文件
dataDir=/opt/zookeeper1/data #zk数据存放目录
clientPort=2181 #zk服务端口
末尾加上
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
五,拷贝zookeeper文件模拟集群
cp /opt/zookeeper1 /opt/zookeeper2 /opt/zookeeper3
六,依次修改2,3配置
zookeeper2配置修改为:
dataDir=/opt/zookeeper2/data #zk数据存放目录
clientPort=2182 #zk服务端口
末尾加上
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
zookeeper3配置修改为:
dataDir=/opt/zookeeper3/data #zk数据存放目录
clientPort=2183 #zk服务端口
末尾加上
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
七,启动三个实例
/opt/zookeeper1/bin/zkServer.sh start
/opt/zookeeper2/bin/zkServer.sh start
/opt/zookeeper3/bin/zkServer.sh start
启动完之后查看zookeeper状态
/opt/zookeeper1/bin/zkServer.sh status
出现如下信息:
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper1/bin/../conf/zoo.cfg
Mode: follower 意思是从节点
Mode: leader 主节点
说明:zookeeper主节点启动或挂掉后会自动选举主节点,建议使用奇数台节点。