安装部署zookeeper集群

实验说明:  三台虚拟机做zookeeper集群,集群个数最好是奇数个,原理详见zookeeper 详解

       安装zookeeper 请确保jdk 已安装好,否则无法启动

       三台虚拟机IP分别为:192.168.12.162  192.168.12.163  192.168.12.164

一、 ssh 登陆192.168.12.162 做如下操作:

1.1 下载解压zookeeper

 wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz -P /opt
tar xf /opt/zookeeper-3.4..tar.gz -C /usr/local/
mv /usr/local/zookeeper-3.4. /usr/local/zookeeper
mkdir -p /usr/local/zookeeper/zookeeper-data/logs
echo “”> /usr/local/zookeeper/zookeeper-data/myid
mv /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg

1.2 配置zookeeper集群

vim /usr/local/zookeeper/conf/zoo.cfg

tickTime=
initLimit=
syncLimit=
dataDir=/usr/local/zookeeper/zookeeper-data
dataLogDir=/usr/local/zookeeper/zookeeper-data/logs
clientPort=
server.=192.168.12.162::
server.=192.168.12.163::
server.=192.168.12.164::

1.3 修改默认zookeeper.out 日志输出位置:

将原日志输出文件位置注释掉,然后新增一行:

ZOO_LOG_DIR="/usr/local/zookeeper/zookeeper-data/logs"

编辑如下文件修改成如下样式:  

vim /usr/local/zookeeper/bin/zkEnv.sh

安装部署zookeeper集群

1.4 同步集群中其他服务器配置

 scp –r /usr/local/zookeeper root@192.168.12.163:/usr/local/
scp –r /usr/local/zookeeper root@192.168.12.164:/usr/local/

二、 ssh 登陆192.168.12.163 修改myid 文件:

echo “2” > /usr/local/zookeeper/zookeeper-data/myid

三、ssh 登陆192.168.12.164修改myid 文件:

echo “3” > /usr/local/zookeeper/zookeeper-data/myid

四、 分别在三台机器上执行如下操作:

4.1 启动zookeeper服务

/usr/local/zookeeper/bin/zkServer.sh start

4.2 查看zookeeper 启动状态

/usr/local/zookeeper/bin/zkServer.sh status

4.2 如启动失败,重新启动zookeeper 置于前台运行,可看到报错信息

/usr/local/zookeeper/bin/zkServer.sh start-foreground

  

上一篇:【原创】node+express+socket搭建一个实时推送应用


下一篇:KAFKA && zookeeper 集群安装