1. 环境准备

2. 部署安装

  1. 上传安装包到虚拟机
  2. tar -zxvf apache-zookeeper-3.6.3-bin.tar.gz -C /data/解压
  3. mv apache-zookeeper-3.6.3-bin zookeeper-3.6.3/修改安装包名称
  4. 进入安装目录,创建zkdata目录,创建myid
1
2
3
4
cd /data/zookeeper-3.6.3/
mkdir zkdata
cd zkdata/
echo 1 > myid
  1. 修改配置文件,添加对应配置信息
1
2
3
4
5
6
7
8
9
cd /data/zookeeper-3.6.3/conf/
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
# 修改以下内容:
dataDir=/data/zookeeper-3.6.3/zkdata
# 添加以下内容:
server.1=192.168.68.121:2888:3888
server.2=192.168.68.122:2888:3888
server.3=192.168.68.123:2888:3888
  1. 分发安装包到另外两台机器
1
2
scp -r zookeeper-3.6.3 hadoop@192.168.68.122:/$PWD
scp -r zookeeper-3.6.3 hadoop@192.168.68.123:/$PWD
  1. 修改另外两台机器的myid文件,192.168.68.122修改为2192.168.68.123修改为3
1
vim /data/zookeeper-3.6.3/zkdata/myid
  1. 三台依次sudo vim /etc/profile添加环境变量,然后source /etc/profile加载环境变量
1
2
3
#ZOOKEEPER_HOME
export ZOOKEEPER_HOME=/data/zookeeper-3.6.3
export PATH=$PATH:$ZOOKEEPER_HOME/bin
  1. 依次启动三台zookeeper
1
2
cd /data/zookeeper-3.6.3/bin/
zkServer.sh start
  1. 查看集群状态zkServer.sh status

3. 群起脚本

  1. 群起脚本需要配置SSH免密登录,我的这篇博客里有免密登录的教程:Hadoop3.x在centos上的完全分布式部署,就不细说了
  2. vim start_cluster.sh添加以下内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash

if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi

case $1 in
"start")
echo " =================== 启动 zookeeper集群 ==================="

echo " --------------- 启动 hadoop121 ---------------"
ssh 192.168.68.121 "/data/zookeeper-3.6.3/bin/zkServer.sh start"
echo " --------------- 启动 hadoop122 ---------------"
ssh 192.168.68.122 "/data/zookeeper-3.6.3/bin/zkServer.sh start"
echo " --------------- 启动 hadoop123 ---------------"
ssh 192.168.68.123 "/data/zookeeper-3.6.3/bin/zkServer.sh start"
;;
"stop")
echo " =================== 关闭 zookeeper集群 ==================="

echo " --------------- 关闭 hadoop121 ---------------"
ssh 192.168.68.121 "/data/zookeeper-3.6.3/bin/zkServer.sh stop"
echo " --------------- 关闭 hadoop122 ---------------"
ssh 192.168.68.122 "/data/zookeeper-3.6.3/bin/zkServer.sh stop"
echo " --------------- 关闭 hadoop123 ---------------"
ssh 192.168.68.123 "/data/zookeeper-3.6.3/bin/zkServer.sh stop"
;;
"status")
echo " =================== 查看 zookeeper集群状态 ==================="

echo " --------------- hadoop121状态 ---------------"
ssh 192.168.68.121 "/data/zookeeper-3.6.3/bin/zkServer.sh status"
echo " --------------- hadoop122状态 ---------------"
ssh 192.168.68.122 "/data/zookeeper-3.6.3/bin/zkServer.sh status"
echo " --------------- hadoop123状态 ---------------"
ssh 192.168.68.123 "/data/zookeeper-3.6.3/bin/zkServer.sh status"
;;
*)
echo "Input Args Error..."
;;
esac
  1. chmod +x start_cluster.sh,赋予脚本执行权限
  2. 执行测试