Rate This Document
Findability
Accuracy
Completeness
Readability

Deploying ZooKeeper

Downloading and Decompressing ZooKeeper

  1. Log in to the agent1 node and go to the /usr/local directory. Download zookeeper-3.4.6.tar.gz and decompress it.
    1
    2
    3
    cd /usr/local
    wget http://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
    tar -zxvf zookeeper-3.4.6.tar.gz
    
  2. Create a soft link for subsequent version update.
    1
    ln -s zookeeper-3.4.6 zookeeper
    

Adding ZooKeeper to Environment Variables

  1. Log in to the agent1 node and open the configuration file.
    1
    vi /etc/profile
    
  2. Press i to enter the insert mode and add ZooKeeper to environment variables.
    1
    2
    export ZOOKEEPER_HOME=/usr/local/zookeeper
    export PATH=$ZOOKEEPER_HOME/bin:$PATH
    
  3. Press Esc, type :wq!, and press Enter to save the file and exit.
  4. Make the environment variables take effect.
    1
    source /etc/profile
    
  5. Repeat steps 1 to 4 on agent2 and agent3 to set ZooKeeper environment variables.

Modifying the ZooKeeper Configuration Files

  1. Log in to the agent1 node and go to the directory where ZooKeeper is located.
    1
    cd /usr/local/zookeeper/conf
    
  2. Copy the configuration file.
    1
    cp zoo_sample.cfg zoo.cfg
    
  3. Modify the common settings.
    1. Open the file.
      1
      vi zoo.cfg
      
    2. Press i to enter the insert mode and modify the data directory.
      1
      dataDir=/usr/local/zookeeper/tmp
      
    3. Optional: Add the AdminServer configuration. (This configuration item is introduced in ZooKeeper 3.5.0. For an earlier version, skip this step.)
      1
      admin.enableServer=false
      
    4. Add the following code to the end of the file. server.1 to server.3 are the nodes where ZooKeeper is deployed.
      1
      2
      3
      server.1=agent1:2888:3888
      server.2=agent2:2888:3888
      server.3=agent3:2888:3888
      
    5. Press Esc, type :wq!, and press Enter to save the file and exit.
  4. Add the JMX configuration.
    1. Open the zkServer.sh file.
      1
      vi /usr/local/zookeeper/bin/zkServer.sh
      
    2. Press i to enter the insert mode and add the JMX configuration to the line shown in the following figure:
      1
      JMXDISABLE=true
      

      If the ZooKeeper version is 3.6 or later, you can create a zookeeper-env.sh file in the /usr/local/zookeeper/conf directory and add the JMX configuration to the file.

    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  5. Optional: Add the JVM configuration.

    If the ZooKeeper version is 3.6 or later, skip this step because the configuration has been preset.

    1. Open the zkEnv.sh file.
      1
      vi /usr/local/zookeeper/bin/zkEnv.sh
      
    2. Press i to enter the insert mode and add the following content to the end of the file:
      1
      2
      3
      4
      5
      6
      7
      # default heap for zookeeper server
      ZK_SERVER_HEAP="${ZK_SERVER_HEAP:-10000}"
      export SERVER_JVMFLAGS="-Xmx${ZK_SERVER_HEAP}m $SERVER_JVMFLAGS"
      
      # default heap for zookeeper client
      ZK_CLIENT_HEAP="${ZK_CLIENT_HEAP:-256}"
      export CLIENT_JVMFLAGS="-Xmx${ZK_CLIENT_HEAP}m $CLIENT_JVMFLAGS"
      
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  6. Create a tmp directory as the data directory.
    1
    mkdir /usr/local/zookeeper/tmp
    
  7. Create an empty file in the tmp directory and write myid to the file.
    1
    2
    touch /usr/local/zookeeper/tmp/myid
    echo 1 > /usr/local/zookeeper/tmp/myid
    
  8. Configure the file permission.
    1
    2
    3
    4
    5
    chmod 750 /usr/local/zookeeper
    find /usr/local/zookeeper/bin -name "*.sh"  | xargs -i chmod 500 {}
    find /usr/local/zookeeper/conf -name "*" -type f | xargs -i chmod 600 {}
    chown -R root /usr/local/zookeeper-3.4.6
    chgrp -R root /usr/local/zookeeper-3.4.6
    

Synchronizing the Configuration to Other Nodes

  1. Log in to the agent1 node and copy the ZooKeeper configuration to other nodes.
    1
    2
    scp -r /usr/local/zookeeper-3.4.6 root@agent2:/usr/local
    scp -r /usr/local/zookeeper-3.4.6 root@agent3:/usr/local
    
  2. Create a soft link and modify myid on agent2 and agent3.
    • agent2:
      1
      2
      3
      cd /usr/local
      ln -s zookeeper-3.4.6 zookeeper
      echo 2 > /usr/local/zookeeper/tmp/myid
      
    • agent3:
      1
      2
      3
      cd /usr/local
      ln -s zookeeper-3.4.6 zookeeper
      echo 3 > /usr/local/zookeeper/tmp/myid