First understand zookeeper (1) zookeeper installation and configuration, first understand zookeeper

Source: Internet
Author: User

First understand zookeeper (1) zookeeper installation and configuration, first understand zookeeper

1. Brief Introduction

Zookeeper is a distributed application Coordination Service and an important component of Hadoop and Hbase. It is a tree-like directory service that supports change push. It can also be used as the Registration Center for dubbo services.

2. Installation

2.1 Download and install

wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gztar -zxvf zookeeper-3.4.6.tar.gzcd zookeeper-3.4.6cp conf/zoo_sample.cfg conf/zoo.cfg

2.2 Configuration

2.2.1 Single Point

(1) Modify zoo. cfg. If there are no special requirements, all of them can be modified by default. The main changes are dataDir and clientPort, as shown below:

TickTime = 2000 initLimit = 10 syncLimit = 5 dataDir =/app/soft/zookeeper-3.4.6/data (change to real output directory) clientPort = 2181

(2) start: bin/zkServer. sh start

(3) Check whether: bin/zkServer. sh status

(4) view the log: vi zooKeeper. out

 

2.2.2 Cluster mode (Single IP multi-node)

(110000beibei3zookeeper-3.4.6.tar.gz, such as zookeeper_node1, zookeeper_node2, and zookeeper_node3. The structure is as follows:

      
(2) Enter zookeeper_node1 ---> conf and modify zoo. cfg as follows:

TickTime = 2000 initLimit = 10 syncLimit = 5 dataDir =/app/soft/zookeeper_node1/data (changed to the real output directory) clientPort = 2181server. 1 = 127.0.0.1: 2888: 3888server. 2 = 127.0.0.1: 2889: 3889
Server.3 = MAID: 2890: 3890

(3) create a myid file in the directory corresponding to dataDir, as shown below:

mkdir datavi myid

Myid indicates your id, corresponding to the above zoo. cfg "server. "After the number, the content of the first server is 1, the content of the second server is 2, and the content of the third server is 3. The content is as follows:

1

(4) Similarly, adjust the address and port of Node 2 and node 3 as follows:

Node 2:

TickTime = 2000 initLimit = 10 syncLimit = 5 dataDir =/app/soft/zookeeper_node2/data (change to real output directory) clientPort = 2182server. 1 = 127.0.0.1: 2888: 3888server. 2 = 127.0.0.1: 2889: 3889server. 3 = 127.0.0.1: 2890: 3890

Node 3:

TickTime = 2000 initLimit = 10 syncLimit = 5 dataDir =/app/soft/zookeeper_node3/data (change to real output directory) clientPort = 2183server. 1 = 127.0.0.1: 2888: 3888server. 2 = 127.0.0.1: 2889: 3889server. 3 = 127.0.0.1: 2890: 389

(5) modify the myid of Node 2 and node 3;

(6) Start the Service as follows:

[root@localhost soft]# zookeeper_node1/bin/zkServer.sh startJMX enabled by defaultUsing config: /app/soft/zookeeper_node1/bin/../conf/zoo.cfgStarting zookeeper ... STARTED[root@localhost soft]# vi zookeeper.out 2015-06-25 05:43:13,252 [myid:] - INFO  [main:QuorumPeerConfig@103] - Reading configuration from: /app/soft/zookeeper_nod2015-06-25 05:43:13,257 [myid:] - INFO  [main:QuorumPeerConfig@340] - Defaulting to majority quorums2015-06-25 05:43:13,260 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 32015-06-25 05:43:13,260 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 02015-06-25 05:43:13,262 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.2015-06-25 05:43:13,273 [myid:1] - INFO  [main:QuorumPeerMain@127] - Starting quorum peer2015-06-25 05:43:13,285 [myid:1] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:21812015-06-25 05:43:13,312 [myid:1] - INFO  [main:QuorumPeer@959] - tickTime set to 20002015-06-25 05:43:13,312 [myid:1] - INFO  [main:QuorumPeer@979] - minSessionTimeout set to -12015-06-25 05:43:13,312 [myid:1] - INFO  [main:QuorumPeer@990] - maxSessionTimeout set to -12015-06-25 05:43:13,315 [myid:1] - INFO  [main:QuorumPeer@1005] - initLimit set to 102015-06-25 05:43:13,359 [myid:1] - INFO  [Thread-1:QuorumCnxManager$Listener@504] - My election bind port: /127.0.0.1:3882015-06-25 05:43:13,371 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer@714] - LOOKING2015-06-25 05:43:13,374 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@815] - New election.2015-06-25 05:43:13,252 [myid:] - INFO  [main:QuorumPeerConfig@103] - Reading configuration from: /app/soft/zookeeper_node1/bin/../conf/zoo.cfg2015-06-25 05:43:13,257 [myid:] - INFO  [main:QuorumPeerConfig@340] - Defaulting to majority quorums2015-06-25 05:43:13,260 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 32015-06-25 05:43:13,260 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 02015-06-25 05:43:13,262 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.2015-06-25 05:43:13,273 [myid:1] - INFO  [main:QuorumPeerMain@127] - Starting quorum peer2015-06-25 05:43:13,285 [myid:1] - INFO  [main:NIOServerCnxnFactory@94] - binding to port 0.0.0.0/0.0.0.0:21812015-06-25 05:43:13,312 [myid:1] - INFO  [main:QuorumPeer@959] - tickTime set to 20002015-06-25 05:43:13,312 [myid:1] - INFO  [main:QuorumPeer@979] - minSessionTimeout set to -12015-06-25 05:43:13,312 [myid:1] - INFO  [main:QuorumPeer@990] - maxSessionTimeout set to -12015-06-25 05:43:13,315 [myid:1] - INFO  [main:QuorumPeer@1005] - initLimit set to 102015-06-25 05:43:13,359 [myid:1] - INFO  [Thread-1:QuorumCnxManager$Listener@504] - My election bind port: /127.0.0.1:38882015-06-25 05:43:13,371 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer@714] - LOOKING2015-06-25 05:43:13,374 [myid:1] - INFO  [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@815] - New election. My id =  1, proposed zxid=0x22015-06-25 05:43:13,376 [myid:1] - INFO  [WorkerReceiver[myid=1]:FastLeaderElection@597] - Notification: 1 (message format version), 1 (n.leader), 0x2 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x1 (n.peerEpoch) LOOKING (my state)2015-06-25 05:43:13,379 [myid:1] - WARN  [WorkerSender[myid=1]:QuorumCnxManager@382] - Cannot open channel to 2 at election address /127.0.0.1:3889java.net.ConnectException: Connection refused        at java.net.PlainSocketImpl.socketConnect(Native Method)        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)        at java.net.Socket.connect(Socket.java:579)        at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:368)        at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:341)        at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:449)        at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:430)        at java.lang.Thread.run(Thread.java:745)2015-06-25 05:43:13,385 [myid:1] - WARN  [WorkerSender[myid=1]:QuorumCnxManager@382] - Cannot open channel to 3 at election address /127.0.0.1:3890java.net.ConnectException: Connection refused        at java.net.PlainSocketImpl.socketConnect(Native Method)        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)

An error is reported because the node 2 and node 3 services are not started yet. Start nodes 2 and 3 in sequence according to the start method of Node 1, and view the log again to find that the service is normal.

View log command: vi zookeeper. out

(7) view the service status as follows:

[root@localhost soft]# zookeeper_node1/bin/zkServer.sh statusJMX enabled by defaultUsing config: /app/soft/zookeeper_node1/bin/../conf/zoo.cfgMode: follower[root@localhost soft]# zookeeper_node2/bin/zkServer.sh statusJMX enabled by defaultUsing config: /app/soft/zookeeper_node2/bin/../conf/zoo.cfgMode: leader[root@localhost soft]# zookeeper_node3/bin/zkServer.sh statusJMX enabled by defaultUsing config: /app/soft/zookeeper_node3/bin/../conf/zoo.cfgMode: follower

We can see that 1 is follower, 2 is leader, and 3 is follower.

 

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.