HeLei Blog

zookeeper部署

最新的版本可以通过官网 http://hadoop.apache.org/zookeeper/来获取,Zookeeper 的安装非常简单,下面将从单机模式和集群模式两个方面介绍 Zookeeper 的安装和配置。

单机模式

  1. 解压安装包zookerper-3.4.7.tar.gz

    1
    tar -xzvf zookerper-3.4.7.tar.gz
  2. 创建Zookeeper子目录

    1
    cp -r zookerper-3.4.7 zookerper
  3. 修改Zookeeper配置文件conf/zoo.cfg

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    # 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=./data
    dataLogDir=./logs
    # 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
  4. 运行

    1
    2
    $ cd bin
    $ ./zkServer.sh start
  5. 查看运行状态

    1
    ./zkServer.sh status

伪集群模式

  1. 新建两个directory

    1
    2
    cp -r zookeeper/ zookerper1/
    cp -r zookeeper/ zookerper2/
  2. 修改Zookeeper配置文件conf/zoo.cfg,这里配置了3个实例

    1
    2
    3
    server.1=localhost:2887:3887
    server.2=localhost:2888:3888
    server.3=localhost:2889:3889
  3. 分别在data目录下添加myid文件

    1
    2
    3
    echo "1" > myid
    echo "2" > myid
    echo "3" > myid
  4. 分别运行3个实例

坚持原创技术分享,您的支持将鼓励我继续创作!