Install and run zookeeper

Source: Internet
Author: User
Tags zookeeper client
Introduction to zookeeper

Zookeeper is a formal subproject of hadoop. It is a reliable coordination system for large-scale distributed systems. It provides functions such as configuration maintenance, Name Service, distributed synchronization, and group service. The goal of zookeeper is to encapsulate key services that are complex and error-prone, and provide users with easy-to-use interfaces and systems with high performance and stable functions.

Zookeeper is an open-source implementation of Google's chubby. it is a highly effective and reliable collaborative work system. zookeeper can be used for leader election and configuration maintenance. in a distributed environment, we need a master instance or some configuration information to ensure consistency of file writing. zookeeper can guarantee the following three points:

  • Watches are ordered with respect to other events, other watches, and
    Asynchronous replies. The Zookeeper client libraries ensures that
    Everything is dispatched in order.
  • A client will see a watch event for a znode it is watching before seeing the new data that corresponds to that znode.
  • The order of watch events from zookeeper corresponds to the order of the updates as seen by the zookeeper service.

 

In zookeeper, znode is a node similar to the path of a UNIX file system. You can store or retrieve data on this node. if the flag is set to ephemeral when znode is created, the znode will no longer exist in zookeeper after the zookeeper and zookeeper have lost connection. zookeeper uses watcher to detect event information. When the client receives event information, such as connection timeout, node data change, and sub-node change, it can call corresponding actions to process data. the wiki page of zookeeper shows how to use zookeeper to handle Event Notifications, queues, priority queues, locks, shared locks, unrecoverable shared locks, and commit in two stages.

Official zookeeper website

Official zookeeper website

Install zookeeper

First download the latest zookeeper-3.4.5.tar.gz

Decompress the package

Tar zxvf zookeeper-3.4.5.tar.gz

Go to the conf directory and change zoo_sample.cfg to zoo. cfg.

Then VI zoo. cfg

Changed:

 

# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/tmp/zookeeper# the port at which the clients will connectclientPort=2181## Be sure to read the maintenance section of the # administrator guide before turning on autopurge.## http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance## The number of snapshots to retain in dataDir#autopurge.snapRetainCount=3# Purge task interval in hours# Set to "0" to disable auto purge feature#autopurge.purgeInterval=1

After editing and saving, enter the bin directory for execution.

./Zkserver. Sh start

