Zookeeper Cluster construction under CentOS

Source: Internet
Author: User

Stand-alone mode:

1) First download zookeeper compression package, here to use zookeeper3.4.8 ....

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz

  

2) unzip

First create the folder, put it in the/user/zookeeper/folder

mkdir Zookeeper1

  

mkdir Zookeeper2

  

mkdir Zookeeper3

Create three folders to hold three instances, unzip to the target folder, locate the compressed package storage path, execute the following command

  

TAR-ZXVF zookeeper-3.4.8.tar.gz-c/usr/zookeeper/zookeeper1

  

TAR-ZXVF zookeeper-3.4.8.tar.gz-c/usr/zookeeper/zookeeper2

  

TAR-ZXVF zookeeper-3.4.8.tar.gz-c/usr/zookeeper/zookeeper3

3) operating unit price environment

First to complete the zookeeper1 of this example, first

  

Use the LL command to display all file details,

Drwxr-xr-x. 2 4096 Mar 17:27 bin-rw-rw-r--. 1 83235 Feb 6 11:46 build.xml-rw-rw-r--. 1 88625 Feb 6 11:46 changes.txtdrwxr-xr-x. 2 4096 Mar 17:21 confdrwxr-xr-x. 4096 6 11:46 contribdrwxr-xr-x. 2 4096 Feb 6 11:50 dist-mavendrwxr-xr-x. 6 4096 Feb 6 11:49 docs-rw-rw-r--. 1 1953 Feb 6 11:46 ivysettings.xml-rw-rw-r--. 1 3498 Feb 6 11:46 ivy.xmldrwxr-xr-x. 4 4096 Feb 6 11:49 lib-rw-rw-r--. 1 11938 Feb 6 11:46 license.txt-rw-rw-r--. 1 171 Feb 6 11:46 notice.txt-rw-rw-r--. 1 1770 Feb 6 11:46 readme_packaging.txt-rw-rw-r--. 1 1585 Feb 6 11:46 readme.txtdrwxr-xr-x. 5 4096 Feb 6 11:46 recipesdrwxr-xr-x. 8 4096 Feb 6 11:49 src-rw-rw-r--. 1 1360961 Feb 6 11:46 zookeeper-3.4.8.jar-rw-rw-r--. 1 819 Feb 6 11:50 zookeeper-3.4.8.jar.asc-rw-rw-r--. 1 6 11:46 Zookeeper-3.4.8.jar.md5-rw-rw-r--. 1 1000 6 11:46 ZOOKEEPER-3.4.8.JAR.SHA1 

CP under Configuration file,

MV Conf/zoo_sample.cfg Conf/zoo.cfg

Start ZK,

./bin/zdserver.sh Start

4) Using a Java Client connection zookeeper

./bin/zkcli.sh-server 127.0.0.1:2181

Then you can use a variety of commands, similar to the file manipulation commands, and the input help can see all the commands.

5) Close

./bin/zdserver.sh Stop

  

Distributed model (Replicated mode)

Zookeeper clusters are generally referred to as zookeeper Ensemble, or quorum.

Because we only have a machine here, through different port number, to make a pseudo-cluster way, if you have more machines, you can install a ZK on each machine, configuration is similar.

The so-called " pseudo-distributed cluster " is the instance in which multiple zookeeper are launched in a single PC. " fully distributed cluster " is each PC that launches a zookeeper instance.

Zookeeper there is no obvious master/slave relationship, each node is a server, leader Hung, will immediately follower from the election of one out as leader.

Because there is no master-slave relationship, nor do you have to configure SSH login without password, each ZK server is self-initiated, with each other through the TCP port to Exchange data

The Zookeeper2,zookeeper3 configuration file is changed, because Zookeeper1 when we do a stand-alone, has been modified, under the Zookeeper2,zookeeper3 conf folder, execute

MV Zoo_sample.cfg Zoo.cfg

  

Create an Environment Catalog

Switch to Var/zookeeper path, create a new three folder Zookeeper1,zookeeper2,zookeeper3 .... For storing PID

Mkdir/var/zookeeper/zookeeper1mkdir/var/zookeeper/zookeeper2mkdir/var/zookeeper/zookeeper3

Create three new files in Zookeeper1,zookeeper2,zookeeper3, respectively myID

~ echo "1" >/var/zookeeper/zookeeper1/myid~ echo "2" >/var/zookeeper/zookeeper2/myid~ echo "3" >/var/zookeeper /zookeeper3/myid

 Note that myID can only be used for numbers, because I experimented with the following, containing English words ZK started up, throwing exceptions

分别修改配置文件
修改:dataDir,clientPort
增加:集群的实例,server.X,”X”表示每个目录中的myid的值

Vi/usr/zookeeper/zookeeper1/conf/zoo.cfg

    

 

# of milliseconds of each tickticktime= -# The number of ticks that the initial # synchronization phase can takeinitlimit=Ten# The number of ticks that can pass between # Sending a request and getting an acknowledgementsynclimit=5# The DirectorywhereThe snapshot isstored.# DoNot use/tmp forStorage,/tmp here isJust # example Sakes.datadir=/var/zookeeper/zookeeper1# the port at which the clients would connectclientport=2181server.1=127.0.0.1:2888:3888server.2=127.0.0.1:2889:3889server.3=127.0.0.1:2890:3890# The maximum number of client connections.# increase This ifYou need to handle more Clients#maxclientcnxns= -# # is sure to read the maintenance sections of the # Administrator guide before turning on autopurge.## http://zookeeper.apache.org/doc/current/zookeeperadmin.html#sc_maintenance# # of snapshots to retaininchDatadir#autopurge.snapretaincount=3# Purge Task intervalinchhours# Set to"0"To disable Auto purge feature#autopurge.purgeinterval=1

The following only the different parts, the other and zk1 the same

Vi/usr/zookeeper/zookeeper2/conf/zoo.cfg

 

Datadir=/var/zookeeper/zookeeper2

 

clientport=2182
Vi/usr/zookeeper/zookeeper3/conf/zoo.cfg

  

Datadir=/var/zookeeper/zookeeper3

 

clientport=2182


Start each machine
/usr/zookeeper/zookeeper1/bin/zkserver.sh start/usr/zookeeper/zookeeper2/bin/zkserver.sh start/usr/zookeeper/ zookeeper3/bin/zkserver.sh start

  

View startup status

CentOS Zookeeper Cluster setup

Related Article

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.