简介:本篇博客包含Zookeeper的详细集群安装教程和群起群停脚本。
1、官网:https://zookeeper.apache.org/
2、下载地址:https://zookeeper.apache.org/releases.html
2、安装使用相关文档:https://zookeeper.apache.org/doc/r3.5.7/index.html
bdc112 | bdc113 | bdc114 |
---|---|---|
zookeeper | zookeoper | zookeoper |
[lqs@bdc112 software]$ tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /home/lqs/module/
[lqs@bdc112 module]$ xsync /zookeeper-3.5.7
1、在/home/lqs/module/zookeeper-3.5.7/创建zkData
[lqs@bdc112 module]$ mkdir zkData
2、在刚刚创建的目录下创建一个myid文件并编辑
[lqs@bdc112 zkData]$ touch myid [lqs@bdc112 zkData]$ vim myid
2
3、将配置好的myid文件拷贝到另外两台服务器上
[lqs@bdc112 zkData]$ xsync myid
+注意:需要在服务器bdc113和服务器114上将myid修改为3和4
1、重命名/home/lqs/module/zookeeper-3.5.7/conf这个目录下的zoo_sample.cfg为zoo.cfg
[lqs@bdc112 conf]$ mv zoo_sample.cfg zoo.cfg
2、打开zoo.cfg文件进行相关配置
[lqs@bdc112 conf]$ vim zoo.cfg
修改数据的存储路径
dataDir=/home/lqs/module/zookeeper-3.5.7/zkData
任何增加如下配置:
#######################cluster########################## server.2=bdc112:2888:3888 server.3=bdc113:2888:3888 server.4=bdc114:2888:3888
3、同步刚刚配置的文件
[lqs@bdc112 conf]$ xsync zoo.cfg
[lqs@bdc112 conf]$ sudo vim /etc/profile.d/my_env.sh
#ZOOKEEPER_HOME export ZOOKEEPER_HOME=/home/lqs/module/zookeeper-3.5.7 export PATH=$PATH:$ZOOKEEPER_HOME/bin
[lqs@bdc112 conf]$ sudo xsync /etc/profile.d/my_env.sh
注意:分发记得对每个节点的环境变量进行source一下
[lqs@bdc112 conf]$ source /etc/profile.d/my_env.sh
1、分别启动Zookeeper
[lqs@bdc112 zookeeper-3.5.7]$ bin/zkServer.sh start [lqs@bdc113 zookeeper-3.5.7]$ bin/zkServer.sh start [lqs@bdc114 zookeeper-3.5.7]$ bin/zkServer.sh start
2、查看状态
[lqs@bdc114 zookeeper-3.5.7]# bin/zkServer.sh status JMX enabled by default Using config: /home/lqs/module/zookeeper-3.5.7/bin/../conf/zoo.cfg Mode: follower [lqs@bdc114 zookeeper-3.5.7]# bin/zkServer.sh status JMX enabled by default Using config: /home/lqs/module/zookeeper-3.5.7/bin/../conf/zoo.cfg Mode: leader [lqs@bdc114 zookeeper-3.5.7]# bin/zkServer.sh status JMX enabled by default Using config: /home/lqs/module/zookeeper-3.5.7/bin/../conf/zoo.cfg Mode: follower
3、分别启动Zookeeper
[lqs@bdc112 zookeeper-3.5.7]$ bin/zkServer.sh stop [lqs@bdc113 zookeeper-3.5.7]$ bin/zkServer.sh stop [lqs@bdc114 zookeeper-3.5.7]$ bin/zkServer.sh stop
[lqs@bdc112 bin]$ pwd /home/lqs/bin [lqs@bdc112 bin]$ vim myzookeeper.sh
输入以下内容:
#!/bin/bash if [ $# -lt 1 ] then echo "No Args Input" exit fi case $1 in "start") for i in bdc112 bdc113 bdc114 do echo "================== 启动 $i Zookeeper ==================" ssh $i /home/lqs/module/zookeeper-3.5.7/bin/zkServer.sh start done for i in bdc112 bdc113 bdc114 do echo "==================$i Zookeeper状态 ==================" ssh $i /home/lqs/module/zookeeper-3.5.7/bin/zkServer.sh status done ;; "stop") for i in bdc112 bdc113 bdc114 do echo "================== 关闭 $i Zookeeper ==================" ssh $i /home/lqs/module/zookeeper-3.5.7/bin/zkServer.sh stop done ;; "status") for i in bdc112 bdc113 bdc114 do echo "================== 查看 $i Zookeeper状态 ==================" ssh $i /home/lqs/module/zookeeper-3.5.7/bin/zkServer.sh status done ;; *) echo "Args Error" ;; esac