Construction of Zookeeper Environment

Source: Internet
Author: User

Recently due to the need to use zookeeper in the project, a careful study, will continue to update zookeeper related articles, leaving a trace.

This article and subsequent zookeeper-related articles are based on the Linux environment, and the code is in C language.

Zookeeper is a sub-project under Hadoop, mainly used to solve the problems in some distributed applications, such as synchronization service, configuration management, cluster management, distributed scheduling and so on, the detailed introduction of zookeeper is a lot on the Internet.

The zookeeper runtime must be loaded with Java-related libraries, and there are a plethora of ways to configure the JDK network under Linux.

First prepare a zookeeper development package, can be downloaded to the official website, here to provide a version, zookeeper-3.4.6.tar.gz.

Generally in the project we will use more than one machine to build zookeeper cluster, due to the constraints, we can build a pseudo-cluster on a machine, as long as a different port to specify the line.

Unzip the package, will get zookeeper-3.4.6 directory, enter the zookeeper-3.4.6 under the Conf directory, we have to make configuration file modification, here we configure three pseudo-cluster server, so new three files zoo1.cfg, zoo2.cfg, Zoo3.cfg, write the following configuration separately:

ticktime=2000initlimit=10synclimit=5datadir=/home/cdadmin/thc/zookeeper/zookeeper-3.4.6/data/d_1clientport= 2181datalogdir=/home/cdadmin/thc/zookeeper/zookeeper-3.4.6/log/log_1server.1=localhost:2887:3887server.2= localhost:2888:3888server.3=localhost:2889:3889

ticktime=2000initlimit=10synclimit=5datadir=/home/cdadmin/thc/zookeeper/zookeeper-3.4.6/data/d_2clientport= 2182datalogdir=/home/cdadmin/thc/zookeeper/zookeeper-3.4.6/log/log_2server.1=localhost:2887:3887server.2= localhost:2888:3888server.3=localhost:2889:3889

ticktime=2000initlimit=10synclimit=5datadir=/home/cdadmin/thc/zookeeper/zookeeper-3.4.6/data/d_3clientport= 2183datalogdir=/home/cdadmin/thc/zookeeper/zookeeper-3.4.6/log/log_3server.1=localhost:2887:3887server.2= localhost:2888:3888server.3=localhost:2889:3889
Note: The corresponding directories for DataDir and DATALOGDIR should be established accordingly.

Configuration parameter Description

Ticktime:zookeeper the heartbeat interval between the client and the server

Initlimit: This configuration item is used to configure the Zookeeper accept client (the client here is not the client that connects the Zookeeper server, but the Leader that is connected to Follower in the Zookeeper server cluster) Server) The maximum number of heartbeat intervals that can be tolerated when a connection is initialized. The client connection failed when the Zookeeper server has not received the return information of the client after 10 heartbeats (that is, ticktime) length. The total length of time is 5*2000=10 seconds.

Synclimit: This configuration item identifies the length of time that a message, request and response is sent between Leader and Follower, the maximum number of ticktime, and the total length of time is 2*2000=4 seconds

DataDir: As the name implies is Zookeeper to save the data directory, by default, Zookeeper will write the data log file is also stored in this directory.

ClientPort: This port is the port that the client connects to the Zookeeper server, Zookeeper listens to the port and accepts the client's access request.

Datalogdir: As the name implies Zookeeper the directory where the log files are saved

Server. A=b:c:d: Where A is a number, indicating this is the first server, B is the IP address of this server, C is the server and the Leader server in the cluster to exchange information on the port; D means that in case the Leader server in the cluster hangs, a port is needed to re-elect , select a new Leader, which is the port that the server communicates with each other when the election is performed. If it is a pseudo-cluster configuration, because B is the same, so different Zookeeper instance communication port numbers can not be the same, so they should be assigned a different port number.

After modifying the parameter file, create a file under each DataDir, the file name is myID, the content of the file is 1, 2, 3, respectively (corresponding to the SERVER.1,SERVER.2,SERVER.3), so you can start the zookeeper server.

Switch to Zookeeper-3.4.6/bin directory to run the command separately: zkserver.sh start zoo1.cfg, zkserver.sh start Zoo2.cfg, zkserver.sh start Zoo3.cfg, enter the command JPS, the result is the same, the start is successful.


After the successful start, we can use the client to connect, run the command: Zkcli.sh-server 127.0.0.1:2182, the client connection on the future we can do some node operation of the server, as shown in:


So the zookeeper was built successfully.

Come here today, goodnight, and be continued!

Construction of Zookeeper Environment

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.