ZooKeeper 3.6.X 配置參考

来源:https://www.cnblogs.com/mylibs/archive/2022/12/15/zookeeper-r363-getting-started-guide.html
-Advertisement-
Play Games

“好記性不如爛筆頭。” —— 張溥 0x00 大綱 0x01 前言 部分內容翻譯自 ZooKeeper 3.6 Documentation,文末附原文章節,可對照理解。 0x02 獨立運行 在獨立模式下設置 ZooKeeper 服務很簡單。服務包含在單個 JAR 文件中,因此安裝包括創建配置。 下載 ...


“好記性不如爛筆頭。” —— 張溥

0x00 大綱

目錄

0x01 前言

部分內容翻譯自 ZooKeeper 3.6 Documentation,文末附原文章節,可對照理解。

0x02 獨立運行

在獨立模式下設置 ZooKeeper 服務很簡單。服務包含在單個 JAR 文件中,因此安裝包括創建配置。

下載穩定的 ZooKeeper 版本後,將其解壓縮並 CD 到根目錄。

要啟動 ZooKeeper,您需要一個配置文件。這是一個示例,在 conf/zoo.cfg 中創建如下配置:

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

這個文件名字可以隨便取,但為了方便這個討論,把它叫做 conf/zoo.cfg。更改 dataDir 的值以指定一個存在的目錄(初始值為空)。以下是每個欄位的含義:

  • tickTime:ZooKeeper 使用的基本時間單位(以毫秒為單位)。它用於執行心跳檢測,最小會話超時時間將是 tickTime 的兩倍。

  • dataDir:存儲記憶體中資料庫快照的位置,除非另有指定,否則事務日誌也將更新到資料庫中。

  • clientPort:偵聽客戶端連接的埠。

現在你已經創建了配置文件,你可以啟動 ZooKeeper:

bin/zkServer.sh start

(如果是 Windows 版本,則執行)

bin/zkServer.cmd

ZooKeeper 使用 log4j 記錄消息 - 更多詳細信息可在程式員指南的日誌記錄部分找到。您將看到輸出到控制台的日誌消息(預設)和/或日誌文件,具體取決於 log4j 配置。

此處概述的步驟在獨立模式下運行 ZooKeeper。沒有複製(集群),因此如果 ZooKeeper 進程出錯,服務將關閉。這對於大多數開發情況來說都很好,但是要在複製模式下運行 ZooKeeper,請參閱運行複製的 ZooKeeper。

0x03 集群運行

在獨立模式下運行 ZooKeeper 便於評估、開發和測試。但在生產環境中,您應該在複製(集群)模式下運行 ZooKeeper。同一應用程式中的複製伺服器組稱為 quorum ,在複製模式下, quorum 中的所有伺服器都具有同一配置文件的副本。

註意

對於複製模式,至少需要三台伺服器,強烈建議您擁有奇數台伺服器。如果只有兩台伺服器,則如果其中一臺伺服器發生故障,則沒有足夠的電腦來形成多數仲裁。兩台伺服器本質上不如一臺伺服器穩定,因為存在兩個單點故障。

複製模式所需的 conf/zoo.cfg 文件與獨立模式下使用的配置文件類似,但有一些不同之處。下麵是一個示例:

tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888

新配置選項 initLimit 是 ZooKeeper 用來限制仲裁中的 ZooKeeper 伺服器必須連接到領導者的時長。配置選項 syncLimit 限制伺服器與領導者之間的超時時間。

對於這兩個超時,您可以使用 tickTime 指定時間單位。在此示例中,initLimit 的超時為 5 個時鐘周期,每個時鐘周期 2000 毫秒,即 10 秒。

伺服器配置 server.X 列出了組成 ZooKeeper 服務的伺服器。當伺服器啟動時,它通過在數據目錄中查找文件 myid 來知道它是哪個伺服器。該文件包含伺服器編號(ASCII字元集)。

