Zookeeper簡單安裝使用

zookeeper對外提供分佈式協調服務,我們的分佈式應用,通過zookeeper可以很輕鬆的實現協調調度

zookeeper經常組成集羣提供服務,如下圖所示,集羣內各主機之間互聯互通,通過選舉產生leader,即使有主機因意外宕機,剩餘的主機也能選舉出一臺作爲leader繼續對外提供服務

更多細節可以查看apach的官方描述

我們有時候自己本地調試服務需要zookeeper提供服務,但是有沒有太多資源使用,可以選擇安裝單機版zookeeper

準備工作:安裝Java環境,配置path

1.下載zookeeper安裝包,本次使用3.6.0版本,可以去官網下載自己需要的版本

wget https://downloads.apache.org/zookeeper/zookeeper-3.6.0/apache-zookeeper-3.6.0-bin.tar.gz

2.解壓tar包

tar -zxvf apache-zookeeper-3.6.0-bin.tar.gz 

3.進入解壓好的文件夾,並複製一份配置文件

cd /usr/local/zookeeper/apache-zookeeper-3.6.0/conf
cp zoo_sample.cfg zoo.cfg

4.編輯配置文件

vi coo.cfg

配置文件如下,修改dataDir和dataLogDir

其中dataDir裏需要創建一個myid文件,裏面配置的當前服務的id編號,本例子裏把myid設爲了2181

dataLogDir裏是日誌文件,如果缺少目錄文件夾及文件,請自己補全

# 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=/usr/local/zookeeper/apache-zookeeper-3.6.0/data
dataLogDir=/usr/local/zookeeper/apache-zookeeper-3.6.0/logs

# 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

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

5.啓動zookeeper

/usr/local/zookeeper/apache-zookeeper-3.6.0/bin/zkServer.sh start

啓動成功顯示如下

/usr/local/jdk1.8.0_251/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

6.如果報Java環境的錯誤就進入/usr/local/zookeeper/apache-zookeeper-3.6.0/bin文件夾修改啓動文件

在#!/usr/bin/env bash下添加jdk路徑,如果啓動不報錯可以不配置這項
 

#!/usr/bin/env bash
export=/usr/local/jdk1.8.0_251/bin:$PATH

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章