上传zookeeper到/export/servers
scp -r D:\桌面\hadoop笔记\资料\04_jar包\zookeeper-3.4.10.tar.gz root@hadoop102:/export/servers
解压zookeeper
[root@hadoop102 servers]# tar -zxvf zookeeper-3.4.10.tar.gz -C ./
# 重命名zookeeper
[root@hadoop102 servers]# mv zookeeper-3.4.10 zookeeper
修改zookeeper配置文件
[root@hadoop102 zookeeper]# cd /export/servers/zookeeper/conf/
[root@hadoop102 conf]# cp zoo_sample.cfg zoo.cfg
[root@hadoop102 conf]# vim zoo.cfg
编辑内容如下
dataDir=/export/data/zookeeper/zkdata
dataLogDir=/export/data/zookeeper/zklog
server.0=hadoop102:2888:3888
server.1=hadoop103:2888:3888
server.2=hadoop104:2888:3888
新建zookeeper执行文件存放目录与日志目录
[root@hadoop102 conf]# mkdir -p /export/data/zookeeper/zkdata
[root@hadoop102 conf]# mkdir -p /export/data/zookeeper/zklog
编辑myid文件
[root@hadoop102 conf]# mkdir -p /export/data/zookeeper/zklog
[root@hadoop102 conf]# cd /export/data/zookeeper/zkdata/
[root@hadoop102 zkdata]# echo 0 >myid
配置zookeeper环境变量
[root@hadoop102 conf]# cd /etc/profile.d/
[root@hadoop102 profile.d]# vim my_env.sh
#内容如下
#ZooKeeper_HOME
export ZK_HOME=/export/servers/zookeeper
export PATH=$PATH:$ZK_HOME/bin
分发my_env.sh文件
[root@hadoop102 profile.d]# scp ./my_env.sh root@hadoop103:/etc/profile.d/
[root@hadoop102 profile.d]# scp ./my_env.sh root@hadoop104:/etc/profile.d/
分发zookeeper
[root@hadoop102 ~]# scp -r /export/servers/zookeeper root@hadoop103:/export/servers/
[root@hadoop102 ~]# scp -r /export/servers/zookeeper root@hadoop104:/export/servers/
分别在hadoop103,hadoop104新建文件夹编辑myid文件
[root@hadoop103 ~]# mkdir -p /export/data/zookeeper/zkdata
[root@hadoop103 ~]# mkdir -p /export/data/zookeeper/zklog
[root@hadoop103 ~]# cd /export/data/zookeeper/zkdata/
[root@hadoop103 zkdata]# echo 1 >myid
[root@hadoop103 zkdata]#
[root@hadoop104 ~]# mkdir -p /export/data/zookeeper/zkdata
[root@hadoop104 ~]# mkdir -p /export/data/zookeeper/zklog
[root@hadoop104 ~]# cd /export/data/zookeeper/zkdata/
[root@hadoop104 zkdata]# echo 2 > myid
刷新环境变量
source /etc/profile
启动zookeeper集群
[root@hadoop102 bin]# zkServer.sh start
编辑群起zookeeper脚本
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start")
echo " =================== 启动 zookeeper集群 ==================="
ssh hadoop102 "/export/servers/zookeeper/bin/zkServer.sh start"
ssh hadoop103 "/export/servers/zookeeper/bin/zkServer.sh start"
ssh hadoop104 "/export/servers/zookeeper/bin/zkServer.sh start"
;;
"stop")
echo " =================== 关闭 zookeeper集群 ==================="
ssh hadoop102 "/export/servers/zookeeper/bin/zkServer.sh stop"
ssh hadoop103 "/export/servers/zookeeper/bin/zkServer.sh stop"
ssh hadoop104 "/export/servers/zookeeper/bin/zkServer.sh stop"
;;
*)
echo "Input Args Error..."
;;
esac
至此zookeeper集群搭建完成