In the previous blog we explained the "zookeeper" stand-alone configuration, this blog will continue to introduce the Zookeeper cluster deployment and configuration. Environment
The environment of the cluster configuration is the same as that of the stand-alone configuration, the only difference is that the cluster is configured between multiple servers, and of course there is a pseudo cluster configuration, that is, to configure multiple services on the same machine, and to differentiate them by their different port numbers. configuration file
Add the configuration of the server item to the stand-alone configuration file, following the new configuration file:
ticktime=2000
initlimit=10
synclimit=5
datadir=/tmp/zookeeper
clientport=2181
server.1=ip1 : 2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888
Configuration Item Interpretation
| Name of parameter |
Description |
| ClientPort |
No default value, must be configured, System properties are not supported configuration. The current server provides a service port for the client to connect to the server through this port, typically set to 1281. No unified ports are required in the cluster and ports can be configured arbitrarily. |
| DataDir |
No default value, must be configured. The server stores the snapshot file directory. By default, if Datalogdir is not configured, the transaction log is also stored in this directory. It is recommended that you configure the transaction log directory independently. |
| Ticktime |
Default value: 3000 (ms), which does not support system property configuration. Used to configure the length of the minimum time unit in the zookeeper, many run-time intervals are expressed using multiples of it. |
| Initlimit |
Leader zookeeper receive the maximum time (10*ticktime) of the other server initialization waiting for the cluster. |
| Synclimit |
Leader zookeeper and cluster other server communication maximum time (5*ticktime). |
Server.id=host:port:port Resolution
Each row this configuration represents a single server in a cluster. Where ID is the server ID, which identifies the number of the machine in the cluster. Also, create a myID file on the server's Data directory (/tmp/zookeeper), which has only one line of content, and is a number that corresponds to the server ID number for each of the servers.
For example, the content of server.1=ip1:2888:3888 's myID is 1. The IDs for different servers need to be different and are consistent with the contents of the IDs and myID files in Server.id in the Zoo.cfg file. The value range for the ID is 1~255.
Where the first port of the configuration parameter in Server.id is the port that communicates between the other machines in the cluster and the leader, and the second port is the one that is used when the cluster elects the leader when leader downtime or other failure.
Follow the same steps above to configure other machines in the cluster. The zoo.cfg files for each cluster are the same, and the configuration files for each zookeeper server are guaranteed to be the same with version control or other tools. The only difference between each machine in a cluster is the number in the server.id corresponding myID file. Start Validation
When you are done, start the server in the cluster and verify the server status. This step is the same as stand-alone mode and will not be repeat.
Note that the general zookeeper cluster is composed of 3~5 servers, that is 2n+1 machine. The following chapters explain in detail why this is the case.