1. 要在單機下搭建群集,簡單的就是分別解壓複製N個目錄。
2. 每個目錄,分配配置對應的data 和 myid ,其中myid 用來表明當前啟動是哪個zookeeper
3. 設定檔的群集屬性
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3883
server.3=127.0.0.1:2883:3883
server.4=127.0.0.1:2884:3884
server.5=127.0.0.1:2885:3885
4. (我被坑的地方)每個zookeeper 服務有三個連接埠,clientPort=2181,這個用於指明給用戶端應用串連的端
(例如java 程式訪問就是這個連接埠)
server.1=127.0.0.1:2881:3881 ,其中2881 用於群集間的伺服器進行資料通訊,3881 用於群集剛啟動時
或leader 當機時 進行選舉。
完整的設定檔(單機環境,5個執行個體的連接埠都要不一樣)
# 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=D:/data/zookeeper/server5/data
# the port at which the clients will connect
clientPort=2185
#
# 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
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3883
server.3=127.0.0.1:2883:3883
server.4=127.0.0.1:2884:3884
server.5=127.0.0.1:2885:3885
附上完整的設定檔 https://swtools.googlecode.com/git/linux/zookeeper/zookeeper.zip