安装部署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

1 wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz -P /opt
2 tar xf /opt/zookeeper-3.4.6.tar.gz -C /usr/local/
3 mv /usr/local/zookeeper-3.4.6 /usr/local/zookeeper
4 mkdir -p /usr/local/zookeeper/zookeeper-data/logs
5 echo1”> /usr/local/zookeeper/zookeeper-data/myid
6 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=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/zookeeper-data
dataLogDir=/usr/local/zookeeper/zookeeper-data/logs
clientPort=2181
server.1=192.168.12.162:2888:3888
server.2=192.168.12.163:2888:3888
server.3=192.168.12.164:2888:3888

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

 

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

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

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

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

 

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

1 scp –r /usr/local/zookeeper root@192.168.12.163:/usr/local/
2 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

 

 

 

 

 

  

 

 

 

 

posted @ 2017-06-24 21:33  池偏一  阅读(171)  评论(0编辑  收藏  举报