ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide

IT Open Net 10/07/2021 207

It was difficult to learn an article, but it was not so difficult. Although some nouns are not understood, I decided to encounter it in subsequent learning?

先决条件

Have not seen it yet

See System Requirements in Administrative Guide.

下载

Download link [1] Apache Zookeeper 3.7.0 is a compiled version with a variety of JAR packages. Another Release version is also installed JAR, so we use Apache Zookeeper 3.7.0.

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述独立运行

Reference link [2]

1 选择一个合适的目录,然后用winzip解压即可2 创建zoo.cfgZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

(1) TickTime: The interval between the server or the client and the server maintains a heartbeat. Unit, minimum session timeout is twice the TickTime (2) DATADIR: Save Data, if you do not specify the log of write data, it will be placed here (3) DatalogDir: So this, save the log (4) Clientport : The client connects the port of the Zookeeper server

3 创建空的数据和日志存放地址并修改zoo.cfgZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

4 Try start (server) (single machine version)

Double click ZKSERVER.CMD

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

If you flash back, you can correct zkserver.cmd, enter PAUSE, save the push, run again, and view the reason for the error. Reference link [3]

5 看一下是否启动成功

CMD input

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述管理ZooKeeper存储

Empty ~

连接到ZooKeeper(客户端)(单机版)

Double-click zkcli.cmd looks failed, find the reason

After all of me, I finally found that I turned ZKSERVER.CMD when I opened zkcli.cmd. They a server, a client, server, and the client is naturally connected., or too caravan.

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述一些指令

• 1 HELP Gets a list of client commands

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

• 2 Create a new node (1): Create a new node (znode), zk_test, and associate it with strings "my_data" (2): View the directory

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述•3 获取节点数据ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述这个和官网的图不一样欸,官网可以获取到一长串信息(如下所示),我们来找找原因。

(1) I am thinking about whether it is a version problem, so I downloaded a ZooKeeper-3.4.13 and then prepared to create a node, the same name. (2) First, find the same zookeeper directory they use (why? I will encounter it later). (3), then, I will get

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

So really is the version problem (4) If you want to see the version information on 3.7.0, you can use:

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

• 4 Delete Node

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

For more details, please refer to the programmer guide [4]

ZooKeeper编程

ZooKeeper has a Java binding and C binding, feature equivalent. The difference is how the message delivery loop is completed. See the programmer guide [5] for details.

集群模式下运行ZooKeeper

Single-machine ZooKeeper is suitable for assessing development and testing. However, the production environment should run ZooKeeper in the cluster mode. The server group replicated in the ZooKeeper cluster is called the statutory quorum, all servers in the statutory number have the same configuration file.

Note

• 1 Cluster mode, the number of servers is at least 3, and the odd server is highly recommended. Because if there is only two servers, one server has a fault, there is a server, and there is no way to form a majority. (Election?) • 2 Setting multiple servers on a machine does not generate redundancy, so all servers will be downtime after machine failure. It is really that every server has a fully independent physical server.

在一台计算机上搭建伪集群参考链接[6]1 复制将之前的ZooKeeper文件复制3份,我顺便换了各名字ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述2 修改zoo.cg(1)initLimit:初始化连接时,Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器最长可以忍受的心跳时长(),如果超出时长还没有连接成功,则说明连接失败。 (2)syncLimit:Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不超过。 (3)server.A=B:C:D A是当前服务的序号,B是该服务所在IP地址,C是节点之间信息交流的端口,D是服务出现异常后,选举Leader的端口

ZK1

ZK2

zk3

3 Creating a MyID file

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

myid的值是zoo.cfg文件里定义的server.A项A的值。Zookeeper启动时会读取这个文件。因此ZK1 的myid内容是1,ZK2 的是2,zk3 的是3。

4 启动

Click on the respective zkserver, respectively.

• 1 error:

• 2 Forgot to change myid, change it, try again. Still report this wrong:

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

The main reason here is that the MyID file is not found, and it is related to the directory, and the directory is changed: This is fine. (I do not know why either)

• 3 three full openings will not report an error

•4 ZK1 报错

I will change their port number.

Then just fine, although I didn't find other applications to take up these ports, but changed.

5 如何判断好没有呢?

Click any zcli.cmd and appear below.

ZooKeeper official documentation Learning Notes 02-ZooKeeper Getting Started Guide  在这里插入图片描述

Of course, you can do not motion, lose command: Reference link [7]

其他优化

Separate transaction logs and data snapshots, that is, the previous log directory

Congratulations, I have finished studying again, I am really awesome!

References

Download link: https://zookeeper.apache.org/releases.html Reference Link: https://blog.csdn.net/qq_33316784/Article/details/88563482 Reference Link: https://blog.csdn.net/sky198989 / Article / Details / 82778957 Programmer Guide: https://zookeeper.5.5.5.5.5/zookeeperprogrammers.html Programmer Guide: https://zookeeper.apache.org/doc/r3.5.5/zookeeperprogrammers .html Reference Link: https://blog.csdn.net/zhangphil/Article/details/99990669 Reference Link: https://www.cnblogs.com/yangzhenlong/p/8270835.html

Latest: 22 How do I evaluate the difficulty of professional courses? Pay attention to avoid these traps! _ Hubei Xinwen Taoist Postgraduate

Next: 10kv column intelligent high pressure prepaid integrated vacuum circuit breaker ZW32-12