Install ZooKeeper in standalone mode and cluster mode in CentOS

Source: Internet
Author: User

Install ZooKeeper in standalone mode and cluster mode in CentOS

The environment for this article is as follows:
Operating System: CentOS 6 32-bit
ZooKeeper version: 3.4.8

0. environment requirements

Zookeeper requires a Java environment later than JDK1.6.
Refer:
CentOS 6 JDK8 installation using rpm

1. download the software package

Go to the ZooKeeper official website and download the software package at http://zookeeper.apache.org/, for example:

wget "http://apache.opencas.org/zookeeper/stable/zookeeper-3.4.8.tar.gz"tar -xzvf zookeeper-3.4.8.tar.gzmv zookeeper-3.4.8 /opt
2. modify the configuration file in standalone mode 2.1
cd /opt/zookeeper-3.4.8/conf/cp zoo_sample.cfg zoo.cfgvi zoo.cfg

Zookeeper provides a default configuration file. After the file is copied to zoo. cfg, we need to modify the data storage path:

dataDir=/opt/zookeeper-3.4.8/data
2.2 run Zookeeper
cd /opt/zookeeper-3.4.8/bin/./zkServer.sh start

If no error is reported, Zookeeper is successfully started.
To facilitate future operations, we can add Zookeeper/bin to path

vi /etc/profile

Add at the end:

ZOOKEEPER_HOME=/opt/zookeeper-3.4.8PATH=$PATH:$ZOOKEEPER_HOME/bin

Update Configuration:

source /etc/profile
3. Cluster Mode

The standalone mode is very convenient and suitable for development and testing scenarios. However, a cluster mode should be run in the production environment. The cluster mode should have at least three nodes, and it is strongly recommended that there be an odd number of nodes. Each node should have the same configuration file.

3.1 modify the configuration file
cd /opt/zookeeper-3.4.8/conf/vi zoo.cfg

After opening, modify it:

tickTime=2000dataDir=/opt/zookeeper-3.4.8/dataclientPort=2181initLimit=5syncLimit=2server.1=master:2888:3888server.2=slave1:2888:3888server.3=slave2:2888:3888

The number followed by the server is the label of the node. We need to write this number into the file named myid. The file should be stored in the directory pointed to by the previously configured dataDir.
For example, in the preceding slave1 node, the corresponding data/myid file should be written to 2.

3.2 copy a folder
scp -r /opt/zookeeper-3.4.8 root@slave1:/opt/scp -r /opt/zookeeper-3.4.8 root@slave2:/opt/

After the copy is complete, remember to modify the myid file of the corresponding server.

3.3 start the service

You need to start the Zookeeper service on each node. After each node is started, you can use zkServer. sh status to view the startup status of the current node and whether it is a leader node or a follower node.

4. Exception Analysis

The running log file is zookeeper. out in the program directory by default.

4.1 unable to connect
2016-04-13 05:18:21,531 [myid:1] - WARN  [WorkerSender[myid=1]:QuorumCnxManager@400] - Cannot open channel to 2 at election address slave1/5.2.8.5:3888java.net.ConnectException: Connection refused        at java.net.PlainSocketImpl.socketConnect(Native Method)        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)        at java.net.Socket.connect(Socket.java:589)        at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:381)        at org.apache.zookeeper.server.quorum.QuorumCnxManager.toSend(QuorumCnxManager.java:354)        at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.process(FastLeaderElection.java:452)        at org.apache.zookeeper.server.quorum.FastLeaderElection$Messenger$WorkerSender.run(FastLeaderElection.java:433)        at java.lang.Thread.run(Thread.java:745)

This exception may occur because the firewall of the zookeeper node is enabled and the corresponding port (2888,3888) is not enabled. It may also be because a node is not started or has crashed.

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.