一、準備工作
1.三台伺服器:master、slave1、slave2
2.三台伺服器安裝了java環境
3.在官網下載下傳zookeeper-3.4.10.tar.gz
二、安裝zookeeper叢集
1.分别修改三台伺服器的hosts檔案:
[[email protected] ~]# vim /etc/hosts
添加如下内容:
192.168.100.1 master
192.168.100.2 slave1
192.168.100.3 slave2
儲存退出,并重新開機三台伺服器。
2.解壓zookeeper
[[email protected] ~]# tar -zxvf zookeeper-3.4.10.tar.gz -C /home
3.修改相應配置
①進入解壓後的檔案夾下,并建立data和logs兩個檔案夾
[[email protected] ~]# cd /home/zookeeper-3.4.10
[[email protected] zookeeper-3.4.10]# mkdir data
[[email protected] zookeeper-3.4.10]# mkdir logs
②進入conf目錄下,将zoo_sample.cfg複制并重命名為zoo.cfg
[[email protected] zookeeper-3.4.10]# cd conf
[[email protected] conf]# cp zoo_sample.cfg zoo.cfg
③修改zoo.cfg檔案配置
[[email protected] conf]# vim 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=/home/zookeeper-3.4.10/data
dataLogDir=/home/zookeeper-3.4.10/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
server.0=master:2888:3888
server.1=slave1:2888:3888
server.2=slave2:2888:3888
④建立myid檔案并修改
進入剛剛建立的data檔案夾下,建立myid檔案,并添加内容
[[email protected] conf]# cd /home/zookeeper-3.4.10/data
[[email protected] conf]# vim myid
添加如下内容:
4.在另外兩台機器上也同樣進行1、2、3的步驟,但是每個機器上myid的内容必須不一樣。我的設定為:master的myid為0;slave1的myid為1;slave2的myid為2。
5.修改profile檔案
[[email protected] conf]# vim /etc/profile
添加如下内容:
#zookeeper
export ZK_HOME=/home/zookeeper-3.4.10
export PATH=$ZK_HOME/bin:$PATH
使修改生效:
[[email protected] conf]# source /etc/profile
6.啟動zookeeper以及檢視狀态
進入到zookeeper的bin目錄下
啟動(需要在三個節點分别啟動):
[[email protected] bin]# ./zkServer.sh start
檢視狀态:
[[email protected] bin]# ./zkServer.sh status