Installation and configuration of zookeeper cluster _zookeeper

Source: Internet
Author: User
Tags time interval zookeeper

The purpose of zookeeper is to encapsulate complex and error-prone key services and to provide users with Easy-to-use interfaces and high-performance, functionally stable systems. Zookeeper has two operating modes, stand-alone mode (Standalone) and cluster mode (distributed), but the zookeeper advantage is that it can build distributed zookeeper clusters (one leader, multiple follower), Therefore, the cluster can ensure high availability, high stability and high reliability. Here is a description of the configuration of the zookeeper two modes: Before configuring zookeeper, download the Zookeeper installation package: Http://zookeeper.apache.org/releases.html#download, I'm using the zookeeper-3.3.6 version.
Zookeeper stand-alone mode (standalone)

After downloading the installation package, use WINSCP to put it in the Linux environment and unzip the installation package:

Tar zxvf zookeeper-3.3.6.tar.gz

After decompression, start configuring zookeeper to enter the directory of the configuration file:

CD  zookeeper-3.3.6/conf/

Modify the zoo_sample.cfg below the directory to zoo.cfg, and then configure the contents as:

# The number of milliseconds of tick ticktime=2000 # The number of
ticks that initial 
# Synchronizati On phase can take
initlimit=10 # The number of
ticks so can pass between 
# Sending a request and getting a Acknowledgement
synclimit=5
# The directory where the snapshot is stored.
Datadir=/tmp/zookeeper
# The port at which the clients'll connect
clientport=2181

The meaning of each of the above configuration parameters:

Ticktime: This time is as zookeeper between the server or between the client and the server to maintain the heartbeat time 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.

Datalogdir:log directory, which can also be any directory. If this parameter is not set, the same setting is used and datadir, which I do not set.

When configured, start the Zookeeper server process:

CD  zookeeper-3.3.6/
bin/zkserver.sh start

After the successful start, use jps-m command query, zookeeper process for Quorumpeermain

To connect to the server with the client process, execute the following command:

bin/zkcli.sh  -server logsrv03:2181

The logsrv above is my hostname, and the following 2181 is the port number of the connection.

After the connection is successful, the following connection information appears:

[root@logsrv03 zookeeper-3.3.6]# bin/zkcli.sh-server logsrv03:2181 connecting to logsrv03:2181 2015-08-18 10:23:48,966 -INFO [main:environment@97]-Client environment:zookeeper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT 2015-08- 10:23:48,969-info [main:environment@97]-Client environment:host.name=logsrv03 2015-08-18 10:23:48,970-info [mai N:ENVIRONMENT@97]-Client environment:java.version=1.7.0_71 2015-08-18 10:23:48,970-info [main:Environment@97]-Clie NT Environment:java.vendor=oracle Corporation 2015-08-18 10:23:48,971-info [main:environment@97]-Client Environment: Java.home=/usr/local/jdk1.7.0_71/jre 2015-08-18 10:23:48,971-info [main:environment@97]-Client Environment: java.class.path=/usr/local/jiang/zookeeper-3.3.6/bin/.. /build/classes:/usr/local/jiang/zookeeper-3.3.6/bin/.. /build/lib/*.jar:/usr/local/jiang/zookeeper-3.3.6/bin/.. /zookeeper-3.3.6.jar:/usr/local/jiang/zookeeper-3.3.6/bin/.. /lib/log4j-1.2.15.jar:/usr/local/jiang/zookeeper-3.3.6/bin/.. /lib/jline-0.9.94.jar:/usr/local/jiang/zookeeper-3.3.6/bin/.. /src/java/lib/*.jar:/usr/local/jiang/zookeeper-3.3.6/bin/.. /conf:.:/ Usr/local/jdk1.7.0_71/lib:/usr/local/jdk1.7.0_71/lib/dt.jar:/usr/local/jdk1.7.0_71/lib/tools.jar 2015-08-18 10:23:48,972-info [main:environment@97]-Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/ Lib64:/lib64:/lib:/usr/lib 2015-08-18 10:23:48,972-info [main:environment@97]-Client environment:java.io.tmpdir=/ TMP 2015-08-18 10:23:48,973-info [main:environment@97]-Client environment:java.compiler=<na> 2015-08-18 10:23: 48,973-info [main:environment@97]-Client environment:os.name=linux 2015-08-18 10:23:48,974-info [main:Environment@ ]-Client Environment:os.arch=amd64 2015-08-18 10:23:48,974-info [main:environment@97]-Client Environment:os.versi
on=2.6.32-431.el6.x86_64 2015-08-18 10:23:48,975-info [main:environment@97]-Client environment:user.name=root 2015-08-18 10:23:48,975-info [Main:environMENT@97]-Client environment:user.home=/root 2015-08-18 10:23:48,976-info [main:environment@97]-Client Environment:u ser.dir=/usr/local/jiang/zookeeper-3.3.6 2015-08-18 10:23:48,977-info [main:zookeeper@379]-Initiating Client Connection, connectstring=logsrv03:2181 sessiontimeout=30000 watcher=org.apache.zookeeper.zookeepermain$
Mywatcher@1698ab04 Welcome to zookeeper! 2015-08-18 10:23:48,995-info [Main-sendthread (): clientcnxn$sendthread@1058]-Opening socket connection to server LOGSR v03/172.17.6.148:2181 2015-08-18 10:23:49,002-info [Main-sendthread (logsrv03:2181): ClientCnxn$SendThread@947]- Socket connection established to logsrv03/172.17.6.148:2181, initiating sessions jline support is enabled 2015-08-18 10:23: 49,020-info [Main-sendthread (logsrv03:2181): clientcnxn$sendthread@736]-session establishment complete on server logs rv03/172.17.6.148:2181, SessionID = 0x24f3b0a17ea0002, negotiated timeout = 30000 Watcher:: Watchedevent State:syncconne CTED Type:none PATh:null [zk:logsrv03:2181 (CONNECTED) 0]  

