Zookeeper stand-alone and cluster installation

Source: Internet
Author: User
Tags zookeeper


1. Download package

Download packages to the zookeeper online 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.gz
MV Zookeeper-3.4.8/opt
1 2 3 2. Stand-alone mode 2.1 Modifying the configuration file
cd/opt/zookeeper-3.4.8/conf/
cp zoo_sample.cfg zoo.cfg
VI zoo.cfg
1 2 3

Zookeeper provides a default profile that, when replicated as ZOO.CFG, needs to modify the path where the data is stored:

Datadir=/opt/zookeeper-3.4.8/data
1
2.2 Running Zookeeper
cd/opt/zookeeper-3.4.8/bin/
./zkserver.sh start
1 2

If there is no error in the operation, the zookeeper started successfully.
In order to be easy to operate later, we can add zookeeper/bin to path

Vi/etc/profile
1

At the end add:

zookeeper_home=/opt/zookeeper-3.4.8
path= $PATH: $ZOOKEEPER _home/bin
1 2

Update configuration:

Source/etc/profile
1
3. Cluster model

stand-alone mode is convenient for developing and testing scenarios, but in a production environment, you should run a cluster pattern. Cluster mode should have at least 3 nodes, and it is highly recommended that you have an odd number of nodes, each node should have the same configuration file. 3.1 Modifying the configuration file

cd/opt/zookeeper-3.4.8/conf/
VI zoo.cfg
1 2

When opened, modify to:

ticktime=2000
datadir=/opt/zookeeper-3.4.8/data
clientport=2181
initlimit=5
synclimit=2
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
1 2 3 4 5
6 7 8

The number following the server is the label of the node, and we need to write this number to a file named myID. The file should be stored in the directory pointed to by the previously configured DataDir.
For example, the SLAVE1 node above, the corresponding Data/myid file should be written to 2.
3.2 Copy folder

Scp-r/opt/zookeeper-3.4.8 root@slave1:/opt/
scp-r/opt/zookeeper-3.4.8 root@slave2:/opt/
1 2

after the copy is complete, remember to modify the myID file for the corresponding server. 3.3 start service

The zookeeper service needs to be started on each node, and each node can use zkserver.sh status to view the current node's startup state and whether it is a leader node or follower node. 4. Anomaly Analysis

The run log file defaults to the Zookeeper.out in the program directory. 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 Electio N Address slave1/5.2.8.5:3888 Java.net.ConnectException:Connection refused at Java.net.PlainSocketImpl.socketConn ECT (Native) 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.quoru M.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)
1 2 3 4 5 6 7 8 (9)

This exception may be that the firewall for the Zookeeper node is turned on and the corresponding port (2888,3888) is not opened, or that a node is not started or is dead.

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.