Zookeeper installation and configuration instructions (3)

The installation and configuration of Zookeeper is very simple. It can be configured in stand-alone mode or in cluster mode. As shown below:

write picture description here

The following will be introduced separately:

Standalone mode

After downloading the installation package of the latest stable version of zookeeper ( see the first blog post ), unzip it to a suitable directory. Enter the conf subdirectory under the zookeeper directory, modify the zoo_sample.cfg sample file and rename it zoo.cfg. Do not modify any configuration, just run the startup command in the bin directory (zkServer.cmd in windows environment, zkServer.sh in linux environment).

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper
clientPort=2181
  • 1
  • 2
  • 3
  • 4
  • 5

Taking window as an example, the successful startup interface: 
write picture description here

We can see that after the startup is successful, all environmental information will be printed. As shown in FIG.

Parameter Description:

  • tickTime: in milliseconds, used to control the heartbeat and timeout, the default timeout time is twice the tickTime
  • dataDir: The data directory is used to store snapshot files. Can be any directory.
  • dataLogDir: log directory, which can also be any directory. If this parameter is not set, the same settings as dataDir will be used.
  • clientPort: The listening port number for the client to connect to zookeeper.

Other configuration items:

  • initLimit sets the time allowed for all followers to connect and synchronize with the leader. If more than half of the followers fail to complete synchronization within the set time period, the leader will announce to give up the leadership position and conduct another leadership election. If the number of zk cluster environments is really large, the time to synchronize data will become longer, so in this case, this parameter can be appropriately adjusted. Default is 10
  • syncLimit sets the time allowed for a follower to synchronize with a leader. If the follower does not complete synchronization within the set time period, it will be discarded by the cluster. All clients connected to this follower will connect to another follower.
  • maxClientCnxns limits the number of clients connected to zookeeper, and limits the number of concurrent connections, it distinguishes different clients by ip, the default value is 60.
  • minSessionTimeout and maxSessionTimeout are the minimum session timeout time and the maximum session timeout time. By default, the minimum timeout time is 2 times the tickTime time, and the maximum session timeout time is 20 times the session timeout time. When the system starts, it will display the corresponding information. Defaults to -1. (Higher version, this configuration has been removed)

Starting from 3.4.0, zookeeper provides the ability to automatically clean up snapshots and transaction logs.

  • autopurge.snapRetainCount, autopurge.purgeInterval 
    client will generate a lot of logs in the process of interacting with zookeeper, and zookeeper will also save the data in memory as snapshots, these data will not be automatically deleted, so the disk is like this data will increase. However, these two parameters can be set to let zookeeper delete data automatically. autopurge.purgeInterval is to set how many hours to clean up. And autopurge.snapRetainCount is to set how many snapshots are retained, and the previous ones are deleted. 
    However, if your cluster is a very busy cluster, and then encounter this delete operation, it may affect the performance of the zookeeper cluster, so this process is generally carried out when the access is low, but unfortunately zookeeper is not set in Which time to run the settings, so sometimes we will disable this automatic deletion function, and configure a cron on the server, and then do it in the early morning.

So far, the stand-alone mode of zookeeper has been configured.

cluster mode

Cluster mode is divided into pseudo-cluster mode and cluster mode. Their configurations are basically the same, but the difference between a single machine and multiple machines. 
Since each server is deployed on different machines in cluster mode, the conf/zoo.cfg file of each server can be exactly the same.

An important configuration in cluster mode is myid.

configure-myid

A myid file will be placed in the dataDir with a number in it to uniquely identify the service. This id is very important and must be unique in the entire cluster . Zookeeper will fetch the configuration on server.x according to this id. For example, the current id is 1, which corresponds to the configuration of server.1 in zoo.cfg. And when we introduce leader election later, the size of this id is also meaningful.

If you think you still won't install it, you can read other recommended installation articles:

Zookeeper installation and configuration

ZooKeeper distributed cluster installation

Summarize

The installation of Zookeeper is very simple. You can just follow the tutorial. In the next blog, we will use the command line to operate zookeeper.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325748355&siteId=291194637