CentOS ZooKeeper Install

Source: Internet
Author: User

Environment: CentOS 6.7, Java version "1.7.0_51, ZooKeeper 3.4.6

Environment: CentOS 6.7, JDK 1.7.0_51, ZooKeeper 3.4.6
(optional) Create a new user

Generally I tend to put the need to start the daemon process, the external service provider program, the server class program, installed under a separate user. This allows for isolation, operational dimensions, and increased security.

Create a new group,

Groupadd Zookeeperuseradd-g Zookeeper Zookeeper


1. Stand-alone mode (Standalone mode) stand-alone mode is useful in the development and commissioning phases. 1.1 Downloads, unzip cd/opt; mkdir appcd app wget Http://archive.apache.org/dist/zookeeper/stable/zookeeper-3.4.6.tar.gztar zxf Zookeeper-3.4.6.tar.gz


1.2 Boot default is stand-alone mode, $ mv conf/zoo_sample.cfg conf/zoo.cfg$./bin/zkserver.sh start


1.3 Using the Java Client Connection zookeeper$./bin/zkcli.sh-server 127.0.0.1:2181 then you can use various commands, similar to the file operation commands, and enter Help to see all the commands.


1.4 Close $./bin/zdserver.sh Stop


2. The distributed model (replicated mode) is configured as a distributed mode in a production environment to be powerful. Zookeeper clusters are generally referred to as zookeeper Ensemble, or quorum.


2.1 Prepare 3 Machines Assuming there are three machines, the hostname and IP correspondence are: 192.168.10.80 zk01192.168.10.81 zk02192.168.10.82 Zk03zookeeper There is no obvious master/ Slave relationship, each node is a server, leader Hung, will be immediately elected from the follower out as a leader. Because there is no master-slave relationship, also do not configure SSH password login, each ZK server is self-initiated, with each other through the TCP port to Exchange data.


2.2 Modifying the configuration file conf/zoo.cfgdatadir=/opt/zookeeper/datadatalogdir=/opt/zookeeper/logsclientport=2181ticktime= 2000initlimit=5synclimit=2server.1=zk01:2888:3888server.2=zk02:2888:3888server.3=zk03:2888:3888
 Note: datadir: Data directory Datalogdir: Log directory ClientPort: Client connection Port ticktime:zookeeper     A heartbeat is sent between the server or between the client and the server, that is, each   ticktime  time. The Initlimit:zookeeper leader      accepts the maximum number of heartbeat intervals that the client (Follower) can tolerate when initializing a connection. After the length of time (that is, ticktime) of the  5 heartbeat is exceeded  Zookeeper  the server has not received the return information from the client, the client connection fails.  The total length of time is  5*2000=10  seconds Synclimit: Indicates the length of request and response time when sending messages between  Leader  and  Follower , up to a maximum of  A ticktime  length of time, the total length of time is  2*2000=4  seconds. Server. A=b:c:d: Where a  is a number, indicating this is the first server;b  is the server's  ip  address, c  represents this server and cluster  Leader  The port;d  for server Exchange information indicates that in case the   leader  server in the cluster is hung up, a port is needed to re-elect a new  leader, which is the port that the server communicates with each other when the election is performed. If it is a pseudo-cluster configuration, because the  B  is the same, so different   zookeeper  instance communication port number can not be the same, so they have to assign a different port number. 
2.3 myID file to the DataDir of each machine, create a new myID file containing a number to identify the current host. echo "1" >>/opt/zookeeper/data/myidecho "2" >>/opt/zookeeper/data/myidecho "3" >>/opt/zookeeper/ Data/myid


2.4 Start each machine zookeeper-3.4.6/bin/zkserver.sh startzookeeper-3.4.6/bin/zkserver.sh startzookeeper-3.4.6/bin/ zkserver.sh start


2.5 View state zookeeper-3.4.6/bin/zkserver.sh status


3. Connect the zookeeper cluster using a Java client./bin/zkcli.sh-server zk01:2181./bin/zkcli.sh-server zk01:2181./bin/zkcli.sh-server zk01 : 2181
./zkcli.sh -server 127.0.0.1 2181connecting to  127.0.0.12015-12-03 16:42:31,452 [myid:] - info  [main:[email protected]]  - [zk: 127.0.0.1:2181 (CONNECTED)  0] ls /      show Current data [ Test1, zookeeper] 
1)   Create node      format:create [-s] [-e] path data acl      where "-S" means creating an "ordered" node, "-e" means creating a temporary node. The default is persistent node  ->create -s /test null   ->create /test null       Below is an example of including ACLs:     ->create -s /test null digest:test:kk3nr5x06nh+xdlgmyorulgk/mo=:rwcda        Create a node with path "/test" with a value of "null" and an ACL authorization of "digest" with the authorized user name: password "test:kk3nr5x06nh+xdlgmyorulgk/mo= ", the ACL has a permission list of" R "" W "" C "" D "" a ".    " digest "authorization means the client azimuth this node data, need to specify the user name and password, You can refer to the Digestauthenticationprovider.generatedigest (String ipname) method in Zookeeper and get "digest" by specifying the original user name and password to this method After the string, such as the incoming "Test:test", will be "test:v28q/nyni4ji3rk54h0r8o5kmug=", the internal principle is the "password" part of the md5 +  SHA1 operation. zkcli.sh command you need to pass the string after digest .     where the ACL is authorized in many ways, you can find more information in the Zoodefs class .      the last parameter is a permission list, R for "read", W for "write" and C for "create", d means "delete", a means "admin"  2)   get node Data      format: get path    - > get /test  -e  czxid = 0x5b  ctime = mon  sep 16 14:14:06 cst 2013  mzxid = 0x5b  mtime =  Mon Sep 16 14:14:06 CST 2013  pZxid = 0x67   cversion = 7  dataversion = 0  aclversion = 0   ephemeralowner = 0x0  datalength = 2  numchildren = 5        you can get all the node information from the results list.   3)   View child nodes list      directives:  LS /PATH4)   Set node value      format: set path data [version] ->  set /test 1313131 -1       where the value needs to be a string, the version number can be obtained by the instruction in 2, if the version number is " -1 "indicates that the version checksum is ignored when updating.  5)   DeleteExcept all nodes      formats: rmr path -> rmr /test        will delete "/test" and all child nodes under it.  6)    set acl     format:  setacl path  acl  -> setAcl /test digest:test:Kk3Nr5X06NH+XdlGMyOrULgK/mo=:rwcda        is very similar to the Create Directive.   7)   Delete node      format:  delete  path [version] -> delete /test -1       It's important to note that If there are child nodes under this path, this will cause the deletion to fail. This is the difference from the "RMR" directive.  8)   Add licensing information      format:  addauth schema  auth -> addauth digest test:test      only after authorization, To access the node data that has ACL control. Note that the "auth" information is the original user name and password, not the .   after the Digestauthenticationprovider signature, if the wrong authorization information is used, it may cause " authentication is not valid :  ".


This article is from "Miles away" blog, declined reprint!

CentOS ZooKeeper Install

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.