Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and deploy a ZooKeeper cluster

2025-04-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to install and deploy ZooKeeper clusters", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to install and deploy ZooKeeper clusters".

0. ZooKeeper can also be used for other purposes, such as:

Data publish and subscribe (configuration Center)

Load balancing

Naming Service (Naming Service)

Distributed notification / coordination

Cluster Management and Master Election

Distributed lock

Distributed queue

1. Introduction and system requirements

ZooKeeper can run on a variety of system platforms. Table 1 shows the system platforms supported by zk and whether the development environment or production environment is supported on this platform.

System development environment production environment

Linux support support

Solaris support support

FreeBSD support support

Does Windows support it?

Does MacOS support it?

There are three ways to install Zookeeper, stand-alone mode, cluster mode and pseudo-cluster mode.

■ stand-alone mode: Zookeeper runs on only one server, which is suitable for test environment.

■ pseudo-cluster mode: running multiple Zookeeper instances on a single physical machine

■ cluster mode: Zookeeper runs on a cluster and is suitable for production environments. This computer cluster is called an "ensemble".

Zookeeper achieves high availability through replication, ensuring that the service continues as long as more than half of the machines in the collection are available. Why does it have to be more than half? This is related to Zookeeper's replication strategy: zookeeper ensures that every change to the znode tree is copied to more than half of the machines in the collection.

Therefore, for the deployment of ZooKeeper cluster mode, the minimum number of three ZooKeeper service processes is recommended, and different service processes are recommended to be deployed on different physical machines to reduce the risk of machine downtime and achieve high availability of ZooKeeper clusters.

ZooKeeper is written in Java and runs on the Java environment, so the Java runtime environment needs to be installed on the machine where zk is deployed. In order to run zk properly, we need JRE1.6 or above. ZooKeeper has no great requirements for the hardware configuration of the machine.

2. Download and install

You can download ZooKeeper from https://zookeeper.apache.org/releases.html. The latest stable version is version 3.4.11. We chose version 3.4.10 today.

# tar zvxf zookeeper-3.4.10.tar.gz

# mv zookeeper-3.4.10.. / zk

# cd.. / zk

[root@galera01 zk] # ls-l

Drwxr-xr-x 2 1001 1001 4096 Mar 23 2017 bin

-rw-rw-r-- 1 1001 1001 84725 Mar 23 2017 build.xml

Drwxr-xr-x 2 1001 1001 4096 Mar 23 2017 conf

Drwxr-xr-x 10 1001 1001 4096 Mar 23 2017 contrib

Drwxr-xr-x 2 1001 1001 4096 Mar 23 2017 dist-maven

Drwxr-xr-x 6 1001 1001 4096 Mar 23 2017 docs

-rw-rw-r-- 1 1001 1001 1709 Mar 23 2017 ivysettings.xml

-rw-rw-r-- 1 1001 1001 5691 Mar 23 2017 ivy.xml

Drwxr-xr-x 4 1001 1001 4096 Mar 23 2017 lib

-rw-rw-r-- 1 1001 1001 11938 Mar 23 2017 LICENSE.txt

-rw-rw-r-- 1 1001 1001 3132 Mar 23 2017 NOTICE.txt

-rw-rw-r-- 1 1001 1001 1770 Mar 23 2017 README_packaging.txt

-rw-rw-r-- 1 1001 1001 1585 Mar 23 2017 README.txt

Drwxr-xr-x 5 1001 1001 4096 Mar 23 2017 recipes

Drwxr-xr-x 8 1001 1001 4096 Mar 23 2017 src

-rw-rw-r-- 1 1001 1001 1456729 Mar 23 2017 zookeeper-3.4.10.jar

-rw-rw-r-- 1 1001 1001 819 Mar 23 2017 zookeeper-3.4.10.jar.asc

-rw-rw-r-- 1 1001 1001 33 Mar 23 2017 zookeeper-3.4.10.jar.md5

-rw-rw-r-- 1 1001 1001 41 Mar 23 2017 zookeeper-3.4.10.jar.sha1

Bin directory: the executable script directory of zk, including scripts for zk service processes, zk clients, etc.

Conf directory: configuration file directory. Zoo_sample.cfg is the sample configuration file, and log4j.properties is the log configuration file.

Lib directory: the package that zk depends on.

Contrib directory: some toolkits for manipulating zk.

