1. 程式人生 > >Zookeeper-3.4.13 win10 配置

Zookeeper-3.4.13 win10 配置

ZooKeeper 是什麼?

ZooKeeper是一個分散式的,開放原始碼的分散式應用程式協調服務,是Google的Chubby一個開源的實現,是Hadoop和Hbase的重要元件。它是一個為分散式應用提供一致性服務的軟體,提供的功能包括:配置維護、域名服務、分散式同步、組服務等。
ZooKeeper的目標就是封裝好複雜易出錯的關鍵服務,將簡單易用的介面和效能高效、功能穩定的系統提供給使用者。
ZooKeeper包含一個簡單的原語集,提供Java和C的介面。
ZooKeeper程式碼版本中,提供了分散式獨享鎖、選舉、佇列的介面,程式碼在zookeeper-3.4.8\src\recipes。其中分佈鎖和佇列有Java和C兩個版本,選舉只有Java版本。

ZooKeeper 下載地址
link

解壓到E:\zookeeper-3.4.13\zookeeper-3.4.13
修改配置檔案
複製zoo_sample.cfg 檔名(E:\zookeeper-3.4.13\zookeeper-3.4.13\conf) 為 zoo.cfg
主要修改一下日誌位置,具體配置檔案如下:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=E:\\zookeeper\\data
dataLogDir=E:\\zookeeper\\log
# the port at which the clients will connect
clientPort=2181
# 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

配置檔案簡單解析
1、tickTime:這個時間是作為 Zookeeper 伺服器之間或客戶端與伺服器之間維持心跳的時間間隔,也就是每個 tickTime 時間就會發送一個心跳。
2、dataDir:顧名思義就是 Zookeeper 儲存資料的目錄,預設情況下,Zookeeper 將寫資料的日誌檔案也儲存在這個目錄裡。
3、dataLogDir:顧名思義就是 Zookeeper 儲存日誌檔案的目錄
4、clientPort:這個埠就是客戶端連線 Zookeeper 伺服器的埠,Zookeeper 會監聽這個埠,接受客戶端的訪問請求。

開啟powershell 檢視一下zookeeper的整體目錄

PS E:\> cd .\zookeeper-3.4.13\
PS E:\zookeeper-3.4.13> ls


    目錄: E:\zookeeper-3.4.13


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2018/11/22      7:14                zookeeper-3.4.13


PS E:\zookeeper-3.4.13> cd .\zookeeper-3.4.13\
PS E:\zookeeper-3.4.13\zookeeper-3.4.13> ls


    目錄: E:\zookeeper-3.4.13\zookeeper-3.4.13


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2018/11/22      7:14                bin
d-----       2018/11/22      7:20                conf
d-----       2018/11/22      7:14                contrib
d-----       2018/11/22      7:14                dist-maven
d-----       2018/11/22      7:14                docs
d-----       2018/11/22      7:14                lib
d-----       2018/11/22      7:14                recipes
d-----       2018/11/22      7:14                src
-a----        2018/6/30      1:04          91400 build.xml
-a----        2018/6/30      1:04           8502 ivy.xml
-a----        2018/6/30      1:04           1709 ivysettings.xml
-a----        2018/6/30      1:04          11938 LICENSE.txt
-a----        2018/6/30      1:04           3132 NOTICE.txt
-a----        2018/6/30      1:04           1585 README.md
-a----        2018/6/30      1:04           1770 README_packaging.txt
-a----        2018/6/30      1:05        1508639 zookeeper-3.4.13.jar
-a----         2018/7/1      7:36            833 zookeeper-3.4.13.jar.asc
-a----        2018/6/30      1:05             33 zookeeper-3.4.13.jar.md5
-a----        2018/6/30      1:05             41 zookeeper-3.4.13.jar.sha1

簡單介紹連個目錄:
bin:可執行指令碼
conf:配置檔案(剛才已經在conf做了一個簡單的配置)
如何啟動zookeeper呢?
執行指令碼需要進入bin

PS E:\zookeeper-3.4.13\zookeeper-3.4.13> cd bin
PS E:\zookeeper-3.4.13\zookeeper-3.4.13\bin> ls


    目錄: E:\zookeeper-3.4.13\zookeeper-3.4.13\bin


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2018/6/30      1:04            232 README.txt
-a----        2018/6/30      1:04           1937 zkCleanup.sh
-a----        2018/6/30      1:04           1056 zkCli.cmd
-a----        2018/6/30      1:04           1534 zkCli.sh
-a----        2018/6/30      1:04           1759 zkEnv.cmd
-a----        2018/6/30      1:04           2696 zkEnv.sh
-a----        2018/6/30      1:04           1089 zkServer.cmd
-a----        2018/6/30      1:04           6773 zkServer.sh
-a----        2018/6/30      1:04            996 zkTxnLogToolkit.cmd
-a----        2018/6/30      1:04           1385 zkTxnLogToolkit.sh

可以看到在bin的下面既有sh,又有cmd,說明zookeeper支援linux和win兩類系統
啟動一下試試:

PS E:\zookeeper-3.4.13\zookeeper-3.4.13\bin> .\zkServer.cmd

使用zkCli.cmd 客戶端連線zookeeper報錯

PS E:\zookeeper-3.4.13\zookeeper-3.4.13\bin> .\zkCli.cmd 127.0.0.0.1:2181

server error

2018-11-22 07:31:21,668 [myid:] - INFO  [main:[email protected]] - binding to port 0.0.0.0/0.0.0.0:2181
2018-11-22 07:34:55,487 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - Accepted socket connection from /127.0.0.1:54509
2018-11-22 07:34:55,533 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - Client attempting to establish new session at /127.0.0.1:54509
2018-11-22 07:34:55,535 [myid:] - INFO  [SyncThread:0:[email protected]] - Creating new log file: log.1
2018-11-22 07:34:55,629 [myid:] - INFO  [SyncThread:0:[email protected]] - Established session 0x100020bd4340000 with negotiated timeout 30000 for client /127.0.0.1:54509
2018-11-22 07:34:55,643 [myid:] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - Exception causing close of session 0x100020bd4340000: 遠端主機強迫關閉了一個現有的連線。
2018-11-22 07:34:55,644 [myid:] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:[email protected]] - Closed socket connection for client /127.0.0.1:54509 which had sessionid 0x100020bd4340000
2018-11-22 07:35:26,053 [myid:] - INFO  [SessionTracker:[email protected]] - Expiring session 0x100020bd4340000, timeout of 30000ms exceeded
2018-11-22 07:35:26,055 [myid:] - INFO  [ProcessThread(sid:0 cport:2181)::[email protected]] - Processed session termination for sessionid: 0x100020bd4340000

解決辦法:
1、換低版本
2、此版本沒有找到很好的解決方案。。。待續
另一種方法:

PS E:\zookeeper-3.4.13\zookeeper-3.4.13\bin> jps -l -v
17828 sun.tools.jps.Jps -Dapplication.home=C:\Program Files\Java\jdk1.8.0_161 -Xms8m
25004 org.apache.zookeeper.server.quorum.QuorumPeerMain -Dzookeeper.log.dir=E:\zookeeper-3.4.13\zookeeper-3.4.13\bin\.. -Dzookeeper.root.logger=INFO,CONSOLE

可以看到QuorumPeerMain的程序

參照地址

參照地址

參照地址