主要安裝過程時按照網上大部分博客中的方法:
- 安裝jdk
- 下載zookeeper的程序包,解壓到任意可以用的目錄,假設爲
/usr/zk
下 - 設置環境變量
ZOOKEEPER_HOME=/usr/zk/zookeeper.x.x.x.
,並將$ZOOKEEPER_HOME/bin
和$ZOOKEEPER_HOME/conf
添加到PATH中 - 配置文件
示例文件爲/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
- 上面配置文件中的
dataDir=/tmp/zookeeper
,因此要創建這個文件夾 - zookeeper啓動時,需要用到myid文件指定節點id,這個myid文件需要自己創建放在在dataDir目錄下,內容就爲server.1對應的1、2、3、4、5…,視節點而定
- 啓動各個節點的zookeeper服務程序,如果啓動出錯,在當前目錄中查看zookeeper.out日誌文件。
#zkServer.sh start
遇到l了問題
zookeeper.out文件中就一句 command ‘java’ cannot found,
說明java環境沒有配置好,但是運行java -version
可以正常輸出版本號
原因:啓動時加了sudo導致的。
即sudo zkServer.sh start
,加了sudo會導致環境改變,驗證如下:
archlab@worker92:/opt/zookeeper-3.4.9/bin$ sudo java -version
sudo: java: command not found
archlab@worker92:/opt/zookeeper-3.4.9/bin$
其他的沒什麼問題。防火牆時已經關閉的。
啓動後,可以看一下jps:
archlab@worker92:/opt/zookeeper-3.4.9/bin$ jps
6421 Jps
6269 QuorumPeerMain
archlab@worker92:/opt/zookeeper-3.4.9/bin$
各節點都啓動之後,通過status命令查看狀態:
archlab@worker92:/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
archlab@worker92:/opt/zookeeper-3.4.9/bin$