最後,記下每個伺服器名稱後面的兩個埠號:“2888”和“3888”。各個節點使用這兩個埠連接到其他節點。這種連接是必要的,以便節點之間可以進行通信,例如,就更新順序達成一致。更具體地說,ZooKeeper 伺服器使用此埠將從者連接到領導。當出現新的領導時,從者使用此埠打開與領導的 TCP 連接。由於預設領導選舉也使用 TCP,因此我們目前需要另一個埠進行領導選舉。這是伺服器配置中的第二個埠。

註意

如果要在一臺電腦上測試多個伺服器,請將伺服器名稱指定為 localhost 並分配不同的埠(例如 2888:3888、2889:3889、2890:3890)。當然,單獨的 _dataDir_s 和不同的 _clientPort_s 也是必要的(在上述的複製示例中,在單個主機上運行,您將有三個不同的配置文件)。

請註意,在一臺電腦上設置多個服務不會產生任何冗餘。如果機器發生故障,所有 zookeeper 服務都將離線。完全冗餘要求每個服務都有自己的主機,它必須是完全獨立的物理伺服器。同一物理主機上的多個虛擬機仍然容易受到該宿主機故障的影響。

如果您的 ZooKeeper 電腦中有多個網路介面,您還可以指示 ZooKeeper 綁定所有介面,併在發生網路故障時自動切換到正常運行的介面。有關詳細信息,請參閱配置參數。

0x04 單機集群配置補充

將解壓後的 zookeeper 包複製三份,可分別重命名為 server1、server2、server3。

在 server1/conf/zoo.cfg 中創建如下配置:

tickTime=2000
dataDir=/server1/data
clientPort=2181
initLimit=5
syncLimit=2
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

在 server2/conf/zoo.cfg 中創建如下配置:

tickTime=2000
dataDir=/server2/data
clientPort=2182
initLimit=5
syncLimit=2
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

在 server3/conf/zoo.cfg 中創建如下配置:

tickTime=2000
dataDir=/server3/data
clientPort=2183
initLimit=5
syncLimit=2
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

在 /server1/data 中創建 myid 文件(沒有尾碼),文件內容為數字 1;

在 /server2/data 中創建 myid 文件(沒有尾碼),文件內容為數字 2;

在 /server3/data 中創建 myid 文件(沒有尾碼),文件內容為數字 3;

依次啟動三個 ZooKeeper 服務。

0x05 官方原文

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:

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:

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.

Running Replicated ZooKeeper

Running ZooKeeper in standalone mode is convenient for evaluation, some development, and testing. But in production, you should run ZooKeeper in replicated mode. A replicated group of servers in the same application is called a quorum, and in replicated mode, all servers in the quorum have copies of the same configuration file.

Note

For replicated mode, a minimum of three servers are required, and it is strongly recommended that you have an odd number of servers. If you only have two servers, then you are in a situation where if one of them fails, there are not enough machines to form a majority quorum. Two servers are inherently less stable than a single server, because there are two single points of failure.

The required conf/zoo.cfg file for replicated mode is similar to the one used in standalone mode, but with a few differences. Here is an example:

tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888

The new entry, initLimit is timeouts ZooKeeper uses to limit the length of time the ZooKeeper servers in quorum have to connect to a leader. The entry syncLimit limits how far out of date a server can be from a leader.

With both of these timeouts, you specify the unit of time using tickTime. In this example, the timeout for initLimit is 5 ticks at 2000 milliseconds a tick, or 10 seconds.

The entries of the form server.X list the servers that make up the ZooKeeper service. When the server starts up, it knows which server it is by looking for the file myid in the data directory. That file has the contains the server number, in ASCII.

Finally, note the two port numbers after each server name: " 2888" and "3888". Peers use the former port to connect to other peers. Such a connection is necessary so that peers can communicate, for example, to agree upon the order of updates. More specifically, a ZooKeeper server uses this port to connect followers to the leader. When a new leader arises, a follower opens a TCP connection to the leader using this port. Because the default leader election also uses TCP, we currently require another port for leader election. This is the second port in the server entry.

Note

If you want to test multiple servers on a single machine, specify the servername as localhost with unique quorum & leader election ports (i.e. 2888:3888, 2889:3889, 2890:3890 in the example above) for each server.X in that server's config file. Of course separate _dataDir_s and distinct _clientPort_s are also necessary (in the above replicated example, running on a single localhost, you would still have three config files).

Please be aware that setting up multiple servers on a single machine will not create any redundancy. If something were to happen which caused the machine to die, all of the zookeeper servers would be offline. Full redundancy requires that each server have its own machine. It must be a completely separate physical server. Multiple virtual machines on the same physical host are still vulnerable to the complete failure of that host.

If you have multiple network interfaces in your ZooKeeper machines, you can also instruct ZooKeeper to bind on all of your interfaces and automatically switch to a healthy interface in case of a network failure. For details, see the Configuration Parameters.


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • LVS 負載均衡 本篇主要介紹一下 lvs 是什麼 以及它的 nat 模式的搭建 配合nginx來演示 1.概述 LVS 是 Linux Virtual Server 的簡寫 (Linux 虛擬伺服器 ), 是由章文嵩博士主導, 它虛擬出一個伺服器集群,然後進行負載均衡的項目, 目前LVS 已經被集 ...
  • Linux常用命令 1、 關機/重啟/註銷 | 常用命令 | 作用 | | | | | shutdown -h now | 即刻關機 | | shutdown -h 10 | 10分鐘後關機 | | shutdown -h 11:00 | 11:00關機 | | shutdown -h +10 | ...
  • 最近在複習以前學習的python爬蟲內容,就拿微博來練了一下手,這個案例適合學習爬蟲到中後期的小伙伴,因為他不是特別簡單也不是很難,關鍵是思路,為什麼說不是很難呢?因為還沒涉及到js逆向,好了話不多說開乾。 (1)找到要爬取的頁面,如下: (2)點開評論,拉到最下方,如下位置: 點擊“點擊查看”進入 ...
  • 來源:developer.aliyun.com/article/889271 本文準備圍繞七個點來講網關,分別是網關的基本概念、網關設計思路、網關設計重點、流量網關、業務網關、常見網關對比,對基礎概念熟悉的朋友可以根據目錄查看自己感興趣的部分。 什麼是網關 網關,很多地方將網關比如成門, 沒什麼問題 ...
  • 無論是要交給程式處理的數據,還是控制腳本的簡單命令,都少不了輸入和輸出。程式要做的第一件事就是處理如同一陰一陽的“輸入與輸出”。 1 、從文件獲取輸入 當我們希望向文件輸出內容時,我們可以通過符號 > 或 >> 實現。而用代表輸入重定向的符號 < 可以從文件中讀取數據,如下: $ wc < my.f ...
  • 作者:張富春(ahfuzhang),轉載時請註明作者和引用鏈接,謝謝! cnblogs博客 zhihu Github 公眾號:一本正經的瞎扯 我在多進程插件框架 hashicorp/go-plugin 的基礎上,使用 protoreflect 來解析 proto3 語法的IDL文件,通過命令行工具自 ...
  • 解決問題 在SpringBoot項目中,如何集成Karate測試框架和Jacoco插件。以及編寫了feature測試文件,怎麼樣配置才能看到被測試介面代碼的覆蓋率。 演示版本及說明 本次講解,基於SpringBoot2.1.4.RELEASE版本,可根據項目版本靈活更改。下麵所有的版本號,可以自行選 ...
  • 查找 假設有如下這樣一個有序鏈表: 想要查找 24、43、59,按照順序遍歷,分別需要比較的次數為 2、4、6 目前查找的時間複雜度是 O(N),如何提高查找效率? 很容易想到二分查找,將查找的時間複雜度降到 O(LogN) 具體來說,我們把鏈表中的一些節點提取出來,作為索引,類似於二叉搜索樹,得到 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...