搭建采用zookeeper-3.4.12.tar.gz包
    三台服务器分别是
    10.4.7.111
    10.4.7.112
    10.4.7.113
    然后在三台服务器分别安装zookeeper

    解压到user/local下

    1. tar -zxvf zookeeper-3.4.12.tar.gz -C /usr/local mv /usr/local/zookeeper-3.4.12 /usr/local/zookeeper

    修改配置文件

    1. cp /usr/local/zookeeper/conf/zoo_sample.cfg
    2. /usr/local/zookeeper/conf/zoo.cfg
    3. vim /usr/local/zookeeper/conf/zoo.cfg
    4. tickTime=2000
    5. initLimit=10
    6. syncLimit=5
    7. dataDir=/usr/local/zookeeper/data
    8. clientPort=2181
    9. server.1=10.4.7.111:2888:3888
    10. server.2=10.4.7.112:2888:3888
    11. server.3=10.4.7.113:2888:3888

    创建数据存储目录

    1. mkdir -p /usr/local/zookeeper/data

    创建myid文件, id 与 zoo.cfg 中的序号对应

    1. #在192.168.2.158机器上执行
    2. echo 1 > /usr/local/zookeeper/data/myid
    3. #在192.168.2.152机器上执行
    4. echo 2 > /usr/local/zookeeper/data/myid
    5. #在192.168.2.150机器上执行
    6. echo 3 > /usr/local/zookeeper/data/myid

    配置环境变量
    vim /etc/profile
    在最后加上
    export ZK_HOME=/usr/local/zookeeper export PATH=$ZK_HOME/bin:$PATH
    分别启动

    1. zkServer.sh start

    查看状态

    1. [root@masterexample data]# zkServer.sh status
    2. ZooKeeper JMX enabled by default
    3. Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
    4. Mode: leader

    关闭防火墙,否则看不到节点状态

    1. systemctl stop firewalld

    重新启动

    1. [root@masterexample data]# zkServer.sh restart
    2. ZooKeeper JMX enabled by default
    3. Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
    4. ZooKeeper JMX enabled by default
    5. Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
    6. Stopping zookeeper ... no zookeeper to stop (could not find file /usr/local/zookeeper/data/zookeeper_server.pid)
    7. ZooKeeper JMX enabled by default
    8. Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
    9. Starting zookeeper ... STARTED