I have been using zookeeper for a while, so I will briefly summarize the configuration. The first is the stand-alone mode:
2 Enter the conf subdirectory under the zookeeper directory, create zoo.cfg
3 Edit zoo.cfg
tickTime=2000
dataDir=D:\\zookeeper\\zookeeper-3.4.9-1\\data\\
dataLogDir =D:\\zookeeper\\zookeeper-3.4.9-1\\datalog\\
clientPort=4180
Parameter Description
tickTime: basic event unit, in milliseconds, used to control heartbeat and timeout, the default timeout time is twice the tickTime
dataDir: data directory. Can be any directory.
dataLogDir: log directory, also can be any Directory. If this parameter is not set, the same settings as dataDir will be used.
clientPort: The port number that listens for client connections
The server configuration is complete, start the server:
bin/zkServer.cmd
Client connection:
bin/zkCli.cmd -server localhost:4180
2Single-machine simulation cluster mode
Copy three installation packages
-
|--zookeeper1
-
|--zookeeper2
-
|--zookeeper3
Change the zookeeper0/conf/zoo.cfg file
initLimit=5
syncLimit=2
dataDir=D:\\zookeeper\\zookeeper-3.4.9-1\\data\\
dataLogDir=D:\\zookeeper\\zookeeper-3.4.9-1\\datalog\\
clientPort=4180
server.1=127.0.0.1:8880:7770
server.2=127.0.0.1:8881:7771
server.3=127.0.0.1:8882:7772
initLimit=5
syncLimit=2
dataDir=D:\\zookeeper\\zookeeper-3.4.9-2\\data
dataLogDir=D:\\zookeeper\\zookeeper-3.4.9-2\\datalog
clientPort=4181
server.1=127.0.0.1:8880:7770
server.2=127.0.0.1:8881:7771
server.3=127.0.0.1:8882:7772
initLimit=5
syncLimit=2
dataDir=D:\\zookeeper\\zookeeper-3.4.9-3\\data
dataLogDir=D:\\zookeeper\\zookeeper-3.4.9-3\\datalog
clientPort=4182
server.1=127.0.0.1:8880:7770
server.2=127.0.0.1:8881:7771
server.3=127.0.0.1:8882:7772
Add parameters
syncLimit: This parameter configures the maximum length of time for sending messages, requests and responses between the leader and the follower. At this time, the parameter is set to 2, indicating the time limit It is 2 times tickTime, that is, 4000ms.
server.X=A:B:C where X is a number, indicating the number of the server. A is the IP address where the server is located. B configures the server to exchange with the leader in the cluster The port used by the message. C configures the port used when electing the leader. Since the configuration is pseudo-cluster mode, the B and C parameters of each server must be different
Need to change dataDir, dataLogDir, clientPort parameters
Create a new myid text file in the dataDir directory, and write 1, 2, and 3 respectively. The numbers here correspond to the server numbers in the zookeeper configuration file, which cannot be wrong.
After the configuration is complete, start three servers respectively
cluster mode
The configuration of cluster mode is basically the same as that of pseudo-cluster.
Since each server is deployed on different machines in cluster mode, the conf/zoo.cfg file of each server can be exactly the same.