zookeeper Pseudo-Distributed Architecture

  1. Get the zookeeper binary package, address[ https://www.apache.org/dyn/closer.cgi/zookeeper/](https://www.apache.org/dyn/closer.cgi/zookeeper/
    The current stable version is 3.4.14
  2. Unzip the file to a custom directory, where I unzip it to / opt/zookeeper
    # tar -xf zookeeper-3.4.14.tar.gz -C /opt/
    # cd /opt/
    # mv zookeeper-3.4.14/ zookeeper
  3. Go into the zookeeper configuration file directory (/ opt/zookeeper/conf), and create three configuration files, zoo1. cfg, zoo2. cfg, zoo3. cfg. The configuration file can be modified by the default zoo_sample.cfg, the contents of which are as follows
    zoo1.cfg:
    # grep -E -v '^#.*|^$' zoo1.cfg
    tickTime=2000                     #The default heartbeat time between CS is 2 seconds
    initLimit=10                      #Maximum number of heartbeats tolerated by follower and leader servers initially connected in a cluster
    syncLimit=5                       #Maximum tolerable heartbeat number of requests and responses between follower and leader servers in a cluster
    dataDir=/opt/zookeeper/Server1/data    #This directory is used to store myid information and some versions, etc.
    dataLogDir=/opt/zookeeper/Server1/log  #Log directory
    clientPort=2181                   #The default port for client connection is 2181
    maxClientCnxns=6000               #maximum connection
    maxSessionTimeout=60000           #Session Overtime
    server.1=test3:2888:3888          #Cluster configuration information server.N = HHHH: A: B N server number, HHH server address, A means the communication port between flower and leader, default 2888, B means the election port, default 3888
    server.2=test3:2788:3788
    server.3=test3:2688:3688

    zoo2.cfg:

    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/Server2/data
    dataLogDir=/opt/zookeeper/Server2/log
    clientPort=2182
    server.1=test3:2888:3888
    server.2=test3:2788:3788
    server.3=test3:2688:3688

    zoo3.cfg

    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/opt/zookeeper/Server3/data
    dataLogDir=/opt/zookeeper/Server3/log
    clientPort=2183
    server.1=test3:2888:3888
    server.2=test3:2788:3788
    server.3=test3:2688:3688
  4. Create corresponding data directories and log directories
    # mkdir -pv /opt/zookeeper/Server{1,2,3}/{data,log}
  5. Create the file myid in the folder specified by dataDir. The content of the myid file is the id number of the corresponding server, ranging from 0 to 255
    # echo 1 > opt/zookeeper/Server1/data/myid 
    # echo 2 > opt/zookeeper/Server2/data/myid 
    # echo 3 > opt/zookeeper/Server3/data/myid 
  6. Add PATH environment variables
    # vi /etc/profile.d/zookeeper.sh
    export ZOOKEEPER_HOME=/opt/zookeeper
    export PATH=$PATH:$ZOOKEEPER_HOME
    # . /etc/profile.d/zookeeper.sh
  7. Start zookeeper with different configuration files
    # zkServer.sh start /opt/zookeeper/conf/zoo1.cfg
    # zkServer.sh start /opt/zookeeper/conf/zoo2.cfg
    # zkServer.sh start /opt/zookeeper/conf/zoo3.cfg
  8. View zookeeper status

    # zkServer.sh status /opt/zookeeper/conf/zoo1.cfg
    # zkServer.sh status /opt/zookeeper/conf/zoo2.cfg
    # zkServer.sh status /opt/zookeeper/conf/zoo3.cfg
  9. Matters needing attention
  • Do not set three port numbers to the same
  • Every dataDir directory has myid files
  • Each myid file should correspond to a number followed by server in zoo.cfg

Tags: Linux Zookeeper Apache Session

Posted on Mon, 08 Apr 2019 23:00:31 -0400 by master123467