The cluster model of zookeeper combat

Source: Internet
Author: User
Tags mkdir zookeeper

Original link: Zookeeper of the actual combat cluster model

The previous article introduces the installation and application of Zookeeper's stand-alone cluster mode, and today it is said that how to install the configuration in the true multi-machine cluster mode.
Here, unzip the zookeeper installation package to the/OPT directory, and on the three machines directory path is the same, the assumption is/opt/zookeeper.

1. First edit the conf/zoo.cfg files in each zookeeper directory, at which point the contents of these three zookeeper profiles are the same, as follows

$ cat/opt/zookeeper/conf/zoo.cfg
ticktime=2000
datadir=/opt/zookeeper/data
clientport=2181
initlimit=10
synclimit=5
server.1=fanbinx1:2888:3888
server.2=fanbinx2:2888:3888
server.3= fanbinx3:2888:3888

There are a few points to be aware of
* DataDir: The datadir of the three zookeeper instances are the same and are assigned to the data directory in the Zookeeper instance directory.
* ClientPort: Three zookeeper instance ports are the same.
* Server.: Three zookeeper instances have the same server list.

2. Create the data directory and instance ID files
Run the following command on each of the three machines to produce a different instance ID file

First machine

Mkdir/opt/zookeeper/data
echo 1 >/opt/zookeeper/data/myid
Second Machine
Mkdir/opt/zookeeper/data
echo 2 >/opt/zookeeper/data/myid
Third machine
Mkdir/opt/zookeeper/data
echo 3 >/opt/zookeeper/data/myid

Note that you need to create a myID file in each zookeeper DataDir directory, which records the instance IDs of each zookeeper.

3. Start Zookeeper Service
Enter each zookeeper's Bin directory, and then run "./zkserver.sh start" to start a zookeeper service.

4. Client Connection
Casually into a zookeeper bin directory, and then run

./zkcli.sh-server 

To connect the zookeeper service separately.

Create a Znode node on one of the client

Create/mykey myvalue

Then view the newly created Zonde node on the other client

Get/mykey

5. View Zookeeper Status
After starting zookeeper, because zookeeper will have a set of leader election algorithm, so if you want to know that zookeeper is leader can run in each zookeeper Bin directory./zkserver.sh Status command to view the.

If it's leader,

$./zkserver.sh status
JMX enabled by default
Using config:/opt/zookeeper/bin/. /conf/zoo.cfg
Mode:leader
If it's not leader,
$./zkserver.sh status
JMX enabled by default
Using config:/opt/zookeeper/bin/. /conf/zoo.cfg
Mode:follower
At this point, you can stop that phase of leader, and then look at the other two zookeeper instances, at which point the remaining two zookeeper instances will elect a leader.











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.