Recipes directory: code examples for some uses of zk

3. Cluster mode running configuration

Although the zk process in stand-alone mode is easy to develop and test, it is not suitable for use in a production environment. In a production environment, we need to use cluster mode to deploy zk. In cluster mode, it is recommended to deploy at least 3 zk processes or an odd number of zk processes.

In cluster mode, all zk processes can use the same configuration file (which means that each zk process is deployed on different machines), such as the following configuration:

# mkdir-p / opt/zkdata

# cd / opt/zk/conf

# cp zoo_sample.cfg zk.cfg

# vi zk.cfg

TickTime=2000

DataDir=/opt/zkdata

ClientPort=2181

InitLimit=5

SyncLimit=2

Server.0=192.168.56.111:2888:3888

Server.1=192.168.56.112:2888:3888

Server.3=192.168.56.113:2888:3888

The name of the setting selection configuration file is in the zkEnv.sh file. The default is zoo.cfg, which has been changed to zk.cfg.

TickTime parameter: tickTime is the basic unit of the above two timeout configurations. For example, for initLimit, the configuration value is 5, indicating that the timeout is 2000ms * 5 = 10 seconds.

InitLimit parameter: there are multiple zk processes in ZooKeeper cluster mode, one of which is leader and the rest is follower.

When follower first established a connection with leader, a considerable amount of data was transferred between them, especially when the data of follower lagged far behind leader.

InitLimit configures the maximum time to synchronize after a connection is established between follower and leader.

SyncLimit parameter: configure the maximum length of time to send messages, requests, and replies between follower and leader. If follower cannot communicate with leader within the setup time, the follower will be discarded.

MaxClientCnxns parameters:

This operation limits the number of clients connected to Zookeeper and the number of concurrent connections, distinguishing different clients through IP. This configuration option prevents certain types of Dos attacks. Setting it to zero or ignoring not setting it will remove the restriction on concurrent connections.

For example, at this point we set the value of maxClientCnxns to 1, as follows:

# set maxClientCnxns

MaxClientCnxns=1

After starting Zookeeper, first connect to the Zookeeper server with a client. Later, if a second client attempts to connect to Zookeeper, or if there is some implicit connection to the client, the above configuration of Zookeeper will be triggered.

MinSessionTimeout and maxSessionTimeout parameters:

That is, the minimum session timeout and the maximum session timeout. By default, minSession=2*tickTime;maxSession=20*tickTime.

Server.id=host:port1:port2

Where id is a number that represents the id of the zk process, and this id is also the content of the myid file in the dataDir directory.

Host is the IP address where the zk process is located, port1 represents the port on which follower and leader exchange messages, and port2 indicates the port on which leader is elected.

DataDir parameter: this parameter has no default value and must be configured. The meaning of configuration is similar to that in stand-alone mode, except that there is a myid file in cluster mode.

The content of the myid file is only one line, and the content can only be a number between 1mm and 255. this number, that is, the id in the server.id above, represents the id of the zk process.

#. / zkServer.sh start

ZooKeeper JMX enabled by default

Using config: / opt/zk/bin/../conf/zk.cfg

Starting zookeeper... STARTED

. / zkCli.sh-server 192.168.56.111purl 2181192.168.56.112Vera 2181192.168.56.113purl 2181

#. / zkCli.sh-server 192.168.56.111purl 2181192.168.56.112Vera 2181192.168.56.113purl 2181

Connecting to 192.168.56.111:2181192.168.56.112:2181192.168.56.113:2181

2018-03-12 14 main:Environment@100 2018 23 468 [myid:]-INFO [main:Environment@100]-Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03 Greater 23 Greater 10:13 GMT

2018-03-12 14-14-20-23 473 [myid:]-INFO [main:Environment@100]-Client environment:host.name=galera02

2018-03-12 14-14-20-23 473 [myid:]-INFO [main:Environment@100]-Client environment:java.version=1.7.0_45

2018-03-12 14-14-20-23 474 [myid:]-INFO [main:Environment@100]-Client environment:java.vendor=Oracle Corporation

2018-03-12 14 main:Environment@100 2015 23475 [myid:]-INFO [main:Environment@100]-Client environment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64/jre

