zookeeper environment configuration

1 local mode configuration

  1. Unzip the installation package

    tar -zxvf zookeeper-3.4.10.tar.gz -C /opt/module/
    
  2. Configuration modification

    a. Set the zoo in the conf directory_ sample. CFG is modified to zoo cfg

    mv zoo_sample.cfg zoo.cfg
    

    b. Modify dataDir path

    dataDir=/opt/software/zookeeper-3.4.10/zkData
    

    c. Create zkData folder

    make zkData
    
  3. Operation 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 ... STARTED
    

    b. Check whether the process starts

    [mayi@mayi101 zookeeper-3.4.10]$ jps
    2257 -- main class information unavailable
    2268 Jps
    

    c. View 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: standalone
    

    d. Start client

    [mayi@mayi101 zookeeper-3.4.10]$ bin/zkCli.sh 
    

    e. Exit client

    quit
    

    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 ... STOPPED
    

2 zoo. Interpretation of CFG parameters

The configuration file zoo. In Zookeeper The meaning of parameters in CFG is interpreted as follows:

1. tickTime =2000: Communication heartbeat, heartbeat time between Zookeeper server and client, unit: Ms

The basic time used by Zookeeper, the time interval between servers or between clients and servers to maintain heartbeat, that is, one heartbeat will be sent every tickTime, and the time unit is milliseconds.

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

2. initLimit =10: initial communication time limit of LF

The maximum number of heartbeats (the number of ticktimes) that can be tolerated during the initial connection between the Follower server and the Leader server in the cluster. It is used to limit the time limit for the Zookeeper server in the cluster to connect to the Leader.

3. syncLimit =5: LF synchronous communication time limit

The maximum response time unit between the Leader and the Follower in the cluster. If the response exceeds syncLimit * tickTime, the Leader thinks the Follower is dead and deletes the Follower from the server list.

4. dataDir: data file directory + data persistence path

It is mainly used to save the data in Zookeeper.

5. clientPort =2181: client connection port

Listen to the port of the client connection.

3 distributed mode configuration

  1. Cluster planning

    Zookeeper is deployed on mayi101,mayi102 and mayi103 nodes

  2. Decompress the above single node mode (both decompressed nodes need to be distributed to mayi102 and mayi103)

  3. Configure server number

    a. Create zkData

    mkdir -p zkData
    

    b. Create a myid file under zkData

    touch myid
    

    When adding myid files, be sure to create them in linux. They may be garbled in notepad + +

    c. Edit myid file

    vim myid
    

    d. Add the number corresponding to the server in the file

    1
    

    e. Distribute the configured zookeeper to other nodes and modify the myid number corresponding to other nodes

    mayi102 Corresponding to 2, mayi103 Corresponding 3
    
  4. Configure zoo cfg

    Refer to the zoo in the local mode above CFG configuration

    And for zoo CFG add server node configuration

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

    Sync zoo Cfg file

    xsync zoo.cfg  #xsync is a distribution script written by itself, which is not sent to the corresponding other service nodes
    
    • Interpretation of configuration parameters

      server.A=B:C:D. 
      

      A: Is a number, which represents the server and corresponds to the myid in the server

      In the cluster mode, configure a file myid. This file is in the dataDir directory. There is a data in this file, which is the value of A. when Zookeeper starts, read this file and get the data and zoo Compare the configuration information in CFG to determine which server it is.

      B: Is the address of this server (write IP can also be used)

      C: This is the port where the Follower server exchanges information with the Leader server in the cluster

      D: In case the Leader server in the cluster hangs up, a port is needed to re elect and select a new Leader, and this port is used to communicate with each other during the election.

  5. Cluster operation

    Start zookeeper separately

    You can configure the environment variable of zookeeper without having to go to the specified directory every time you start

    #ZK_HOME
    export ZK_HOME=/opt/software/zookeeper-3.4.10
    

    Each node starts the zookeeper service

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

    View 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: follower
    
  6. Start and close scripts

    zkStart.sh
    *********************open 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
    
    
    zkStop.sh
    *********************stop it 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
    

Tags: Linux MariaDB Zookeeper bash markdown v-im

Posted by lssjg on Sat, 16 Apr 2022 03:01:16 +0300