天天看點

安裝ZooKeeper的一些記錄

主要安裝過程時按照網上大部分部落格中的方法:

  1. 安裝jdk
  2. 下載下傳zookeeper的程式包,解壓到任意可以用的目錄,假設為

    /usr/zk

  3. 設定環境變量

    ZOOKEEPER_HOME=/usr/zk/zookeeper.x.x.x.

    ,并将

    $ZOOKEEPER_HOME/bin

    $ZOOKEEPER_HOME/conf

    添加到PATH中
  4. 配置檔案

    示例檔案為/usr/zk/zookeeper.x.x.x/conf/zoo_sample.cfg,将其名稱更改為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=/tmp/zookeeper
# 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
server.1 = 192.168.30.184:2888:3888
server.2 = 192.168.30.190:2888:3888
server.3 = 192.168.30.191:2888:3888
server.4 = 192.168.30.192:2888:3888
server.5 = 192.168.30.193:2888:3888
           
  1. 上面配置檔案中的

    dataDir=/tmp/zookeeper

    ,是以要建立這個檔案夾
  2. zookeeper啟動時,需要用到myid檔案指定節點id,這個myid檔案需要自己建立放在在dataDir目錄下,内容就為server.1對應的1、2、3、4、5…,視節點而定
  3. 啟動各個節點的zookeeper服務程式,如果啟動出錯,在目前目錄中檢視zookeeper.out日志檔案。

遇到l了問題

zookeeper.out檔案中就一句 command ‘java’ cannot found,

說明java環境沒有配置好,但是運作

java -version

可以正常輸出版本号

原因:啟動時加了sudo導緻的。

sudo zkServer.sh start

,加了sudo會導緻環境改變,驗證如下:

[email protected]:/opt/zookeeper-3.4.9/bin$ sudo java -version
sudo: java: command not found
[email protected]:/opt/zookeeper-3.4.9/bin$ 
           

其他的沒什麼問題。防火牆時已經關閉的。

啟動後,可以看一下jps:

[email protected]:/opt/zookeeper-3.4.9/bin$ jps
6421 Jps
6269 QuorumPeerMain
[email protected]:/opt/zookeeper-3.4.9/bin$ 
           

各節點都啟動之後,通過status指令檢視狀态:

[email protected]:/opt/zookeeper-3.4.9/bin$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: leader
[email protected]:/opt/zookeeper-3.4.9/bin$ 
           

繼續閱讀