玩家將零售版英特爾 12 代酷睿 i9-12900K 全效能核心超頻到 5.2GHz
阿新 • • 發佈:2021-10-20
系統版本:CentOS Linux release 8.3.2011
JDK版本:1.8
Zookpeer版本:3.7.0
此次搭建的叢集為偽叢集,即在一臺機器上開3個例項。
-
下載安裝包
[root@i-h0xe1oiq tools]# wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
-
解壓安裝包
[root@i-h0xe1oiq tools]# tar xf apache-zookeeper-3.7.0-bin.tar.gz -C /application/
-
檢視解壓後的目錄
[root@i-h0xe1oiq apache-zookeeper-3.7.0-bin]# tree -L 1 . ├── bin ├── conf ├── docs ├── lib ├── LICENSE.txt ├── NOTICE.txt ├── README.md └── README_packaging.md 4 directories, 4 files
-
準備配置檔案,進入conf目錄,建立zoo.cfg檔案,內容可複製conf/zoo_sample.cfg。
[root@i-h0xe1oiq conf]# cp zoo_sample.cfg zoo.cfg
-
配置檔案說明
# The number of milliseconds of each tick tickTime=2000 # CS通訊心跳數,Zookeeper 伺服器之間或客戶端與伺服器之間維持心跳的時間間隔,也就是每個 tickTime 時間就會發送一個心跳。tickTime以毫秒為單位。 # The number of ticks that the initial # synchronization phase can take initLimit=10 # LF初始通訊時限,叢集中的follower伺服器(F)與leader伺服器(L)之間初始連線時能容忍的最多心跳數(tickTime的數量)。 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # LF同步通訊時限,叢集中的follower伺服器與leader伺服器之間請求和應答之間能容忍的最多心跳數(tickTime的數量)。 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/tmp/zookeeper # 資料檔案目錄,Zookeeper儲存資料的目錄,預設情況下,Zookeeper將寫資料的日誌檔案也儲存在這個目錄裡。 # the port at which the clients will connect clientPort=2181 # 客戶端連線埠,客戶端連線 Zookeeper 伺服器的埠,Zookeeper 會監聽這個埠,接受客戶端的訪問請求。 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 ## Metrics Providers # # https://prometheus.io Metrics Exporter #metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider #metricsProvider.httpPort=7000 #metricsProvider.exportJvmInfo=true # 伺服器名稱與地址:叢集資訊(伺服器編號,伺服器地址,LF通訊埠,選舉埠) # 這個配置項的書寫格式比較特殊,規則如下: # server.N=YYY:A:B # 其中N表示伺服器編號,YYY表示伺服器的IP地址,A為LF通訊埠,表示該伺服器與叢集中的leader交換的資訊的埠。B為選舉埠,表示選舉新leader時伺服器間相互通訊的埠(當leader掛掉時,其餘伺服器會相互通訊,選擇出新的leader)。一般來說,叢集中每個伺服器的A埠都是一樣,每個伺服器的B埠也是一樣。但是當所採用的為偽叢集時,IP地址都一樣,只能時A埠和B埠不一樣。
-
偽叢集準備三份zookeeper例項
[root@i-h0xe1oiq application]# ll -h total 12K drwxr-xr-x 17 cloud-user cloud-user 4.0K Mar 17 2021 apache-zookeeper-3.7.0-2181 drwxr-xr-x 17 root root 4.0K Oct 25 14:54 apache-zookeeper-3.7.0-2182 drwxr-xr-x 17 root root 4.0K Oct 25 14:54 apache-zookeeper-3.7.0-2183
-
各例項配置檔案
# 例項1 tickTime=2000 initLimit=10 syncLimit=5 dataDir=/application/apache-zookeeper-3.7.0-2181/data clientPort=2181 server.1=127.0.0.1:12888:13888 server.2=127.0.0.1:14888:15888 server.3=127.0.0.1:16888:17888 # 例項2 tickTime=2000 initLimit=10 syncLimit=5 dataDir=/application/apache-zookeeper-3.7.0-2182/data clientPort=2182 server.1=127.0.0.1:12888:13888 server.2=127.0.0.1:14888:15888 server.3=127.0.0.1:16888:17888 # 例項3 tickTime=2000 initLimit=10 syncLimit=5 dataDir=/application/apache-zookeeper-3.7.0-2183/data clientPort=2183 server.1=127.0.0.1:12888:13888 server.2=127.0.0.1:14888:15888 server.3=127.0.0.1:16888:17888
-
配置例項ID以區分
# 例項1 [root@i-h0xe1oiq application]# mkdir -p apache-zookeeper-3.7.0-2181/data/ && echo 1 > apache-zookeeper-3.7.0-2181/data/myid # 例項2 [root@i-h0xe1oiq application]# mkdir -p apache-zookeeper-3.7.0-2182/data/ && echo 2 > apache-zookeeper-3.7.0-2182/data/myid # 例項3 [root@i-h0xe1oiq application]# mkdir -p apache-zookeeper-3.7.0-2183/data/ && echo 3 > apache-zookeeper-3.7.0-2183/data/myid
-
啟動節點
[root@i-h0xe1oiq application]# ./apache-zookeeper-3.7.0-2181/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /application/apache-zookeeper-3.7.0-2181/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@i-h0xe1oiq application]# ./apache-zookeeper-3.7.0-2182/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /application/apache-zookeeper-3.7.0-2182/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@i-h0xe1oiq application]# ./apache-zookeeper-3.7.0-2183/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /application/apache-zookeeper-3.7.0-2183/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
-
檢視節點狀態
[root@i-h0xe1oiq application]# ./apache-zookeeper-3.7.0-2181/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /application/apache-zookeeper-3.7.0-2181/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Client SSL: false. Mode: follower [root@i-h0xe1oiq application]# ./apache-zookeeper-3.7.0-2182/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /application/apache-zookeeper-3.7.0-2182/bin/../conf/zoo.cfg Client port found: 2182. Client address: localhost. Client SSL: false. Mode: leader [root@i-h0xe1oiq application]# ./apache-zookeeper-3.7.0-2183/bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /application/apache-zookeeper-3.7.0-2183/bin/../conf/zoo.cfg Client port found: 2183. Client address: localhost. Client SSL: false. Mode: follower