Zookeeper Test
[Root @ localhost bin] #. /zkcli. shconnecting to localhost: 21812013-01-16 14:36:22, 484 [myid:]-info [main: Environment @ 100]-client environment: zookeeper. version = 3.4.5-1392090, built on 09/30/2012 14:36:22 GMT2013-01-16, 488 [myid:]-info [main: Environment @ 100]-client environment: host. name = localhost. localdomain2013-01-16 14:36:22, 489 [myid:]-info [main: Environment @ 100]-client environment: Java. version = 1.6.0 _ 292013-01-16 14:36:22, 489 [myid:]-info [main: Environment @ 100]-client environment: Java. vendor = Sun Microsystems inc.2013-01-16 14:36:22, 490 [myid:]-info [main: Environment @ 100]-client environment: Java. home =/usr/Java/jdk1.6.0 _ 29/jre2013-01-16 14:36:22, 490 [myid:]-info [main: Environment @ 100]-client environment: Java. class. path =/usr/local/zookeeper-3.4.5/bin /.. /build/class ES:/usr/local/zookeeper-3.4.5/bin /.. /build/lib /*. jar:/usr/local/zookeeper-3.4.5/bin /.. /lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper-3.4.5/bin /.. /lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper-3.4.5/bin /.. /lib/netty-3.2.2.Final.jar:/usr/local/zookeeper-3.4.5/bin /.. /lib/log4j-1.2.15.jar:/usr/local/zookeeper-3.4.5/bin /.. /lib/jline-0.9.94.jar:/usr/local/zookeeper-3.4.5/bin /.. /zookeeper-3.4.5.jar:/us R/local/zookeeper-3.4.5/bin /.. /src/Java/lib /*. jar:/usr/local/zookeeper-3.4.5/bin /.. /conf :. /:/usr/Java/jdk1.6.0 _ 29/lib:/usr/Java/jdk1.6.0 _ 29/JRE/lib2013-01-16 14:36:22, 491 [myid:]-info [main: environment @ 100]-client environment: Java. library. path =/usr/Java/jdk1.6.0 _ 29/JRE/lib/i386/client:/usr/Java/jdk1.6.0 _ 29/JRE/lib/i386: /usr/Java/jdk1.6.0 _ 29/JRE /.. /lib/i386:/usr/Java/packages/lib/i386:/lib:/usr /Lib2013-01-16 14:36:22, 491 [myid:]-info [main: Environment @ 100]-client environment: Java. io. tmpdir =/tmp2013-01-16 14:36:22, 491 [myid:]-info [main: Environment @ 100]-client environment: Java. compiler = <Na> 14:36:22, 492 [myid:]-info [main: Environment @ 100]-client environment: OS. name = Linux2013-01-16 14:36:22, 492 [myid:]-info [main: Environment @ 100]-client environment: OS. arch = i000020 13-01-16 14:36:22, 493 [myid:]-info [main: Environment @ 100]-client environment: OS. version = 2.6.18-308.24.1.el52013-01-16 14:36:22, 493 [myid:]-info [main: Environment @ 100]-client environment: user. name = root2013-01-16 14:36:22, 493 [myid:]-info [main: Environment @ 100]-client environment: user. home =/root2013-01-16 14:36:22, 494 [myid:]-info [main: Environment @ 100]-client environment: user. dir =/u Sr/local/zookeeper-3.4.5/bin2013-01-16 14:36:22, 496 [myid:]-info [main: zookeeper @ 438]-initiating client connection, connectstring = localhost: 2181 sessiontimeout = 30000 watcher = org. apache. zookeeper. zookeepermain $ mywatcher @ 5ffb18welcome to zookeeper! 2013-01-16 14:36:22, 592 [myid:]-info [main-sendthread (localhost. localdomain: 2181): clientcnxn $ sendthread @ 966]-opening socket connection to server localhost. localdomain/127.0.0.1: 2181. will not attempt to authenticate using SASL (login configuration cannot be located) 14:36:22, 601 [myid:]-info [main-sendthread (localhost. localdomain: 2181): clientcnxn $ sendthread @ 849]-socket connection established to localhost. localdomain/127.0.0.1: 2181, initiating sessionjline support is enabled2013-01-16 14:36:22, 693 [myid:]-info [main-sendthread (localhost. localdomain: 2181): clientcnxn $ sendthread @ 1207]-session establishment complete on server localhost. localdomain/127.0.0.1: 2181, sessionid = 0x13c3c5224cc0000, negotiated timeout = 30000 watcher: watchedevent state: syncconnected type: None path: NULL [ZK: localhost: 2181 (connected) 0] helpzookeeper-server host: Port cmd ARGs Connect Host: port get path [Watch] ls path [Watch] set path data [version] RMR path delquota [-N |-B] path quit printwatches on | off create [-S] [- e] path data ACL stat path [Watch] Close ls2 path [Watch] History listquota path setacl path ACL getacl path sync path redo records no addauth scheme auth Delete path [version] setquota-N | -B Val path [ZK: localhost: 2181 (connected) 1] Create/my_data "data.ch.com" created/my_data [ZK: localhost: 2181 (connected) 2] GET/my_data "data.ch.com" czxid = 0x2ctime = wed Jan 16 14:38:20 CST 2013 mzxid = 0x2mtime = wed Jan 16 14:38:20 CST 2013 pzxid = 0x2cversion = 0 dataversion = 0 aclversion = 0 bytes = 0x0datalength = 13 numchildren = 0 [ZK: localhost: 2181 (connected) 3] Set/my_date "123456.com" node does not exist:/my_date [ZK: localhost: 2181 (connected) 4] Set/my_data "Export czxid = 0x2ctime = wed Jan 16 14:38:20 CST 2013 mzxid = 0x4mtime = wed Jan 16 14:38:58 CST 2013 pzxid = 0x2cversion = 0 dataversion = 1 aclversion = 0 ephemeralowner = 0x0datalength = 12 numchildren = 0 [ZK: localhost: 2181 (connected) 5] GET/my_data "Export czxid = 0x2ctime = wed Jan 16 14:38:20 CST 2013 mzxid = 0x4mtime = wed Jan 16 14:38:58 CST 2013 pzxid = 0x2cversion = 0 dataversion = 1 aclversion = 0 ephemeralowner = 0x0datalength = 12 numchildren = 0 [ZK: localhost: 2181 (connected) 6] Create/mytemp "" created/mytemp [ZK: localhost: 2181 (connected) 7] GET/mytnode does not exist:/MYT [ZK: localhost: 2181 (connected) 8] GET/mytemp "" czxid = 0x5ctime = wed Jan 16 14:40:44 CST 2013 mzxid = 0x5mtime = wed Jan 16 14:40:44 CST 2013 pzxid = 0x5cversion = 0 dataversion = 0 aclversion = 0 ephemeralowner = 0x0datalength = 11 numchildren = 0 [ZK: localhost: 2181 (connected) 9] GET/mytemp "" czxid = 0x5ctime = wed Jan 16 14:40:44 CST 2013 mzxid = 0x5mtime = wed Jan 16 14:40:44 CST 2013 pzxid = 0x5cversion = 0 dataversion = 0 aclversion = 0 ephemeralowner = 0x0datalength = 11 numchildren = 0 [ZK: localhost: 2181 (connected) 10] GET/my_data "Export czxid = 0x2ctime = wed Jan 16 14:38:20 CST 2013 mzxid = 0x4mtime = wed Jan 16 14:38:58 CST 2013 pzxid = 0x2cversion = 0 dataversion = 1 aclversion = 0 ephemeralowner = 0x0datalength = 12 numchildren = 0 [ZK: localhost: 2181 (connected) 11] lszookeeper-server host: Port cmd ARGs Connect Host: port get path [Watch] ls path [Watch] set path data [version] RMR path delquota [-N |-B] path quit printwatches on | off create [-S] [- e] path data ACL stat path [Watch] Close ls2 path [Watch] History listquota path setacl path ACL getacl path sync path redo records no addauth scheme auth Delete path [version] setquota-N | -B Val path [ZK: localhost: 2181 (connected) 12]

 

 

 

 

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.