Pseudo-distributed cluster is to deploy multiple ZK applications on one machine. Before deployment, the server needs JDK environment Java-version to display relevant Java information before zooKeeper can be built. This article is built based on macOs, the original address

download

Download and unzip

The tar - ZXVF zookeeper - 3.4.6. Tar. GzCopy the code

Rename folders

The mv zookeeper - 3.4.6 zookeeperCopy the code

configuration

step1

CFG zoo-sample. CFG zoo1. CFG cp zoo-sample. CFG zoo2. CFG and cp zoo-sample. CFG zoo3. CFG in the conf directory of the ZK

step2

Edit the zoo1, 2, and 3 files as follows

# the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/Users/book/zk/server1/data # the port at which the clients will connect 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=localhost:2187:2887 server.2=localhost:2188:2888 server.3=localhost:2189:2889Copy the code

dataDir=/Users/book/zk/server1/data

clientPort=2181

server.1=localhost:2187:2887 server.2=localhost:2188:2888 server.3=localhost:2189:2889

Zoo2. CFG (clientPort = 2182; DataDir = / Users/book/zk/server2 / data)

Zoo3. CFG (clientPort = 2182; DataDir = / Users/book/zk/server3 / data)

Configuration instructions

  • TickTime: Indicates the heartbeat interval between Zookeeper servers or between clients and servers. That is, each tickTime sends a heartbeat.

  • InitLimit: This configuration item is used to configure the Zookeeper accept client (not the client through which the user connects to the Zookeeper server, It is the maximum heartbeat interval that the Follower server connected to the Leader in the Zookeeper cluster can endure during initial connection. If the Zookeeper server does not receive any message from the client after the tickTime period exceeds 10 heartbeats, the connection to the client fails. The total length of time is 10*2000=20 seconds

  • SyncLimit: This configuration item identifies the request and reply duration between the Leader and Follower. The maximum duration is tickTime. The total duration is 5 x 2000=10 seconds

  • DataDir: Indicates the directory in which Zookeeper saves data. By default, Zookeeper saves log files that write data in this directory.

  • ClientPort: This port is used by the client to connect to the Zookeeper server. Zookeeper listens to this port and receives access requests from the client.

  • Server. A=B: C: D: where A is A number indicating the number of the server. B is the IP address of the server; C represents the port through which the server exchanges information with the Leader server in the cluster. D indicates that 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. In the pseudo-cluster configuration mode, different Zookeeper instances cannot communicate with the same port number because B is the same. Therefore, they need to be assigned different port numbers.

$ mkdir /Users/book/zk/server1/data
$ mkdir /Users/book/zk/server2/data
$ mkdir /Users/book/zk/server3/data

$ echo 1 > /Users/book/zk/server1/data/myid
$ echo 2 > /Users/book/zk/server2/data/myid
$ echo 3 > /Users/book/zk/server3/data/myid
Copy the code

Start the

$ ./zkServer.sh start zoo1.cfg
$ ./zkServer.sh start zoo2.cfg
$ ./zkServer.sh start zoo3.cfg
Copy the code

Check whether the test is successful.

$ ./zkCli.sh -server localhost:2181
Copy the code