mac installation zookeeper pseudo cluster

Keywords: Zookeeper Apache Session snapshot

Catalogue
1. Configuration
2. Start all servers of zookeeper pseudo cluster
3. Access Client
4. Writing startup scripts

1. Configuration

zookeeper download address: http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/ 
Deploy three servers on a machine, create a folder zookeeperLab under the specified folder, create three folders server1, server2, server3 in the zookeeperLab folder, then unzip a zookeeper download package inside each folder, and create several folders as follows:
data,dataLog, logs,zookeeper-3.4.6 
1. Enter the data directory and create a file named myid, which writes a number, such as server1, then write a 1, a myid file for server2, and a myid file for server3.(
2. Enter the zookeeper-3.4.6/conf directory, change the copy of the zoo_sample.cfg file to zoo.cfg, and open zoo.cfg as follows:

conf  cat zoo.cfg
# The number of milliseconds of each tick
#Controls heartbeat and timeout, with the smallest session timeout twice as long as tickTime by default.
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
#initLimit: This configuration item is used to configure the maximum number of heartbeat intervals a Zookeeper can tolerate when initializing a connection to a client that is not a user connecting to the Zookeeper server, but a Follower server connected to the Leader in the Zookeeper server cluster.When the Zookeeper server has not received a return message from the client after more than 10 heartbeats (tickTime), the client connection fails.The total length of time is 5*2000=10 seconds
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
#syncLimit: This configuration item identifies the length of time for sending messages, requests, and responses between Leader and Follower. The maximum number of tickTime s is 2*2000=4 seconds
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/Users/duwei/software/zookeeperLab/server1/data
dataLogDir=/Users/duwei/software/zookeeperLab/server1/dataLog
# the port at which the clients will connect
#Client Connection Port
clientPort=2181
# 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.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
  •  

Be careful:

  1. ClientPort This port If you deploy multiple servers on a single machine, then each machine needs a different clientPort, such as server1 is 2181, server2 is 2182, server3 is 2183, and dataDir and dataLogDir need to be distinguished.
  2. The last few lines need to be aware that the server.X number corresponds to the number in the data/myid.You write 1, 2, 3 in the myid files of three servers, so zoo.cfg in each server configures server.1, server.2, and server3 is OK.Because on the same machine, the two ports that follow and the three servers are not the same. Otherwise, the ports conflict. The first port is for information exchange among cluster members, and the second port is for election leaders when the leader hangs up.
  3. server.A=B:C:D: where A is a number indicating the number of servers; B is the ip address of the server; C is the port on which the server exchanges information with the Leader server in the cluster; D is the port on which the Leader server in the cluster hangs and needs to be re-selectedSelect a new Leader, which is the port used by the servers to communicate with each other during the election.If it is a pseudo-cluster, since B is the same, different Zookeeper instances cannot have the same port number for communication, so assign them different port numbers.

2. Start all servers of zookeeper pseudo-cluster

Start the service by going into the zookeeper-3.4.6/bin directory of each of the three servers

sh zkServer.sh start
  •  

View server status when startup is complete

sh zkServer.sh status
  •  

3. Access Client

Enter the zookeeper/bin directory of any server, start a client, and access the service.

./zkCli.sh –server localhost:2181 
  •  

4. Writing startup scripts

vi zkCluster.sh

#!/bin/sh
zkpath=/Users/duwei/software/zookeeperLab
returnValue=0
cd $zkpath
pid=`ps -ef |grep -v "grep"|grep "zookeeperLab/server" |awk '{print $2}'`
start(){
    sh ./server1/zookeeper-3.4.6/bin/zkServer.sh start
    sh ./server2/zookeeper-3.4.6/bin/zkServer.sh start
    sh ./server3/zookeeper-3.4.6/bin/zkServer.sh start
}
stop(){
    kill -9 ${pid}
}
case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    stop
    start
    ;;
hup)
    hup
    ;;
*)
    printf 'Usage: %s {start|stop|restart}\n'
    exit 1
    ;;
esac
exit "$returnValue"

Posted by Hitch54 on Thu, 11 Jul 2019 14:23:51 -0700