ZooKeeper入门指南,2024年最新java面试必问技术栈

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Java开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024b (备注Java)
img

正文

*   [管理ZooKeeper存储]( )
*   [Connecting to ZooKeeper]( )
*   [连接到ZooKeeper]( )
*   [Programming to ZooKeeper]( )
*   [ZooKeeper编程]( )
*   [Running Replicated ZooKeeper]( )
*   [运行ZooKeeper集群]( )
*   [Other Optimizations]( )
*   [其他优化]( )

Getting Started: Coordinating Distributed Applications with ZooKeeper


入门指南:使用ZooKeeper协调分布式应用程序

This document contains information to get you started quickly with ZooKeeper. It is aimed primarily at developers hoping to try it out, and contains simple installation instructions for a single ZooKeeper server, a few commands to verify that it is running, and a simple programming example. Finally, as a convenience, there are a few sections regarding more complicated installations, for example running replicated deployments, and optimizing the transaction log. However for the complete instructions for commercial deployments, please refer to the ZooKeeper Administrator’s Guide.

本文档包含使您快速开始使用ZooKeeper的信息。它主要针对希望尝试使用它的开发人员,并包含单个ZooKeeper服务器的简单安装说明,一些验证其正在运行的命令以及一个简单的编程示例。最后,为方便起见,有几节涉及更复杂的安装,例如,集群运行的部署以及优化事务日志。但是,有关商业部署的完整说明,请参阅《ZooKeeper管理员指南》

Pre-requisites

See System Requirements in the Admin guide.

先决条件

请参阅管理指南中的系统要求

Download

To get a ZooKeeper distribution, download a recent stable release from one of the Apache Download Mirrors.

下载

要获得ZooKeeper发行版,请从Apache下载镜像之一下载最新的稳定版本。

Standalone Operation

Setting up a ZooKeeper server in standalone mode is straightforward. The server is contained in a single JAR file, so installation consists of creating a configuration.

Once you’ve downloaded a stable ZooKeeper release unpack it and cd to the root

To start ZooKeeper you need a configuration file. Here is a sample, create it in conf/zoo.cfg:

独立运行

在独立模式下设置ZooKeeper服务器非常简单。该服务器包含在单个JAR文件中,因此安装包括创建配置。

下载稳定的ZooKeeper版本后,将其解压缩并CD到根目录

要启动ZooKeeper,您需要在conf / zoo.cfg中创建一个配置文件。下面这个是一个示例:

tickTime=2000 dataDir=/var/lib/zookeeper clientPort=2181

This file can be called anything, but for the sake of this discussion call it conf/zoo.cfg. Change the value of dataDir to specify an existing (empty to start with) directory. Here are the meanings for each of the fields:

  • tickTime : the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.
  • dataDir : the location to store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database.
  • clientPort : the port to listen for client connections

Now that you created the configuration file, you can start ZooKeeper:

该文件可以被命名为任何文件,但是为了便于讨论,将其命名为conf / zoo.cfg。更改dataDir的值指定以现有(一开始是空文件)目录。以下是每个字段的含义:

  • tickTime:ZooKeeper使用的基本时间单位(毫秒)。它用于做心跳,并且最小会话超时将是tickTime的两倍。

  • dataDir:存储内存数据库快照的位置,除非另有说明,否则存储数据库更新的事务日志。

  • clientPort:用于侦听客户端连接的端口

现在,您已经创建了配置文件,您可以启动ZooKeeper:

bin/zkServer.sh start

ZooKeeper logs messages using log4j – more detail available in the Logging section of the Programmer’s Guide. You will see log messages coming to the console (default) and/or a log file depending on the log4j configuration.

The steps outlined here run ZooKeeper in standalone mode. There is no replication, so if ZooKeeper process fails, the service will go down. This is fine for most development situations, but to run ZooKeeper in replicated mode, please see Running Replicated ZooKeeper.

ZooKeeper使用log4j记录消息-有关详细信息,请参阅《程序员指南》的“记录”部分。您将看到进入控制台的日志消息(默认)和/或一个日志文件,具体取决于log4j配置。

此处概述的步骤以独立模式运行ZooKeeper。没有集群,因此,如果ZooKeeper进程失败,该服务将关闭。这对于大多数开发情况都很好,但是要以集群方式运行ZooKeeper,请参阅“运行ZooKeeper集群”

Managing ZooKeeper Storage

For long running production systems ZooKeeper storage must be managed externally (dataDir and logs). See the section on maintenance for more details.

Connecting to ZooKeeper

管理ZooKeeper存储

对于长时间运行的生产系统,必须从外部管理ZooKeeper存储(dataDir和日志)。有关更多详细信息,请参见维护部分。

连接到ZooKeeper

$ bin/zkCli.sh -server 127.0.0.1:2181

This lets you perform simple, file-like operations.

Once you have connected, you should see something like:

这使您可以执行简单的类似文件的操作。

连接后,您应该会看到类似以下内容的信息:

Connecting to localhost:2181 log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper). log4j:WARN Please initialize the log4j system properly. Welcome to ZooKeeper! JLine support is enabled [zkshell: 0]

From the shell, type help to get a listing of commands that can be executed from the client, as in:

在shell中,键入help以获取可以在客户端执行的命令的列表,如下所示:

[zkshell: 0] help ZooKeeper -server host:port cmd args addauth scheme auth close config [-c] [-w] [-s] connect host:port create [-s] [-e] [-c] [-t ttl] path [data] [acl] delete [-v version] path deleteall path delquota [-n|-b] path get [-s] [-w] path getAcl [-s] path getAllChildrenNumber path getEphemerals path history listquota path ls [-s] [-w] [-R] path ls2 path [watch] printwatches on|off quit reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*] redo cmdno removewatches path [-c|-d|-a] [-l] rmr path set [-s] [-v version] path data setAcl [-s] [-v version] [-R] path acl setquota -n|-b val path stat [-w] path sync path

From here, you can try a few simple commands to get a feel for this simple command line interface. First, start by issuing the list command, as in ls, yielding:

从这里,您可以尝试一些简单的命令,以了解这种简单的命令行界面。首先,如中下所示ls 发出list命令,得到:

[zkshell: 8] ls / [zookeeper]

Next, create a new znode by running create /zk_test my_data. This creates a new znode and associates the string “my_data” with the node. You should see:

接下来,通过运行创建一个新的znode create /zk_test my_data。这将创建一个新的znode并将字符串“ my_data”与该节点关联。您应该看到:

[zkshell: 9] create /zk_test my_data Created /zk_test

Issue another ls / command to see what the directory looks like:

发出另一个ls /命令以查看目录的情况:

[zkshell: 11] ls / [zookeeper, zk_test]

Notice that the zk_test directory has now been created.

Next, verify that the data was associated with the znode by running the get command, as in:

请注意,现在已创建zk_test目录。

接下来,通过运行get命令来验证数据是否与znode关联,如下所示:

[zkshell: 12] get /zk_test my_data cZxid = 5 ctime = Fri Jun 05 13:57:06 PDT 2009 mZxid = 5 mtime = Fri Jun 05 13:57:06 PDT 2009 pZxid = 5 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0 dataLength = 7 numChildren = 0

最后

如果觉得本文对你有帮助的话,不妨给我点个赞,关注一下吧!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

最后

如果觉得本文对你有帮助的话,不妨给我点个赞,关注一下吧!

[外链图片转存中…(img-R3CYUcOk-1713656791119)]

[外链图片转存中…(img-7Vqm0021-1713656791120)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注Java)
[外链图片转存中…(img-ww6GtplQ-1713656791120)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 20
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值