2018-03-12 14-14 main:Environment@100 20-23 475 [myid:]-INFO [main:Environment@100]-Client environment:java.class.path=/opt/zk/bin/../build/classes:/opt/zk/bin/../build/lib/*.jar:/opt/zk/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zk/bin/../lib/slf4j-api-1.6.1.jar:/opt/zk/bin /.. / lib/netty-3.10.5.Final.jar:/opt/zk/bin/../lib/log4j-1.2.16.jar:/opt/zk/bin/../lib/jline-0.9.94.jar:/opt/zk/bin/../zookeeper-3.4.10.jar:/opt/zk/bin/../src/java/lib/*.jar:/opt/zk/bin/../conf:

2018-03-12 14 main:Environment@100 2015 23475 [myid:]-INFO [main:Environment@100]-Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

2018-03-12 14 main:Environment@100 2015 23475 [myid:]-INFO [main:Environment@100]-Client environment:java.io.tmpdir=/tmp

2018-03-12 14 main:Environment@100 2015 23475 [myid:]-INFO [main:Environment@100]-Client environment:java.compiler=

2018-03-12 14 main:Environment@100 2015 23475 [myid:]-INFO [main:Environment@100]-Client environment:os.name=Linux

2018-03-12 14 main:Environment@100 2015 23475 [myid:]-INFO [main:Environment@100]-Client environment:os.arch=amd64

2018-03-12 14-14 main:Environment@100 20-23 475 [myid:]-INFO [main:Environment@100]-Client environment:os.version=2.6.32-431.el6.x86_64

2018-03-12 14 main:Environment@100 2015 23475 [myid:]-INFO [main:Environment@100]-Client environment:user.name=root

2018-03-12 14-14-20-23 476 [myid:]-INFO [main:Environment@100]-Client environment:user.home=/root

2018-03-12 14-14-20-23 476 [myid:]-INFO [main:Environment@100]-Client environment:user.dir=/opt/zk/bin

2018-03-12 14-14-20-23-77 [myid:]-INFO [main:ZooKeeper@438]-Initiating client connection, connectString=192.168.56.111:2181192.168.56.112:2181192.168.56.113:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@6c8d5190

2018-03-12 14 14 main-SendThread 2015 23494 [myid:]-INFO [main-SendThread (192.168.56.113): ClientCnxn$SendThread@1032]-Opening socket connection to server 192.168.56.113) 192.168.56.113 Will not attempt to authenticate using SASL (unknown error)

Welcome to ZooKeeper!

2018-03-12 14 14 main-SendThread 2015 23581 [myid:]-INFO [main-SendThread (192.168.56.113): ClientCnxn$SendThread@876]-Socket connection established to 192.168.56.113 / 192.168.56.113 / 19181, initiating session

JLine support is enabled

2018-03-12 1414 main-SendThread 2018868 [myid:]-INFO [main-SendThread (192.168.56.113purl 2181): ClientCnxn$SendThread@1299]-Session establishment complete on server 192.168.56.113ampoule 192.168.56.113purl 2181, sessionid = 0x26218afe3bd0000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: 192.168.56.111 zk 2181192.168.56.112purl 2181192.168.56.113purl 2181 (CONNECTED) 0]

[zk: 192.168.56.111 quit 2181192.168.56.112purl 2181192.168.56.113purl 2181 (CONNECTED) 0]

Quitting...

2018-03-12 14 main-EventThread:ClientCnxn$EventThread@519 22 main-EventThread:ClientCnxn$EventThread@519 41435 [myid:]-INFO [main-EventThread:ClientCnxn$EventThread@519]-EventThread shut down for session: 0x26218afe3bd0000

2018-03-12 14 main:ZooKeeper@684 22 main:ZooKeeper@684 41436 [myid:]-INFO [main:ZooKeeper@684]-Session: 0x26218afe3bd0000 closed

4. Check the current zk cluster status

[root@galera01 bin] #. / zkServer.sh status

ZooKeeper JMX enabled by default

Using config: / opt/zk/bin/../conf/zk.cfg

Mode: follower

[root@galera02 bin] #. / zkServer.sh status

ZooKeeper JMX enabled by default

Using config: / opt/zk/bin/../conf/zk.cfg

Mode: leader

[root@galera03 bin] #. / zkServer.sh status

ZooKeeper JMX enabled by default

Using config: / opt/zk/bin/../conf/zk.cfg

Mode: follower

-End

These are all the contents of the article "how to install and deploy ZooKeeper clusters". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report