1 Local mode configuration

  1. Decompress the installation package

    Tar -zxvf zookeeper-3.4.10.tar.gz -c /opt/module/Copy the code
  2. Configuration changes

    A. Change zoo_sample. CFG in the conf directory to zoo.cfg

    mv zoo_sample.cfg zoo.cfg
    Copy the code

    B. Modify the dataDir path

    DataDir = / opt/software/zookeeper - 3.4.10 / zkDataCopy the code

    C. Create a zkData folder

    make zkData
    Copy the code
  3. Operating zookeeper

    A. start

    [mayi@mayi101 zookeeper-3.4.10]$bin/ zkserver. sh start Zookeeper JMX enabled by default Using config: / opt/software/zookeeper - 3.4.10 / bin /.. /conf/zoo.cfg Starting zookeeper ... STARTEDCopy the code

    B. Check whether the process is started

    [mayi@mayi101 zookeeper-3.4.10]$JPS 2257 -- Main class information Unavailable 2268 JPSCopy the code

    C. View the status

    [mayi@mayi101 zookeeper-3.4.10]$bin/ zkserver. sh status Zookeeper JMX enabled by default Using config: / opt/software/zookeeper - 3.4.10 / bin /.. /conf/zoo.cfg Mode: standaloneCopy the code

    D. Start the client

    [mayi @ mayi101 zookeeper - 3.4.10] $bin/zkCli. ShCopy the code

    E. Exit the client

    quit
    Copy the code

    F. stop zookeeper

    [mayi@mayi101 zookeeper-3.4.10]$bin/ zkserver. sh stop Zookeeper JMX enabled by default Using config: / opt/software/zookeeper - 3.4.10 / bin /.. /conf/zoo.cfg Stopping zookeeper ... STOPPEDCopy the code

2 Zoo. CFG parameter interpretation

The meanings of parameters in Zookeeper configuration file zoo. CFG are described as follows:

1. TickTime =2000: Indicates the communication heartbeat duration between the Zookeeper server and the client, in milliseconds

Basic time used by Zookeeper. Interval for maintaining heartbeat between servers or between clients and servers. That is, each tickTime sends a heartbeat, in milliseconds.

It is used for the heartbeat mechanism and sets the minimum session timeout to twice the heartbeat time. (The minimum session timeout is 2*tickTime)

2. InitLimit =10: indicates the initial communication duration of LF

Maximum number of heartbeat beats (the number of Ticktimes) that can be tolerated during the initial connection between the Follower server and the Leader server in the cluster, which is used to limit the duration of the connection between the Zookeeper server and the Leader server in the cluster.

3. SyncLimit =5: INDICATES the SYNCHRONIZATION communication duration of LF

A unit of maximum response time between the Leader and Follower in the cluster. If the response time exceeds syncLimit * tickTime, the Leader considers the Follwer dead and deletes the Follwer from the server list.

4. DataDir: data file directory + persistent path

Used to save data in Zookeeper.

5. ClientPort =2181: indicates the client connection port

Listen for the port to which the client is connected.

3 Distributed mode configuration

  1. Cluster planning

    Zookeeper is deployed on mayi101, Mayi102, and Mayi103 nodes

  2. Decompress the previous single-node mode (distribute the decompressed ones to mayi102 and Mayi103 nodes)

  3. Configuring the Server Number

    A. create zkData

    mkdir -p zkData
    Copy the code

    B. Create a myID file under zkData

    touch myid
    Copy the code

    Add myid file, be sure to create in Linux, in notepad++ is likely to be garbled

    C. Edit the myID file

    vim myid
    Copy the code

    D. Add the server NUMBER to the file

    1
    Copy the code

    E. Distribute the zooKeeper configuration to other nodes and change the myID of other nodes

    Mayi102 corresponds to 2, mayi103 corresponds to 3Copy the code
  4. Configuration zoo. CFG

    See zoo. CFG in local mode above for configuration

    And add the server node configuration to zoo.cfg

    vim zoo.cfg
    
    #Add the following
    #######################cluster##########################
    server.1=mayi101:2888:3888
    server.2=mayi102:2888:3888
    server.3=mayi103:2888:3888
    Copy the code

    CFG file to synchronize

    CFG #xsync is a self-written distribution script, not sent to the corresponding other service nodesCopy the code
    • Interpretation of Configuration Parameters

      Server. A = B: C: D.Copy the code

      A: Is A number, which server, corresponding to the server myID

      In cluster mode, A file myID is configured, which is in the dataDir directory. There is A data in this file that is the value of A. When Zookeeper starts up, it reads this file and compares the data with the configuration information in zoo.cfg to determine which server it is.

      B: Is the address of this server (write IP is also ok)

      C: is the port through which the followers of the server exchange information with the Leader server in the cluster

      D: Yes, in case the Leader server in the cluster fails, a port is needed to re-elect a new Leader, and this port is used to communicate with each other during the election.

  5. Cluster operations

    Start ZooKeeper respectively

    You can configure zooKeeper environment variables so that you do not need to go to the specified directory every time you start zooKeeper

    #ZK_HOMEExport ZK_HOME = / opt/software/zookeeper - 3.4.10Copy the code

    Start the ZooKeeper service on each node

    [mayi@mayi101 ~]$ zkServer.sh start
    [mayi@mayi102 ~]$ zkServer.sh start
    [mayi@mayi103 ~]$ zkServer.sh start
    Copy the code

    Check the status

    [mayi@mayi101 ~]$ zkServer.sh status ZooKeeper JMX enabled by default Using config: / opt/software/zookeeper - 3.4.10 / bin /.. /conf/zoo.cfg Mode: leader [mayi@mayi102 ~]$ zkServer.sh status ZooKeeper JMX enabled by default Using config: / opt/software/zookeeper - 3.4.10 / bin /.. /conf/zoo.cfg Mode: follower [mayi@mayi103 ~]$ zkServer.sh status ZooKeeper JMX enabled by default Using config: / opt/software/zookeeper - 3.4.10 / bin /.. /conf/zoo.cfg Mode: followerCopy the code
  6. Start and close scripts

    ZkStart. Sh * * * * * * * * * * * * * * * * * * * * * open zookeeper * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    #! /bin/bashif (($#==0)) then exit 1; fi for i in mayi101 mayi102 mayi103 do echo Starting zk in $i ssh $i "zkServer.sh $1" > /dev/null done zkStop.sh * * * * * * * * * * * * * * * * * * * * * stop zookeeper * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *#! /bin/bash
    
    if (($#==0))
    then
        exit 1;
    fi
    for i in mayi101 mayi102 mayi103
    do
        echo Starting zk in $i
        ssh $i "zkServer.sh $1" > /dev/null
    done
    Copy the code