zookeeper cluster configuration

Posted by Brad7928 on Thu, 20 Jun 2019 03:43:25 +0200

Download and install

from Official website Download the latest version of zookeeper

Relevant address: http://mirror.bit.edu.cn/apache/zookeeper/current/

# wget --quiet http://mirror.bit.edu.cn/apache/zookeeper/current/zookeeper-3.4.10.tar.gz

# tar -xf zookeeper-3.4.10.tar.gz
# cd zookeeper-3.4.10

Enter the conf directory, change the default zoo_sample.cfg to zoo.cfg, and execute the command: bin/zkServer.sh start.

zkServer command related parameters:

Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}

Cluster configuration

Cluster nodes must be odd

  1. Three copies of zookeeper directory are extracted, such as zookeeper 1, zookeeper 2 and zookeeper 3.
  2. Create and modify the configuration file zoo0x.cfg, dataDir and clientPort can not be the same.
  3. Create the file myid in three dataDir directories and store the corresponding number of service nodes, such as server.1 storage 1.
  4. After the modifications are completed, the zookeeper service node can be started by running bin/zkServer.sh.

Configuration file reference:

vim /opt/zookeeper01/conf/zoo01.cfg
# 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=/tmp/zookeeper01
dataDir=/data/product/zookeeper01/datadir
# the port at which the clients will connect
clientPort=2181
# listen ip address
#clientPortAddress=localhost
# 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
server.01=localhost:2887:3887 
server.02=localhost:2888:3888
server.03=localhost:2889:3889

Cluster Service Configuration Description

server.A=B:C:D
- A is a number, indicating which server this is.
- B is the IP address of the server (or the host name mapped to the IP address).
- The first port of C is used for exchanging information between cluster members, which represents the port of exchanging information between the server and the Leader server in the cluster.
- D is the port used to elect leader when leader hangs up.

About Logs

By default, zookeeper's log is based on the path where the bin/zkServer.sh start command is executed. Under the current path, a file named zookeeper.out is created and the log content is written to it.

Modification logs are saved under fixed path files:

1. Modify the startup script bin/zkServer.sh and add:

ZOO_LOG_DIR="$ZOOBINDIR/../logs"

2. Modify vim bin/zkEnv.sh

 42 if [ "x$ZOOCFG" = "x" ]
 43 then
 44     ZOOCFG="zoo02.cfg"

Client Link Cluster

spring:
  cloud:
    zookeeper:
      connect-string: localhost:2181,localhost:2182,localhost:2183

Note: If you use the Spring Cloud Zookeeper Config module, you must configure it in bootstrap.yml

Note: The zookeeper cluster is better to keep odd nodes. If only one node is left in the cluster, the cluster will fail and the client will not be able to connect.

Topics: Zookeeper Apache vim Spring