数据建设实践之大数据平台(二)安装zookeeper

时间:2024-07-13 07:01:01

安装zookeeper

上传安装包到/opt/software目录并解压

[bigdata@node101 software]$ tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/services/ 

重命名文件

[bigdata@node101 services]$ mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7

配置环境变量

export JAVA_HOME=/opt/services/jdk1.8.0_161
export ZK_HOME=/opt/services/zookeeper-3.5.7
export PATH=$PATH:$JAVA_HOME/bin:$ZK_HOME/bin

分发bigdata_env.sh

[bigdata@node101 ~]$ sudo ./bin/xsync /etc/profile.d/bigdata_env.sh

刷新环境变量,5台机器上执行

[bigdata@node101 ~]$ source /etc/profile

/opt/services/zookeeper-3.5.7下创建文件夹

[bigdata@node101 zookeeper-3.5.7]$  mkdir zlogs zdata

在zdata目录下编辑myid文件,填上序号1

[bigdata@node101 zdata]$ vim  myid

在conf目录下编辑配置文件

[bigdata@node101 conf]$ cp zoo_sample.cfg zoo.cfg
[bigdata@node101 conf]$ vim zoo.cfg
dataDir=/opt/services/zookeeper-3.5.7/zdata
dataLogDir=/opt/services/zookeeper-3.5.7/zlogs
server.1=node101:2888:3888
server.2=node102:2888:3888
server.3=node103:2888:3888

分发文件

[bigdata@node101 ~]$ xsync /opt/services/zookeeper-3.5.7 

修改myid序号,其他节点上执行

编写zk.sh启动停止脚本

[bigdata@node101 bin]$ vim zk.sh 
#!/bin/bash

if [ $# -lt 1 ]
then
    echo "No Args Input...[start,stop]"
    exit ;
fi
case $1 in
"start")
        echo " =================== 启动 zk集群 ==================="

        echo " --------------- 启动 node101 ---------------"
        ssh node101 "$ZK_HOME/bin/zkServer.sh start"
        echo " --------------- 启动 node102---------------"
        ssh node102 "$ZK_HOME/bin/zkServer.sh start"
        echo " --------------- 启动 node103 ---------------"
        ssh node103 "$ZK_HOME/bin/zkServer.sh start"
;;
"stop")
        echo " =================== 关闭 zk集群 ==================="
        echo " --------------- 关闭 node101 ---------------"
        ssh node101 "$ZK_HOME/bin/zkServer.sh stop"
        echo " --------------- 关闭 node102---------------"
        ssh node102 "$ZK_HOME/bin/zkServer.sh stop"
        echo " --------------- 关闭 node103 ---------------"
        ssh node103 "$ZK_HOME/bin/zkServer.sh stop"
;;
*)
    echo "Input Args Error...[start,stop]"
;;
esac

zk.sh 授权

[bigdata@node101 bin]$ chmod +x  zk.sh

分发zk.sh

[bigdata@node101 bin]$ xsync  zk.sh

启动zk

[bigdata@node101 bin]$ zk.sh start 

查看zk状态

[bigdata@node101 zookeeper-3.5.7]$ bin/zkServer.sh status