解压zookeeper,tar -zxvf zookeeper-3.4.6.tar.gz
将zookeeper-3.4.6拷贝到/opt下,复制三份分别并将目录名改为zookeeper1、zookeeper2、zookeeper3
//创建data目录
mkdir /opt/zookeeper1/data
mkdir /opt/zookeeper2/data
mkdir /opt/zookeeper3/data
echo 1 > /opt/zookeeper1/data/myid
echo 2 > /opt/zookeeper2/data/myid
echo 3 > /opt/zookeeper3/data/myid
cd /opt/zookeeper1/conf
cp zoo_sample.cfg zoo.cfg
//修改datadir如下
dataDir=/opt/zookeeper1/data
clientPort=2181(zookeeper2中为2182、zookeeper3中为2183)
在末尾添加这三项配置(注意:2881和3881分别是zookeeper之间通信的端口号、zookeeper之间选举使用的端口号。2181是客户端连接的端口号,别搞错了哦):
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882
server.3=127.0.0.1:2883:3883
cp /opt/zookeeper1/conf/zoo.cfg /opt/zookeeper2/conf/
cp /opt/zookeeper1/conf/zoo.cfg /opt/zookeeper3/conf/
//修改dataDir和clientPort对应值
/opt/zookeeper1/bin/zkServer.sh start
/opt/zookeeper2/bin/zkServer.sh start
/opt/zookeeper3/bin/zkServer.sh start
/opt/zookeeper1/bin/zkServer.sh status
/opt/zookeeper2/bin/zkServer.sh status
/opt/zookeeper3/bin/zkServer.sh status