1. 程式人生 > >Zookeeper叢集的搭建

Zookeeper叢集的搭建

1.先安裝 lzrsz

yum install -y lzrsz

接著就可以直接使用 rz 命令將zookeeper的壓縮包上傳到伺服器了

2.解決zookeeper的安裝包 在 ~ 目錄下

tar -zxvf zookeeper-3.4.5.tar.gz -C ./apps/

看解壓的檔案 (練習的時候使用的zookeeper是包含了原始碼) 為了複製時速度快一點,所以應該把不影響的檔案都刪除掉 在這裡插入圖片描述

  1. rm -rf src/ *.xml *.txt
  2. rm -rf docs dist-maven/

3.修改配置檔案: 在這裡插入圖片描述 這個zoo_sample.cfg是不生效的,需要改一個名字

cp zoo_sample.cfg zoo.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
#
# 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

需要修改的地方:

  1. dataDir 是zookeeper資料存放的目錄,不能放在臨時目錄裡面,

在這裡插入圖片描述

2.配置zookeeper服務的機器: 在這裡插入圖片描述

server.1=bd1:2888:3888 
server.2=bd2:2888:3888
server.3=bd3:2888:3888

zookeeper叢集的伺服器個數是 奇數個數

埠: 2888 是叢集的leader跟flower之間通訊的埠 3888 是投票的時候互相通訊的埠 配置完上面之後,還需要再dataDir這個目錄裡面配置myid 在 root目錄下新建資料夾 zkdata 在zkdata目錄下面:

echo 1 > myid

在這裡插入圖片描述

上面的步驟是在一臺機器上配置好了zookeeper,現在需要在另外的兩臺機器上面進行同樣的配置 可以直接使用scp進行復制 複製 apps

scp -r apps/ [email protected]:/root

scp -r apps/ [email protected]:/root

然後分別在bd2根bd3機器上新建zkdata,然後寫上myid 在這裡插入圖片描述

啟動叢集: 在這裡插入圖片描述

檢視狀態: 在這裡插入圖片描述

這樣的話,三臺機器是同時啟動的: bd1: 在這裡插入圖片描述

bd2: 在這裡插入圖片描述

bd3: 在這裡插入圖片描述