1. 程式人生 > 實用技巧 >ZooKeeper安裝

ZooKeeper安裝

一、Zookeeper簡介與應用場景

  Zookeeper 是一個開源的分散式的,為分散式應用提供協調服務的 Apache 專案.提供的服務包括:統一命名服務、統一配置管理、統一叢集管理、伺服器節點動態上下線、軟負載均衡等.   Zookeeper的主要有單機、偽叢集、叢集三種部署方式.

  

二、官網下載Linux版本的Zookeeper,下載好的Zookeeper上傳到Linux系統上(上傳到 /opt下面,主要是放在這裡備份一下)

三、建立一個安裝目錄(我這裡想安裝在 /usr/local/zookeeper下面)

四、解壓

  1、切換到 /opt目錄下面,然後執行命令解壓

// 解壓檔案到 /usr/local/zookeeper目錄下
tar -zxvf zookeeper-3.4.14.tar.gz -C /usr/local/zookeeper

  2、解壓後的目錄結構如下

五、建立配置檔案

  1、建立一個zookeeper的配置檔案zoo.cfg,可複製conf/zoo_sample.cfg作為配置檔案

  2、zoo.cfg配置檔案簡介

# The number of milliseconds of each tick
# tickTime:客戶端與伺服器、伺服器與伺服器之間維持心跳的時間間隔,也就是每一個tickTime會發送一次心跳,單位為毫秒
#
tickTime=2000
#
# The number of ticks that the initial 
# synchronization phase can take
# initLimit:叢集中Leader和Follow初始化連線時最多能容忍的心跳數
# 也就是初始化過程中,如果Leader和Follow在 (10*tickTime)的時間內還沒有連線上,則認為連線失敗
initLimit=10
#
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
# syncLimit:同步通訊實現,Leader和Follow伺服器之間傳送請求和接收應答最多能容忍的心跳數
# 也就是Leader和Follow如果傳送的請求在 (5*tickTime)的時間沒沒有應答,那麼就認為Leader和Follow之間連線失敗
#
syncLimit=5
#
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
# dataDir:zookeeper儲存日誌檔案的目錄
#
dataDir=/tmp/zookeeper
#
# the port at which the clients will connect
# clientPort:客戶端連線zookeeper伺服器的埠,zookeeper會監控這個埠
#
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.伺服器編號=伺服器的IP地址:LF通訊埠:選舉埠
# server.N=YYY:A:B
# N:伺服器編號,每一臺伺服器的編號都是唯一的
# YYY:伺服器的IP地址
# A:LF通訊的埠,伺服器與zookeeper叢集中Leader交換資訊的埠
# B:選舉埠,叢集中每一臺伺服器的A埠都是一樣的,叢集中的每一臺伺服器的B埠也是一樣的
# 但是當採用偽叢集的時候,由於IP地址都是一樣的,只能是A埠和B埠不一樣.