Zookeeper的分布式安装


简介:本篇博客包含Zookeeper的详细集群安装教程和群起群停脚本。


这里写目录标题

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

解压安装

  • 解压Zookeeper安装包到自己的安装目录下
[lqs@bdc112 software]$ tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /home/lqs/module/
  • 同步/home/lqs/module/zookeeper-3.5.7目录到bdc113、bdc114
[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
  • 在文件中添加与server对应的编号

2

3、将配置好的myid文件拷贝到另外两台服务器上

[lqs@bdc112 zkData]$ xsync myid

+注意:需要在服务器bdc113和服务器114上将myid修改为3和4

配置zoo.cfg文件

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

Zookeeper的分布式安装
3、同步刚刚配置的文件

[lqs@bdc112 conf]$ xsync zoo.cfg

修改环境变量

[lqs@bdc112 conf]$ sudo vim /etc/profile.d/my_env.sh

Zookeeper的分布式安装

#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
上一篇:2.纯 CSS 创作一个矩形旋转 loader 特效


下一篇:Linux see 网卡当前流量