Zookeeper Installation and configuration

Source: Internet
Author: User
Tags time limit zookeeper port number
installation
The installation and configuration of Zookeeper is very simple. It can be configured in stand-alone mode or in cluster mode. The following sections will introduce them separately.

Stand-alone mode
Click here to download the zookeeper installation package, unzip it to a suitable directory. Enter the conf subdirectory under the zookeeper directory, and create zoo.cfg:

Bash code Favorite code
tickTime = 2000
dataDir = / Users / apple / zookeeper / data
dataLogDir = / Users / apple / zookeeper / logs
clientPort = 4180
Parameter Description:

tickTime: The basic time unit used in zookeeper, millisecond value.
dataDir: data directory. It can be any directory.
dataLogDir: log directory, can also be any directory. If this parameter is not set, the same settings as dataDir will be used.
clientPort: The port number to listen for client connections.
At this point, zookeeper's stand-alone mode has been configured. To run the server, just run the script:

Bash code Favorite code
bin / zkServer.sh start
 After the server is started, you can start the client to connect to the server and execute the script:
Bash code Favorite code
bin / zkCli.sh -server localhost: 4180
 
Pseudo-cluster mode
The so-called pseudo cluster refers to starting multiple zookeeper processes on a single machine and forming a cluster. Take 3 zookeeper processes as an example.

Make 2 copies of the zookeeper directory:

Bash code Favorite code
| --zookeeper0
| --zookeeper1
| --zookeeper2
 Change zookeeper0 / conf / zoo.cfg file to:

Bash code Favorite code
tickTime = 2000
initLimit = 5
syncLimit = 2
dataDir = / Users / apple / zookeeper0 / data
dataLogDir = / Users / apple / zookeeper0 / logs
clientPort = 4180
server.0 = 127.0.0.1: 8880: 7770
server.1 = 127.0.0.1: 8881: 7771
server.2 = 127.0.0.1: 8882: 7772
Added several parameters with the following meanings:

initLimit: The zookeeper cluster contains multiple servers, one of which is the leader, and the remaining servers in the cluster are followers. The initLimit parameter configures the maximum heartbeat time between the follower and the leader when initializing the connection. At this time, this parameter is set to 5 , Indicating that the time limit is 5 times tickTime, that is, 5 * 2000 = 10000ms = 10s.
syncLimit: This parameter configures the maximum length of time for sending messages, requests and responses between the leader and follower. At this time, this parameter is set to 2, indicating that the time limit is 2 times the tickTime, which is 4000ms.
server.X = A: B: C where X is a number, which indicates the server number. A is the IP address of the server. B configures the port used by the server and the leader in the cluster to exchange messages. C configuration The port used when electing the leader. Since the pseudo-cluster mode is configured, the B and C parameters of each server must be different.
Refer to zookeeper0 / conf / zoo.cfg, configure zookeeper1 / conf / zoo.cfg, and zookeeper2 / conf / zoo.cfg files. Just change the dataDir, dataLogDir, clientPort parameters.

Create a new myid file in the previously set dataDir and write a number, which indicates the server number. This number must correspond to the X in server.X in the zoo.cfg file.
Write 0 to / Users / apple / zookeeper0 / data / myid, write 1 to / Users / apple / zookeeper1 / data / myid, and write 2 to / Users / apple / zookeeper2 / data / myid.

Go to / Users / apple / zookeeper0 / bin, / Users / apple / zookeeper1 / bin, / Users / apple / zookeeper2 / bin respectively, and start the server.
Choose any server directory and start the client:

Bash code Favorite code
bin / zkCli.sh -server localhost: 4180
 
Cluster mode
The configuration of the cluster mode is basically the same as that of the pseudo cluster.
Since the servers are deployed on different machines in the cluster mode, the conf / zoo.cfg file of each server can be exactly the same.
Here is an example:

Bash code Favorite code
tickTime = 2000
initLimit = 5
syncLimit = 2
dataDir = / home / zookeeper / data
dataLogDir = / home / zookeeper / logs
clientPort = 4180
server.43 = 10.1.39.43: 2888: 3888
server.47 = 10.1.39.47: 2888: 3888
server.48 = 10.1.39.48: 2888: 3888
In the example, three zookeeper servers are deployed, which are deployed on 10.1.39.43, 10.1.39.47, and 10.1.39.48. It should be noted that the dataDir directory of each server (as in the above example, it is / home / zookeeper / data) The numbers in the myid file (create the file yourself) must be different, and they need to be consistent with the numbers after server. in zoo.cfg, as in the above example, the myid of 10.1.39.43 server is 43, and the myid of 10.1.39.47 server is 47, 10.1.39.48 server has a myid of 48.

Configuration introduction
The default zookeeper configuration file is zookeeper / conf / zoo_sample.cfg, which needs to be modified to zoo.cfg. The meaning of each configuration item is explained as follows:



1.tickTime: CS communication heartbeat

Heartbeat interval between Zookeeper servers or between client and server, that is, one heartbeat is sent every tickTime. tickTime is in milliseconds.
tickTime = 2000

2.initLimit: LF initial communication time limit
The maximum number of heartbeats (number of tickTimes) that the follower server (F) and the leader server (L) in the cluster can tolerate during the initial connection.
initLimit = 5

3.syncLimit: LF synchronous communication time limit
The maximum number of heartbeats (the number of tickTimes) that can be tolerated between requests and responses between the follower server and the leader server in the cluster.
syncLimit = 2
 
4.dataDir: data file directory
The directory where Zookeeper saves data. By default, Zookeeper saves log files that write data in this directory.
dataDir = / home / michael / opt / zookeeper / data

5.dataLogDir: log file directory
Directory where Zookeeper saves log files.
dataLogDir = / home / michael / opt / zookeeper / log

6.clientPort: client connection port
The port on which the client connects to the Zookeeper server. Zookeeper will listen to this port and accept client access requests.
clientPort = 2333

7. Server name and address: cluster information (server number, server address, LF communication port, election port)
This configuration item is written in a special format with the following rules:
server.N = YYY: A: B

Where N is the server number, YYY is the IP address of the server, A is the LF communication port, and it is the port where the server exchanges information with the leader in the cluster. The default port is 2888. B is the election port, which indicates the port that the servers communicate with each other when the new leader is elected (when the leader dies, the other servers will communicate with each other and choose a new leader). The default port is 3888. Generally speaking, the A port of each server in the cluster is the same, and the B port of each server is the same. However, when a pseudo-cluster is used, the IP addresses are all the same, but only when the A port and the B port are different.
Here is an example of a real cluster:
server.0 = 233.34.9.144: 2008: 6008
server.1 = 233.34.9.145: 2008: 6008
server.2 = 233.34.9.146: 2008: 6008
server.3 = 233.34.9.147: 2008: 6008

Here is an example of a pseudo-cluster:
server.0 = 127.0.0.1: 2008: 6008
server.1 = 127.0.0.1: 2007: 6007
server.2 = 127.0.0.1: 2006: 6006
server.3 = 127.0.0.1: 2005: 6005

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.