centos7 搭建zookeeper环境

一、单机部署zookeeper

  1. 从官网下载zookeeper安装包(路径:/opt)
  2. tar -zxvf zookeeper-3.4.10.tar.gz zookeeper
  3. cd zookeeper/conf
  4. cp zoo_sample.cfg zoo.cfg,编辑如下
    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/data
    clientPort=2181
    dataLogDir=/opt/zookeeper/logs
    server.1=localhost:2888:3888
    
  5. 准备启动环境
    mkdir /var/lib/zookeeper
    mkdir /opt/zookeeper/logs
    echo "1" > /tmp/zookeeper/myid
    
  6. /opt/zookeeper/bin/zkServer.sh start 启动zookeeper
  7. jps 查询zookeeper运行状态

二、集群,按照上述配置多台(奇数)。

三、伪集群部署

  1. 同样解压文件(/opt/zookeeper)。

  2. 创建配置文件

    cd zookeeper/conf
    cp zoo_sample.cfg zoo1.cfg
    cp zoo_sample.cfg zoo2.cfg
    cp zoo_sample.cfg zoo3.cfg
    
  3. zoo1.cfg 如下

    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/data/d_1
    clientPort=2181
    dataLogDir=/opt/zookeeper/logs/log_1
    server.1=localhost:2887:3887
    server.2=localhost:2888:3888
    server.3=localhost:2889:3889
    

    zoo2.cfg 如下

    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/data/d_2
    clientPort=2182
    dataLogDir=/opt/zookeeper/logs/log_2
    server.1=localhost:2887:3887
    server.2=localhost:2888:3888
    server.3=localhost:2889:3889
    

    zoo3.cfg 如下

    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/data/d_3
    clientPort=2183
    dataLogDir=/opt/zookeeper/logs/log_3
    server.1=localhost:2887:3887
    server.2=localhost:2888:3888
    server.3=localhost:2889:3889
    
  4. 启动前目录创建

    mkdir /opt/zookeeper/data/d_1
    mkdir /opt/zookeeper/data/d_2
    mkdir /opt/zookeeper/data/d_3
    
    mkdir /opt/zookeeper/logs/log_1
    mkdir /opt/zookeeper/logs/log_2
    mkdir /opt/zookeeper/logs/log_3
    
    echo "1" > /opt/zookeeper/data/d_1/myid
    echo "2" > /opt/zookeeper/data/d_2/myid
    echo "3" > /opt/zookeeper/data/d_3/myid
    
  5. 启动集群

    cd /opt/zookeeper/bin
    ./zkServer.sh start zoo1.cfg
    ./zkServer.sh start zoo2.cfg
    ./zkServer.sh start zoo3.cfg
    
  6. jps 查看进程

    #出现下面三个实例表示成功
    1794 Jps
    1735 QuorumPeerMain
    1689 QuorumPeerMain
    1710 QuorumPeerMain
    

你可能感兴趣的:(centos7 搭建zookeeper环境)