本文記錄了我安裝zookeeper的方法,最後運行了一個單機的實例驗證安裝。html
因爲zookeeper
採用Java
編寫的,因此咱們須要Java
環境才能運行 此處咱們採用open-jdk-8
直接一行命令便可安裝apache
$ sudo apt-get install openjdk-8-jre
複製代碼
打開zookeeper官網,能夠找到對應的下載地址: archive.apache.org/dist/zookee…vim
使用wget下載:bash
$ wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz
複製代碼
下載下來的文件是壓縮文件,所以,咱們須要解壓ide
$ tar -xvf zookeeper-3.4.13.tar.gz
複製代碼
安裝目錄能夠爲任意,此處咱們安裝在/usr/local/zookeeper/
下,所以,將剛纔下載解壓完成的文件夾移動到/usr/local/zookeeper/
測試
$ mv zookeeper-3.4.13 /usr/local/zookeeper/zookeeper-3.4.13
複製代碼
爲了方便之後zookeeper
的版本更新,咱們安裝zookeeper
的時候能夠在同級目錄下建立一個不帶版本號的軟連接,而後將其指向帶zookeeper的真正目錄ui
即建立一個名爲/usr/local/zookeeper/apache-zookeeper
的軟連接,指向/usr/local/zookeeper/zookeeper-3.4.13
,之後更新版本的話,只須要修改軟連接的指向,而咱們配置的環境變量都不須要作任何更改this
$ ln -s /usr/local/zookeeper/zookeeper-3.4.13 /usr/local/zookeeper/apache-zookeeper
複製代碼
將zookeeper添加到環境變量spa
$ vim /etc/profile
複製代碼
新增下面兩行命令行
# 此處使用剛剛建立的軟連接
export ZK_HOME=/usr/local/zookeeper/apache-zookeeper
export PATH=$ZK_HOME/bin:$PATH
複製代碼
讓剛纔修改的path生效
$ source /etc/profile
複製代碼
此時,zookeeper的安裝完成,啓動一個單機版的測試一下
zookeeper啓動時候,會讀取conf
文件夾下的zoo.cfg
做爲配置文件,所以,咱們能夠將源碼提供的示例配置文件複製一個,作一些修改
# 進入配置文件目錄
$ cd /usr/local/zookeeper/apache-zookeeper/conf
# 複製示例配置文件
cp zoo_sample.cfg zoo.cfg
# 修改 zoo.cfg 配置文件
vim zoo.cfg
複製代碼
修改數據存放位置 dataDir=/usr/local/zookeeper/data
# 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.
# 只須要修改此處爲zookeeper數據存放位置
dataDir=/usr/local/zookeeper/data
# 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
複製代碼
進入bin目錄,執行運行命令(因爲剛纔設置了zookeeper
到環境變量PATH
裏面,因此,咱們其實能夠在任何目錄下執行下面的命令)
# 進入bin目錄
$ cd /usr/local/zookeeper/apache-zookeeper/bin
# 執行啓動命令
$ ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
# 查看狀態
$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper/bin/../conf/zoo.cfg
Mode: standalone
複製代碼
看到命令行輸出運行成功,表明運行成功