zookeeper-3.4.6 installation and ease of use

Source: Internet
Author: User
Tags time interval zookeeper zookeeper client
One, Zookeeper introduction

Zookeeper mainly for distributed programs to provide coordination services, to solve the problem of consistency. such as the selection of the main node in the high availability in the distributed, CS architecture, there are multiple servers, client-to-server selection and other applications.
Zookeeper's main role is leader and follower, a time, only one leader, the rest of the nodes are follower,leader by the Paxos algorithm to vote.
Zookeeper mainly uses the algorithm is the Paxos algorithm, is also the zookeeper core. You can see for yourself. The main role proponents and recipients, each node is fair, can have both roles. The following are the main stages of Paxos:
The recipient actually only needs to reply to the proposal_id biggest proposal that it has accepted, because other proposals simply cannot be selected by the selection policy. So the final agreement, as it is, is Paxos:
Phase one pre-proposal phase:
Proposed by Proposer:
Acceptor broadcast pre-proposal to the recipient, with the next proposal proposal PROPOSAL_ID
Accepted by acceptor:
After receiving the pre-proposal Update a_proposal_id = MAX (proposal_id,a_proposal_id), if the pre-proposed proposal_id>a_proposal_id, Acceptor replied to records of the most accepted proposal_id proposals.

Phase two proposal phase:
Proposed by Proposer:
Wait until most of the recipients have received a reply to the pre-proposal, selecting the proposal_id largest proposal from the legal number of proposals, composed of all replies, with the value of the proposal as the value of this proposal.
If K is an empty set, then the proposal can be arbitrarily assigned. The proposal was then broadcast to the recipients, who shared the same proposal_id with the proposal and the advance proposal.
Accepted by acceptor:
If the proposal received by proposal_id>= a.proposal_id, then accept this proposal, update a_proposal_id = max (proposal_id,a_proposal_id), update the record proposal. Two, installation of zookeeper

1. Installation Preparation
① three Linux virtual machines, I'm using CENTOS7.
② need to install JDK
③zookeeper's installation package (can be downloaded here)
2. Start the installation (three machines are needed for the content)
① Decompression

TAR-ZXVF zookeeper-3.4.6.tar.gz-c/usr/local/hpeu/

② Configuration

Cd/usr/local/hpeu/zookeeper-3.4.6/conf
There are only zoo_sample.cfg files in it, you need to rename this file to Zoo.cfg, and modify some of these configurations
CP Zoo_sample.cfg Zoo.cfg

Modify the configuration as follows:

ticktime=2000
initlimit=10
synclimit=5
datadir=/usr/local/hpeu/zookeeper-3.4.6/zookeeper
Datalogdir=/usr/local/hpeu/zookeeper-3.4.6/zookeeper/logs
clientport=2181
server.1=hadoop1:2888:3888
server.2=hadoop2:2888:3888
server.3=hadoop3:2888:3888

The main parameters are explained as follows:
ticktime-> Heartbeat time interval
Initlimit-> the maximum number of heartbeat intervals that can be tolerated when initializing a connection
Synclimit-> This configuration item identifies the length of time that a message is sent between leader and follower, the duration of the request and the response, and the maximum number of ticktime, the total length of time is 5*2000=10 seconds
Datadir->zookeeper Data Catalog
Datalogdir->zookeeper Log Directory
Clientport-> Port for Client link zookeeper
Server.1=hadoop4:2888:3888->servers is a fixed field, and 1 represents the ID of the HADOOP4 (note this ID) HADOOP4 represents the hostname of a node (this can be IP), 2888 represents the port of communication between leader and follower (this is the default, which can be changed), and 3888 indicates that there is no leader when the leader Port is elected by voting.

③ Configuring the Zookeeper directory as an environment variable

Vim/etc/profile
//Join these two
export zookeeper_home=/usr/local/hpeu/zookeeper-3.4.6
export path= $PATH: $ Zookeeper_home/bin

Source/etc/profile

Another important configuration is to create the myID file:
The myID file is created in the Zookeeper Data directory and corresponds to the ID of the ZOO.CFG configuration, that is, the value in myID in HADOOP1 is 1, the value in Hadoop2 in myID is 2, and the value in Hadoop3 in myID is 3. Start up and easy to use

zkserver.sh Start/status/stop Open/View status/Stop execution command for the zookeeper server of the node
After opening to see the status of three nodes, one for leader, the other two are follower

To start the zookeeper client with the zkcli.sh command
After you start the client, you can use the Help command to view the corresponding instructions.

LS/--  View the node under the root directory, by default there is a zookeeper node
get/zookeeper, view zookeeper node information
Create [-S] [-e] path data ACL-& gt; Create path node data must be, ACLs can be added without (this indicates some permissions), [-s] means that this is a sequential node, that is, the nodes name is unique in this directory, will automatically add some ID number to you after your name, without adding the ID number will not be added to you. [-e] means that the node is zero, that is, the client launches, zookeeper will be automatically deleted, if not added, the node is a persistent node. Delete
path [version], remove node
RMR path, recursive delete node,
connect Host:port, zookeeper server on a host



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.