To this end, the Zookeeper standalone mode is configured.


Zookeeper cluster mode (distributed)

The zookeeper service itself consists of a cluster (2n+1 services allow n failures). The Zookeeper service has two roles, one is leader, writes the service and the data synchronization, the remaining is follower, provides reads the service, leader after the expiration will elect the new follower in the leader. Throughout the zookeeper cluster model, the entire cluster is a whole, in which any one zookeeper node in the cluster shares the entire cluster of services. Details can refer to http://zookeeper.apache.org/doc/trunk/zookeeperInternals.html

The following is a description of the configuration process for the cluster pattern: Step One: Configure the host name and IP mappings

In the process of running the zookeeper cluster, each zookeeper node needs to communicate with each other, and it communicates through the host name, each node of the cluster needs to recognize each other, so it is necessary to configure the other node host name to IP mapping when configuring a zookeeper node.

For example, configure my zookeeper cluster, a total of three machines in the cluster: Logsrv02, logsrv03, logsrv04, logsrv03 as an example, into the/etc/hosts, the contents are as follows:

172.17.6.142 logsrv02
172.17.6.148 logsrv03
172.17.6.149 logsrv04
Step Two: Configure the Zookeeper configuration file

# The number of milliseconds of tick ticktime=2000 # The number of
ticks that initial 
# Synchronizati On phase can take
initlimit=10 # The number of
ticks so can pass between 
# Sending a request and getting a Acknowledgement
synclimit=5
# The directory where the snapshot is stored.
Datadir=/tmp/zookeeper
# The port at which the clients'll connect
clientport=2181
server.1=logsrv02 : 2888:3888
server.2=logsrv03:2888:3888
server.3=logsrv04:2888:3888
The above configuration file and stand-alone mode is actually more than the cluster server.id and host name, port number mapping information, the details of the configuration file can refer to the official description:
Http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html#sc_RunningReplicatedZooKeeper Step three: Add installation files to Logsrv02 and logsrv04

We have configured the Zookeeper installation files in the logsrv03, in a cluster, each zookeeper node only need to use the same installation files on the line, so you need to copy the configured files to the other two machines, here are two methods:

The first is to copy the files directly using WINSCP, and then copy them to the other two machines, which requires installing WINSCP (used to securely copy files between local and remote computers, supporting the SCP protocol)

Download Address: http://winscp.net/eng/download.php

Second: The way remote commands are copied directly to Logsrv02 and LOGSRV04, as shown in the following:

cd/usr/local/
scp-r zookeeper-3.3.6/root@logsrv02:/usr/local/
scp-r zookeeper-3.3.4/root@logsrv04:/usr/ local/
Fourth step: Set up myID

Under the directory specified by our DataDir, create a myID file with a number that identifies the current host, the number of x in the server.x configured in CONF/ZOO.CFG, set ID to this number, as shown below:

[Root@logsrv02 zookeeper]# echo "1" >/tmp/zookeeper/myid
[root@logsrv03 zookeeper]# echo "2" >/tmp/zookeeper /myid
[root@logsrv04 zookeeper]# echo "3" >/tmp/zookeeper/myid
Fifth step: After configuration, start the cluster

Once configured, enter the/USR/LOCAL/ZOOKEEPER-3.3.6/directory, and then execute the following command to start the zookeeper:

[Root@logsrv02 zookeeper-3.3.6]# bin/zkserver start [
root@logsrv03 zookeeper-3.3.6]# bin/zkserver start
[ ROOT@LOGSRV04 zookeeper-3.3.6]# bin/zkserver Start
Sixth Step: Installation Verification

After the installation is complete, you can view the startup status of the zookeeper by Zookeeper's script, as well as the role of each zookeeper node in the cluster (leader and follower), and the following are the results of my zookeeper cluster nodes:

[Root@logsrv02 zookeeper-3.3.6]# bin/zkserver.sh status
JMX enabled by default
Using config:/usr/local/jiang/ zookeeper-3.3.6/bin/.. /conf/zoo.cfg
mode:follower

[root@logsrv03 zookeeper-3.3.6]# bin/zkserver.sh status
JMX enabled by Default
Using config:/usr/local/jiang/zookeeper-3.3.6/bin/. /conf/zoo.cfg
mode:follower

[root@logsrv04 zookeeper-3.3.6]# bin/zkserver.sh status
JMX enabled by Default
Using config:/usr/local/zookeeper-3.3.6/bin/. /conf/zoo.cfg
Mode:leader

Through the above information can be learned that LOGSRV04 is leader, the remaining two are follower.

After the cluster is configured, you can use one of the Zookeeper node connection point cluster, and through a node can share the entire cluster of services, such as: When you configure the zookeeper cluster, then install the middleware Kafka, after the zookeeper boot Kafka, Then the creation of topic,topic by scripting needs to specify zookeeper nodes, when many nodes correspond to topic, this time in the Zookeeper cluster, query a topic list of nodes, You can query the topic list of all nodes in the entire cluster.


Reference links

The following is when I study zookeeper, the collection of zookeeper related links, can refer to learning:

Http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html#sc_RunningReplicatedZooKeeper

http://zookeeper.apache.org/doc/trunk/

Http://zookeeper.apache.org/doc/trunk/zookeeperInternals.html

http://zookeeper.apache.org/

http://blog.csdn.net/shirdrn/article/details/7183503

http://jm-blog.aliapp.com/?p=1384

http://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/

http://cailin.iteye.com/blog/2014486

http://blog.jpush.cn/push_zookeeper_study_usage/

http://coolxing.iteye.com/blog/1871009

http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt192

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.