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

搭建Zookeeper叢集

一、環境要求

  • OS:Centos6.x
  • JDK: 1.8
  • 防火牆:關閉

二、下載Zookeeper

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

三、安裝並配置

1. 新建目錄

mkdir -p /data/zookeeper  
mkdir -p /data/log/zookeeper

2. 解壓zookeeper

tar -zxvf zookeeper-3.4.10.tar.gz

3. 修改配置

ln -s zookeeper-3.4.10 zookeeper 
cd zookeeper/conf/

3.1 修改配置

cp zoo_sample.cfg zoo.cfg
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=/data/zookeeper
dataLogDir=/data/log/zookeeper
# 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.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888

3.2 分發配置到其它機器

scp zoo.cfg [email protected]:~/zookeeper/conf/
scp zoo.cfg [email protected]:~/zookeeper/conf/

3.3 根據server.1server.2server.3的值,在這三臺機器上建立myid

touch /data/zookeeper/myid

在node1的機器上執行:

echo "1" > /data/zookeeper/myid 

在node2的機器上執行:

echo "2" > /data/zookeeper/myid 

在node3的機器上執行:

echo "3" > /data/zookeeper/myid 

執行完畢後,node1的myid值為1,node2的myid值為2,node3的myid值為3.

4. 啟動zookeeper

bin/zkServer.sh start

並且檢視狀態

bin/zkServer.sh status