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

Construction and introduction of Zookeeper Cluster

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains "the Construction and introduction of Zookeeper Cluster". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "the Construction and introduction of Zookeeper Cluster"!

1. Set up

How to build a stand-alone machine without security verification is not to say, Baidu search a lot. Here I will talk about how to build a Zookeeper cluster that is available in the production environment.

Download address of Zookeeper 3.4.13

Docker is not recommended, and there are many things to consider. If you want to use Docker, it is recommended to build your own image. If you are an Docker expert, you can ignore this sentence.

The following description is to build under the Linux server (the Winserver server is also the same) first operate a single machine, and then copy to other machines. After downloading Zookeeper (hereinafter referred to as zk), enter the conf folder under the decompressed directory of zk. Zoo_sample.cfg is an instance of the configuration file of zk. A Copy named zoo.cfg zk will read this configuration by default.

Configuration details:

TickTime: the interval between heartbeats, which is used to determine whether the Client is disconnected (default 2000ms)

DataDir: the directory where zk data files are saved. Zk stores configurations based on files.

ClientPort: this port is the port on which the client connects to the zk server. Zk listens on this port and accepts requests for access from the client.

InitLimit: the number of retries when initializing Client (default is 5). To determine whether a Client connection is successful, an initLimit heartbeat is sent. Each tickTime sends a heartbeat. If all failed, the Client connection failed.

SyncLimit: this configuration item identifies the length of time for sending messages, requests and replies between Leader and Follower. The maximum length of time cannot exceed the number of tickTime. The total time length is 2 "2000" 4 seconds.

Server.n = ip:port:electPort: n represents the serial number of each instance. Ip is the ip address of each instance, port is the port for interaction between instances, and electPort is the port for re-electing Leader. (it is only used in cluster mode. The stand-alone machine can comment on this configuration. I asked the great god earlier that it is safe for zk to build at least 3 instances, which is related to its own election mechanism.

MaxClientCnxns: the maximum number of Client connections. If the concurrency of business requirements is large, if the machine is relatively strong, set it larger (default is 60).

Autopurge.snapRetainCount: number of files retained when automatically cleaning snapshot and transaction logs (default 3)

Autopurge.purgeInterval: cleaning frequency (in hours). Default is 0: not enabled, and greater than 0: enable `.

To use Hosts, set Hosts (/ etc/hosts) on the machine where each instance resides, such as zk1 127.0.0.1

Here is my simple configuration:

# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use / tmp for storage, / tmp here is just # example sakes.dataDir=/data/zookeeper/data# the port at which the clients will connectclientPort=2181server.1=zk1:2888:3888server.2=zk2:2888:3888server.3=zk2:2888:38882. Start

The scripts for zk are placed in the zk/bin directory

ZkServer.sh service operation script (only common commands are introduced)

# background start. / zkServer.sh start# foreground start. / zkServer.sh start-foreground# stop. / zkServer.sh stop# restart. / zkServer.sh restart# check status (where Mode represents a Leader node or a Follow node). / zkServer.sh status

ZkCli.sh is the client of zk. It connects to local instances by default. You can operate other remote instances by executing ZooKeeper-server host:port cmd args after entering ZkCli.

# enter zk client command line operation. / zkCli.sh

List some common commands (other commands can)

# View ls / pathget / path# under root directory to view node status / attribute stat / path# delete node rmr / path# delete data delete / path [version] 3. Permission verification

There are three ways to verify the permissions of zk. Here are only two commonly used methods (first, build a cluster, and the permission settings will be synchronized to the entire cluster):

Step 1: create a new node (ignored if you add permissions to an existing node) create / path "test" # create a node and alias 1. The permission verification setting command after entering zkCli through IP restriction # will introduce the permission parameter setAcl / path ip:192.168.1.1: [permissions] # or the ip segment setAcl / path ip:192.168.0.0/16: [permissions] # verify that the local verification is passed. You can use another ip segment to verify ls / path2. Controlled by user + password

The password in this way is the ciphertext from BASE64 (SHA1). How to generate the ciphertext that ensures success?

# calculate the ciphertext through this class (the corresponding version can be seen in the zk/lib directory) java-cp. / zookeeper-3.4.13.jar:./lib/log4j-1.2.17.jar:./lib/slf4j-log4j12-1.7.25.jar:./lib/slf4j-api-1.7.25.jar org.apache.zookeeper.server.auth.DigestAuthenticationProvider test:123456#test is the user name password is the password BASE64 (SHA1 (original ciphertext) Code)) setAcl / path digest:test:password: [permission] # verify whether the check is successful Now it must be successful, but if you re-enter zkCli, you will fail. Ls / path# will enter zkCli to execute the addAuth command. This is a function similar to login. Test is the user name, 123456 is the original addauth digest test:123456#, and then execute the ls command. Then you will successfully introduce ls / pathpermission.

Permission is represented by cdrwa, such as:

SetAcl / path digest:test:password:cdw

Each letter represents:

CREATE (c): create permission to create a child node under the current node

DELETE (d): delete permissions to delete the current node

READ (r): read permission to get the data of the current node, and to list all the child nodes of the current node

WRITE (w): write permission to write data to the current node

ADMIN (a): administrative permissions, which can set the permission of the current node

At this point, I believe you have a deeper understanding of "the construction and introduction of Zookeeper cluster". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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: 206

*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

Servers

Wechat

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

12
Report