Single Installation Zookeeper cluster

Source: Internet
Author: User
Tags zookeeper
single installation zookeeper cluster Zookeeper Introduction

The main roles of the zookeeper cluster are Leader,learner (Follower,observer (when the server is increased to a certain extent and the throughput is lowered due to the increased voting pressure, the Observer is increased.) ) and client:
* Leader: Leader, responsible for voting initiation and resolution, as well as updating system status, note that write operations must be approved by Leader.
* Follower: Accepts the client's request and returns the result to the client and participates in the voting.
* Observer: Accept the request from the client, transfer the written request to leader, and do not vote. The purpose of observer is to extend the system to improve the speed of reading.
* Client: Clients, want to zookeeper to initiate the request. Configuration Item Description Ticktime: This time is as a zookeeper between the server or between the client and the server to maintain the heartbeat interval, that is, each ticktime time will send a heartbeat. DataDir: As the name implies is zookeeper save the data directory, by default, zookeeper will write the data log file also saved in this directory.

ClientPort: This port is the port where the client connects to the zookeeper server, and zookeeper listens to the port to accept the client's access request.
When these configuration items are configured, you can start zookeeper now, check if zookeeper is already in service after startup, and you can check if there is a ClientPort port number you have configured in the monitor service through the Netstat–ano command.

Initlimit: This configuration entry is used to configure the Zookeeper accept client (where the client is not the client that connects to the zookeeper server, but the Leader that is connected to the Follower in the Zookeeper server cluster) Server) The maximum number of heartbeat intervals that can be tolerated when a connection is initialized. This client connection fails when the Zookeeper server has not received the return information of the client after the 10 heartbeat time (i.e. ticktime) length has expired. The total length of time is 5*2000=10 seconds Synclimit: This configuration item identifies Leader and Follower send messages between the length of request and response time, the longest can not exceed the length of the ticktime, the total length of time is 2*2000=4 seconds ser Ver. A=b:c:d: Where A is a number that indicates what the server is, B is the IP address of the server, and C is the port where the server exchanges information with the Leader server in the cluster; D means that if the Leader server in the cluster hangs, a port needs to be returned for the election. To elect a new Leader, which is the port that the server communicates with each other at the time of the election. If it is a pseudo cluster configuration, because B is the same, so the different zookeeper instance communication port number can not be the same, so to assign them different port number. Install zookeeper

Download and unzip the zookeeper installation package, and I have the latest version installed here 3.4.11

Copy the Zookeeper installation directory into 3 folders and rename it:

zookeeper-3.4.11-2181  
zookeeper-3.4.11-2182  
zookeeper-3.4.11-2183

Each of these directories represents a node of the zookeeper cluster. Configure zookeeper each node Configure 1th Node

CD zookeeper-3.4.11-2181/conf
vim zoo.cfg

After that, write the following configuration to Zoo.cfg:

ticktime=2000
initlimit=10
synclimit=5
datadir=/home/hadoop/zookeeper-3.4.11-2181/data  # Note that this is best for full path
clientport=2181
server.1=127.0.0.1:2222:2223
server.2=127.0.0.1:3333:3334
server.3= 127.0.0.1:4444:4445
Create a Data directory
cd/home/hadoop/zookeeper-3.4.11-2181
mkdir Data
Create a myID file in the data directory
Cd/home/hadoop/zookeeper-3.4.11-2181/data
echo "1" >myid
Configure 2nd Node
CD zookeeper-3.4.11-2182/conf
vim zoo.cfg

After that, write the following configuration to Zoo.cfg:

ticktime=2000
initlimit=10
synclimit=5
datadir=/home/hadoop/zookeeper-3.4.11-2182/data  # Note that this is best for full path
clientport=2182
server.1=127.0.0.1:2222:2223
server.2=127.0.0.1:3333:3334
server.3= 127.0.0.1:4444:4445
Create a Data directory
cd/home/hadoop/zookeeper-3.4.11-2182
mkdir Data
Create a myID file in the data directory
Cd/home/hadoop/zookeeper-3.4.11-2182/data
echo "2" >myid
Configure 3rd Node
CD zookeeper-3.4.11-2183/conf
vim zoo.cfg

After that, write the following configuration to Zoo.cfg:

ticktime=2000
initlimit=10
synclimit=5
datadir=/home/hadoop/zookeeper-3.4.11-2183/data  # Note that it's best to have a full path
clientport=2183
server.1=127.0.0.1:2222:2223
server.2=127.0.0.1:3333:3334
server.3=127.0.0.1:4444:4445
Create a Data directory
cd/home/hadoop/zookeeper-3.4.11-2183
mkdir Data
Create a myID file in the data directory
Cd/home/hadoop/zookeeper-3.4.11-2183/data
echo "3" >myid
Start Zookeeper cluster
CD zookeeper-3.4.11-2181/bin/
./zkserver.sh start
cd zookeeper-3.4.11-2182/bin/  
./zkserver.sh start
CD zookeeper-3.4.11-2183/bin/
./zkserver.sh start

Note: The error message may be printed here because the node is connected to another node when it is started, and the other nodes are not started. View cluster status

CD zookeeper-3.4.11-2181/bin/
./zkserver.sh status
output: Follower
CD zookeeper-3.4.11-2182/bin/  
. /zkserver.sh status
output: Follower
cd zookeeper-3.4.11-2183/bin/
./zkserver.sh status
output: Leader

With this output, the leader has been selected.

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.