Mac Installs zookeeper Pseudo Cluster

Posted by wcl99 on Mon, 24 Jun 2019 01:15:20 +0200

Original address: http://blog.csdn.net/u013673245/article/details/49331607

Catalogue
I. Configuration
2. Start all servers of zookeeper pseudocluster
3. Access Client
IV. Writing startup scripts

I. Configuration

zookeeper Download Address: http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/ 
Deploy three servers on a machine, set up a folder zookeeperLab under the specified folder, set up three folders server1, server2, server3 in the zookeeperLab folder, then decompress a zookeeper download package in each folder, and also set up several folders, the overall structure is 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 corresponding to server2, and a myid file corresponding to server3.  
2. Enter the zookeeper-3.4.6/conf directory, change the copy of zoo_sample.cfg file to zoo.cfg, open zoo.cfg, as follows:

conf  cat zoo.cfg
# The number of milliseconds of each tick
#Controlling heartbeat and timeout, the smallest session timeout by default is twice as long as tickTime.
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 that Zookeeper acceptance clients can tolerate when initializing connections (the client is not the client where the user connects to the Zookeeper server, but the Follower server connected to the Leader in the Zookeeper server cluster). When the Zookeeper server has not received the return information from the client after more than 10 heartbeat times (tickTime), it indicates that the client connection failed. 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 message, request and response time between Leader and Follower. The maximum number of tickTime s can not exceed the total length of 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

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 2181, server2 2182, server3 2183, dataDir and dataLogDir also need to be distinguished.
  2. The last few lines need to be noted that the number server.X corresponds to the number in 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 server 3 is OK. Because on the same machine, the two ports and three servers connected behind are not the same. Otherwise, the ports conflict. The first port is used to exchange information among cluster members, and the second port is used to elect the leader when the leader hangs down.
  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 for exchanging information between the server and the Leader server in the cluster; D is 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 This is the port that servers communicate with each other when elections are executed. If it is a pseudo cluster configuration, because B is the same, different Zookeeper instances can not have the same communication port number, so they need to be assigned different port numbers.

2. Start all servers of zookeeper pseudocluster

Enter the zookeeper-3.4.6/bin directory of three servers and start the service

sh zkServer.sh start
  • 1
  • 1

When the startup is complete, view the server status

sh zkServer.sh status
  • 1
  • 1

3. Access Client

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

./zkCli.sh –server localhost:2181 
  • 1
  • 1

IV. 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"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

Topics: Zookeeper Apache Session snapshot