Install ZooKeeper in CentOS 6.7

Source: Internet
Author: User

Install ZooKeeper in CentOS 6.7
Environment: CentOS 6.7, jdk 1.7.0 _ 51, ZooKeeper 3.4.6 (optional) create a new user

Generally, I tend to install the daemon process, the program that provides external services, that is, the server-class Program, under individual users. In this way, isolation can be achieved, and security is also improved in O & M.

Create a new group,

groupaddzookeeper useradd -gzookeeperzookeeper

1. Standalonemode) Standalone mode is useful in the development and debugging stages. 1.1 download and decompress cd /opt ; mkdir app cd app wgethttp: //archive .apache.org /dist/zookeeper/stable/zookeeper-3 .4.6. tar .gz tar zxfzookeeper-3.4.6. tar .gz

1.2 start The default mode is the standalone mode, $ mv conf /zoo_sample .cfgconf /zoo .cfg $. /bin/zkServer .shstart

1.3 Use a java client to connect to ZooKeeper $. /bin/zkCli .sh-server127.0.0.1:2181 Then you can use various commands, which are similar to file operation commands. Enter help to view all commands.

1.4 close $. /bin/zdServer .shstop

2. Distributed Mode) In the production environment, you must configure the distributed mode to make full use of the power. A ZooKeeper cluster is generally called ZooKeeperensemble or quorum.

2.1 prepare 3 machines Suppose there are three machines, hostname The relationship with the ip address is: 192.168.10.80zk01 192.168.10.81zk02 192.168.10.82zk03 ZooKeeper does not have an obvious master /slave Link. Each node is a server. If the leader crashes, it will immediately start from follower. Select one as the leader. Because there is no master-slave relationship, you do not need to configure SSH password-less login. Each zk server is started by itself. And exchange data through the TCP port.

2.2 modify the configuration file conf /zoo .cfg dataDir= /opt/zookeeper/data dataLogDir= /opt/zookeeper/logs clientPort=2181 tickTime=2000 initLimit=5 syncLimit=2 server.1=zk01:2888:3888 server.2=zk02:2888:3888 server.3=zk03:2888:3888 Note: DataDir: Data Directory DataLogDir: log directory ClientPort: Client Connection Port TickTime: The interval between the Zookeeper server or between the client and the server to maintain the heartbeat, that is, each The tickTime will send a heartbeat.    InitLimit: Leader of Zookeeper The maximum number of Heartbeat intervals that can be tolerated during client (Follower) initialization. When more than five heartbeats exist After the length of time (that is, tickTime), the Zookeeper server has not received the response from the client. Client connection failed. The total length is 5*2000 = 10 seconds. SyncLimit: length of the request and response time between the Leader and the Follower when sending messages. The maximum length cannot exceed The length of each tickTime. The total length is 2*2000 = 4 seconds. Server. A = B: C: D: where A is A number, indicating the number of the server; B is the IP address of the server; C Indicates the port on which the server exchanges information with the Leader server in the cluster. D indicates that When the Leader server crashes, a port is required to re-elect and select a new Leader, which is used Port on which the Server communicates during the election. If it is a pseudo cluster configuration method, because B is the same, so different The communication port numbers of Zookeeper instances cannot be the same, so you need to assign them different port numbers. 2.3myid File Create a new myid file under dataDir of each machine and store a number to identify the current host. echo "1" >> /opt/zookeeper/data/myid echo "2" >> /opt/zookeeper/data/myid echo "3" >> /opt/zookeeper/data/myid

2.4 start each machine zookeeper-3.4.6 /bin/zkServer .shstart zookeeper-3.4.6 /bin/zkServer .shstart zookeeper-3.4.6 /bin/zkServer .shstart

2.5 view status zookeeper-3.4.6 /bin/zkServer .shstatus

3. Use the java client to connect to the ZooKeeper Cluster . /bin/zkCli .sh-serverzk01:2181 . /bin/zkCli .sh-serverzk01:2181 . /bin/zkCli .sh-serverzk01:2181 . /zkCli .sh-server127.0.0.12181 Connectingto127.0.0.1 2015-12-0316:42:31,452[myid:]-INFO[main:Environment@100]- [zk:127.0.0.1:2181(CONNECTED)0] ls /Display current data [test1,zookeeper] 1) create a node Format: create [-s] [-e] pathdataacl Where "-s" Creates "Ordered" Node, "-e" Creates a temporary node. The default value is persistent node. ->create-s /test null ->create /test null The following is an example of ACL: ->create-s /test nulldigest: test :Kk3Nr5X06NH+XdlGMyOrULgK /mo =:rwcda Create a path "/test" The value is "null" The ACL authorization method is "digest" The authorized user name: the password is "test:Kk3Nr5X06NH+XdlGMyOrULgK/mo=" The ACL permission list is "r" "w" "c" "d" "a" . "digest" The authorization method indicates the location of the client. You must specify the user name and password. For details, see zookeeper. DigestAuthenticationProvider.generateDigest(String IpName) method. You can obtain it by specifying the original user name and password to this method. "digest" For example "test:test" , You will get To "test:V28q/NynI4JI3Rk54h0r8O5kMug=" The internal principle is "Password" Partial MD5 + Sha1 operation. Then you need to pass the string after digest on the zkCli. sh command. There are many methods for ACL authorization. You can find more information in the ZooDefs class. The last parameter is the permission list. "read" , W indicates "write" , C indicates "create" , D indicates "delete" , A indicates "admin" 2) Get node data Format: getpath ->get /test -e cZxid=0x5b ctime=MonSep1614:14:06CST2013 mZxid=0x5b mtime=MonSep1614:14:06CST2013 pZxid=0x67 cversion=7 dataVersion=0 aclVersion=0 ephemeralOwner=0x0 dataLength=2 numChildren=5 You can obtain all node information from the result list. 3) view the subnode list Command: ls /path 4) set the node Value Format: set pathdata[version] -> set /test 1313131-1 The value must be a string, and the version number can be obtained through the command in 2). if the version number is "-1" Indicates that version Verification is ignored during update. 5) delete all nodes Format: rmrpath ->rmr /test Will be deleted "/test" And all its subnodes. 6) set ACL Format: setAclpathacl ->setAcl /test digest: test :Kk3Nr5X06NH+XdlGMyOrULgK /mo =:rwcda It is very similar to the create Command. 7) delete a node Format: deletepath [version] ->delete /test -1 Note that if there are sub-nodes under this path, the deletion will fail. "rmr" Command differences. 8) add authorization information Format: addauthschemaauth ->addauthdigest test : test Only after authorization can you access the node data with ACL control. Note: "auth" The information is the original user name and password, instead of passing through After the signature of DigestAuthenticationProvider. If incorrect authorization information is used, it may cause "Authenticationis notvalid:".

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.