hadoop 3.3大数据集群搭建系列2-安装zookeeper

一. 下载并解压

cd /home/software
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz --no-check-certificate

tar -xvf apache-zookeeper-3.6.3-bin.tar.gz -C /home

二. 修改配置文件

cd /home/apache-zookeeper-3.6.3-bin/conf
# 添加zookeeper配置文件
cp zoo_sample.cfg zoo.cfg
# 创建数据存放目录
mkdir /home/apache-zookeeper-3.6.3-bin/data

vim zoo.cfg
# 添加如下内容
server.1=hp5:2188:2888
server.2=hp6:2188:2888
server.3=hp7:2188:2888
# 修改dataDir
dataDir=/home/apache-zookeeper-3.6.3-bin/data

# 配置文件保存退出后,进入data目录
cd ../data
# 生成myid文件,指定myid服务号
echo "1" > myid

三. 将zookeeper目录分发到其他节点

# 分发到其他集群节点
cd /home
scp -r apache-zookeeper-3.6.3-bin/ root@hp6:/home
scp -r apache-zookeeper-3.6.3-bin/ root@hp7:/home

四. 修改其他节点的myid文件

登录 hp6 节点:

cd /home/apache-zookeeper-3.6.3-bin/data
# 指定myid服务号为 2
vim myid

登录 hp7 节点:

cd /home/apache-zookeeper-3.6.3-bin/data
# 指定myid服务号为 3
vim myid

五. 编写操作zookeeper集群的脚本

cd /home/apache-zookeeper-3.6.3-bin/bin
# 创建zookeeper启动脚本
vim zk.sh
# 添加如下内容
#!/bin/bash
case $1 in
"start"){
    for i in hp5 hp6 hp7
    do 
         echo -------------------------------- $i zookeeper 启动 ---------------------------
        ssh $i "/home/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start"
    done
}
;;
"stop"){
    for i in hp5 hp6 hp7
    do
        echo -------------------------------- $i zookeeper 停止 ---------------------------
        ssh $i "/home/apache-zookeeper-3.6.3-bin/bin/zkServer.sh stop"
    done
}
;;
"status"){
    for i in hp5 hp6 hp7
    do
        echo -------------------------------- $i zookeeper 状态 ---------------------------
        ssh $i "/home/apache-zookeeper-3.6.3-bin/bin/zkServer.sh status"
    done
}
;;
esac

# 保存退出后,修改zk.sh脚本执行权限
chmod +x ./zk.sh

脚本的命令说明:

# 启动集群命令
./zk.sh start
# 停止集群命令
./zk.sh stop
# 查看集群状态命令
./zk.sh status

六. 启动集群

# 启动zookeeper集群
cd /home/apache-zookeeper-3.6.3-bin
./bin/zk.sh start
image.png

七. 连接zookeeper集群

# 连接zookeeper集群
cd  /home/apache-zookeeper-3.6.3-bin
./bin/zkCli.sh
image.png

参考:

  1. https://blog.csdn.net/LW_GHY/article/details/87862903
  2. https://blog.csdn.net/u011109589/article/details/124907414

你可能感兴趣的:(hadoop 3.3大数据集群搭建系列2-安装zookeeper)