Apache ZooKeeper Getting Started Guide Translator

Source: Internet
Author: User
Tags log4j


ZooKeeper Start Wizard
  • Start: Coordinate distributed programs with zookeeper
    • Singleton operation
    • Manage Zookeeper store
    • connect zo Okeeper
    • Execute zookeeper
    • Execute zookeeper
    • other optimizations
Getting Started: Coordinating distributed programs through zookeeper This document includes help for you to start using zookeeper at a high speed.

The article is mainly for the 0 basic developers who want to try to use zookeeper, including some simple examples. With only one zookeeperserver, some commands confirm that the server is executing, a simple sample of the program.

At the end of the article, for convenience, there are some things that take into account some relatively complex examples. GCA, deploy in replication mode to optimize transactions.

But false assumptions are applied to commercial projects. Please refer to ZooKeeper Administrator ' s Guide.


Single-instance operationstarting the Zookeeperserver in a singleton mode is simple. The zookeeper service includes a jar file and some configuration. Start zookeeper You first need a copy of the configuration file in the Downloaded Files folder conf/zoo.cfg:ticktime=2000 datadir=/var/lib/zookeeper clientport=2181you can name the file arbitrarily, but we call it conf/zoo.cfgto describe the narrative. If the DataDir folder already exists, change the value of DataDir. Here is an introduction to the meaning of each field Ticktime the time unit used by the zookeeper is milliseconds.

This time is like the heartbeat time of Zookeeper, which is twice times the time-out range of the minimum session unit.

DataDirThis folder is where the snapshot of the data in memory is stored, unless you specifically specify that the log of the update data is in this position. ClientPortThe client connection listens to port. You need to create a configuration file. Start ZooKeeper:bin/zkserver.sh start ZooKeeper's log record is through log4j-many other about the log explanation please see LOG4J official website. The startup zookeeper described here is in singleton mode.

If the process fails, the zookeeper service will be hung out. Singleton mode startup is best for the development environment. False assumption has replicated mode start see running replicated ZooKeeper.

Managing ZooKeeper Storagefor long-running zookeeper services in a production environment, storage must be managed with additional management (DataDir and logs), see Maintenance for these Connecting to ZooKeeperAssuming that zookeeper has been executed, you are able to connect through the following options:
  • < Strong>java : Use
    bin/zkcli.sh-server 127.0.0.1:2181    
    this Lets perform simple, file-like operations.
  • C: Compile cli_mt (multi-threaded) or Cli_st (single-threaded) by running make cli_mt or /c4> makeCli_st in the src/c subdirectory in the ZooKeeper sources. See the README contained within SRC/C for full details.

    You can run the program from src/c using:

    Ld_library_path=. CLI_MT 127.0.0.1:2181

    Or

    Ld_library_path=. Cli_st 127.0.0.1:2181

    This would give you a simple shell to the Execute file system like operations on ZooKeeper.

Once You has connected, you should see something like:

Connecting to Localhost:2181log4j:warn No Appenders could is found for logger (org.apache.zookeeper.ZooKeeper). log4j: WARN Initialize the log4j system properly. Welcome to zookeeper! JLine support is enabled[zkshell:0]        

assume that you are executing in the shell. You can. Type after connectinghelp, which returns a list of commands that the client can executeFor example, the following:
[zkshell:0] helpzookeeper host:port cmd args        get path [watch]        ls path [watch]        set path data [version]        del Quota [-n|-b] path        quit        printwatches on|off        Create path data ACL        stat path [watch]        Listquota path< C11/>history        setacl path ACL        getacl path        sync path        redo Cmdno        addauth scheme auth        Delete path [version]        deleteall path        setquota-n|-b val Path        

You can try some simple commands to understand this simple command line. First, start by issuing the List command, as inls, yielding:[zkshell:8] ls/[zookeeper]Next. Create a how to get through executioncreate/zk_test My_dataThis will create a new anode and string data "My_data" associated with this anode, and you can see the following execution results:
[Zkshell:9] Create/zk_test my_datacreated/zk_test      

