1. 程式人生 > >Ubuntu安裝ZooKeeper

Ubuntu安裝ZooKeeper

系統環境

  • Ubuntu 16.04 LTS
  • zookeeper-3.5.2-alpha.tar.gz

安裝步驟

1.下載ZooKeeper tar包並解壓

tar -zxvf zookeeper-3.5.2-alpha.tar.gz

2.進入解壓後文件夾下的conf目錄(/opt/apps/zookeeper/zookeeper-3.5.2-alpha/conf),複製一份zoo_sample.cfg重新命名為zoo.cfg

3.編輯zoo.cfg,修改以下配置

# 建立資料儲存目錄和日誌檔案目錄(目錄需要自己建立)
dataDir=/opt/apps/zookeeper/zookeeper
-3.5.2-alpha/data dataLogDir=/opt/apps/zookeeper/zookeeper-3.5.2-alpha/logs #設定server地址(hostname為本伺服器地址;第一個埠用於集合體中follower以偵聽leader;第二個埠用於leader選舉) server.1=172.19.76.133:2888:3888

完整配置檔案如下

# 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=/opt/apps/zookeeper/zookeeper-3.5.2-alpha/data dataLogDir=/opt/apps/zookeeper/zookeeper-3.5
.2-alpha/logs # the port at which the clients will connect clientPort=2181 server.1=172.19.76.133:2888:3888 # 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

4.在上一步建立的data目錄下建立mydata檔案,填入伺服器配置後面的數字,這裡為1,給伺服器進行編號

5.啟動ZooKeeper服務端

./zkServer.sh start
root@iZuf69wuhmgaijvje9a369Z:/opt/apps/zookeeper/zookeeper-3.5.2-alpha/bin# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/apps/zookeeper/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

注意:請勿使用sh zkServer.sh start來啟動zkServer,會出現無法找到JAVA_HOME環境變數錯誤
zk啟動異常

6.檢視zkServer狀態

./zkServer.sh status
root@VM-0-15-ubuntu:/opt/apps/zookeeper/zookeeper-3.5.2-alpha/bin# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/apps/zookeeper/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone