每台机器的环境:CentOS 6.5,Java 1.8,安装zookeeper-3.4.5。
② 三台虚拟机,虚拟机1,cluster-2和luster-3的ip地址为:192.168.0.110,192.168.0.108,192.168.0.106。
先在虚拟机1上操作:
①下载zookeeper-3.4.5.tar.gz源代码,把源码包解压到/usr/local/路径下,并修改文件名称:
tar -xvzf zookeeper-3.4.5.tar.gz -C /usr/local/
cd /usr/local/
mv zookeeper-3.4.5.tar.gz zookeeper
②进入到zookeeper的conf目录下,将zoo_sample.cfg这个文件复制为zoo.cfg(必须是这个文件)
cd /usr/local/zookeeper/conf
cp zoo_sample.cfg zoo_sample1.cfg
mv zoo_sample.cfg zoo.cfg
③修改zoo.cfg文件内容:vim zoo.cfg
# 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/data #修改数据路径
dataLogDir=/usr/local/zookeeper/log
# 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
server.0=192.168.0.110:2888:3888 #修改三台机器zookeeper集群
server.1=192.168.0.108:2888:3888
server.2=192.168.0.106:2888:3888
④在zookeeper目录下建立个新文件夹data : mkdir data
⑤在data目录下新建文件myid,文件内容为0,与server.0相对应vim myid
⑥配置zookeeper环境变量:vim /etc/profile
在文件末尾加上
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$PATH
然后source /etc/profile文件
Kafka-cluster-2和Kafka-cluster-3操作以上6个步骤。
⑦Kafka-cluster-2虚拟机命令行输入:
vim /usr/local/zookeeper/data/myid 将里面的数字修改成1.
⑧Kafka-cluster-3虚拟机命令行输入:
vim /usr/local/zookeeper/data/myid 将里面的数字修改成2.
在每台虚拟机zookeeper目录命令行上输入:./bin/zkServer.sh start便可启动集群,可以使用指令:./bin/zkServer.sh status查看zookeeper状态。