by executing LS/command will see the current folder status:
[zkshell:11] LS/[zookeeper, zk_test]        

attention. This Zk_test folder has been created.

You can confirm the data associated with this node by executing the get command. For example, the following:

[Zkshell:12] Get/zk_testmy_dataczxid = 5ctime = Fri June 13:57:06 PDT 2009mZxid = 5mtime = Fri June 13:57:06 PDT 200 9pZxid = 5cversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0dataLength = 7numChildren = 0        

we can also change and zk_test the associated data throughSetcommands, such as the following:
[Zkshell:14] set/zk_test junkczxid = 5ctime = Fri June 13:57:06 PDT 2009mZxid = 6mtime = Fri June 14:01:52 PDT 2009p Zxid = 5cversion = 0dataVersion = 1aclVersion = 0ephemeralOwner = 0dataLength = 4numChildren = 0[zkshell:15] Get/zk_test Junkczxid = 5ctime = Fri June 13:57:06 PDT 2009mZxid = 6mtime = Fri June 14:01:52 PDT 2009pZxid = 5cversion = 0dataVer sion = 1aclVersion = 0ephemeralOwner = 0dataLength = 4numChildren = 0      

(Note that we set the zk_test data and then executed theGetcommand, the data did change).

finally throughDeleteDelete the zk_test node:
[zkshell:16] delete/zk_test[zkshell:17] LS/[zookeeper][zkshell:18]

get a lot of other content. Please see Programmer's Guide. Programming to ZooKeeper

ZooKeeper has a Java bindings and C bindings. They is functionally equivalent. The C bindings exist in the Variants:single threaded and multi-threaded. These differ only on how the messaging loop was done. For more information, see the programming Examples in the ZooKeeper Programmer ' s Guide for sample code using of the differ ENT APIs.

Copy mode execution zookeeperThe implementation of zookeeper in a singleton mode is very convenient for evaluating test development. But in a formal environment you should do it in copy mode. Each zookeeperserver has a copy of the same configuration file.

This file and the configuration file described above for the singleton pattern are similar to those used. Just a little bit different, such as the following:

Ticktime=2000datadir=/var/lib/zookeeperclientport=2181initlimit=5synclimit=2server.1=zoo1:2888:3888server.2= zoo2:2888:3888server.3=zoo3:2888:3888

This new property, Initlimit , is used to define the timeout period for zookeeper connection to leader, and the properties Synclimitlimit a leader stale time. For both of these timeouts, you can also specify ticktime time unit measurement. Like what. Initlimit is 5 ticks, each tick is 2000 milliseconds, or 10 seconds. Propertiesserver. Xlists the composition of the Zookeeper service.

When the server starts up, it knows which server it is by looking in the myID file in the Data folder. This file contains an ASCII-encoded server number.

Finally, note the two port numbers after each server name:"2888" and "3888". You can connect to each other via these ports. For example, a connection to each other is necessary when the data is updated sequentially.

Especially when the Zookeeperserver is connected to leader in turn. When a new leader is born, the younger brothers will connect to leader with the TCP protocol via the port number. Because the default leader is also used with the TCP protocol. We must request another port for the election of leader. is the second port number of the property server.


NoteIf you want to perform multiple zookeeper services on a single machine, test it. Need to point out the unique cluster name localhost and those leader election port(such as 2,888:3,888, 2,889:3,889, 2,890:3,890). It is also necessary to isolate the individual DataDir folders and the different port numbers.

(In this copy mode execution example, each execution in a single machine has a configuration file)


Other Optimizationsadditional configuration parameters can improve performance: there is a couple of other configurations parameters that can greatly increase performance:to reduce wait and high-speed updates, it is important to have a thing in the log folder. The default thing log file is put together with the data snapshot and the myID file. PropertiesDatalogdir could have named somewhere else .
 Last published:08/07/2014 04:18:26copyright? 2008-2013 the Apache software Foundation.

Apache ZooKeeper Getting Started Guide Translator

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.