Zk单机多实例部署

一.环境准备

当前环境:centos7.3一台
软件版本:zookeeper-3.5.2
部署目录:/usr/local/zookeeper
启动端口:2181,2182,2183
配置文件:/usr/local/zookeeper/conf/zoo1 ~ 3.cfg

yum依赖
yum install java-1.8.0-openjdk

二.安装

1.下载安装包
wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.5.2-alpha/zookeeper-3.5.2-alpha.tar.gz

2.解压并移动
tar zxvf zookeeper-3.5.2-alpha.tar.gz
mv zookeeper-3.5.2-alpha /usr/local/zookeeper

3.创建数据目录和日志目录,有几个节点,创建几个
cd /usr/local/zookeeper
mkdir data1
mkdir data2
mkdir data3

mkdir /var/log/zookeeper
mkdir /var/log/zookeeper/one
mkdir /var/log/zookeeper/two
mkdir /var/log/zookeeper/three

3.复制配置文件
cp conf/zoo.cfg conf/zoo1.cfg
cp conf/zoo.cfg conf/zoo2.cfg
cp conf/zoo.cfg conf/zoo3.cfg

修改配置文件,这里只修改第一个,后面几个类似
vim /usr/local/zookeeper/conf/zoo1.cfg

clientPort=2181 #端口不同实例不一样,第二个可以是2182
dataDir=/usr/local/zookeeper/data1 #对应的数据目录
syncLimit=5
tickTime=2000
initLimit=10
dataLogDir=/var/log/zookeeper/one #对应日志
dynamicConfigFile=/usr/local/zookeeper/conf/zoo1.cfg.dynamic #对应的节点文件

4.复制节点文件
cp conf/zoo.cfg.dynamic conf/zoo1.cfg.dynamic
cp conf/zoo.cfg.dynamic conf/zoo2.cfg.dynamic
cp conf/zoo.cfg.dynamic conf/zoo3.cfg.dynamic

修改节点文件,这里只修改第一个,后面几个类似
vim conf/zoo1.cfg.dynamic

server.1=172.26.98.239:2777:3777  ##第一台节点IP端口
server.2=172.26.98.239:2888:3888  ##第二台节点IP端口
server.3=172.26.98.239:2999:3999  ##第三台节点IP端口

5.建立myid文件
echo "1" > data1/myid
echo "2" > data2/myid
echo "3" > data3/myid

三.使用验证

启动效验
/usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo1.cfg

/usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo2.cfg

/usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo3.cfg

查看集群状态
/usr/local/zookeeper/bin/zkServer.sh status /usr/local/zookeeper/conf/zoo1.cfg

/usr/local/zookeeper/bin/zkServer.sh status /usr/local/zookeeper/conf/zoo2.cfg

/usr/local/zookeeper/bin/zkServer.sh status /usr/local/zookeeper/conf/zoo3.cfg

/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Client port found: 2182. Client address: localhost.
Mode: leader
posted @ 2019-01-04 15:08  禾子、  阅读(578)  评论(0编辑  收藏  举报