侧边栏壁纸
博主头像
运维匠-运维工程师知识分享经验和最佳实践博主等级

生活百般滋味,人生需要笑对

  • 累计撰写 60 篇文章
  • 累计创建 3 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Zookeeper离线安装脚本

运维匠
2023-03-18 / 0 评论 / 0 点赞 / 7 阅读 / 4196 字
温馨提示:
本文最后更新于 2024-07-15,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

Zookeeper离线安装脚本

#!/bin/bash
#********************************************************************
#Author:            yuankun
#Date:              2023-03-18
#FileName:         install_zookeeper.sh
#Description:      The test script
#Copyright (C):     2023 All rights reserved
#********************************************************************
JDK_FILE="jdk-8u321-linux-x64.tar.gz"
#JDK_FILE="jdk-11.0.12_linux-x64_bin.tar.gz"
ZOOKEEPER_FILE=apache-zookeeper-3.7.1-bin
TAR=tar.gz
ZOOKEEPER_DIR=/usr/local/src
DIR=`pwd`
JDK_DIR="/usr/local"

color () {
    RES_COL=60
    MOVE_TO_COL="echo -en \\033[${RES_COL}G"
    SETCOLOR_SUCCESS="echo -en \\033[1;32m"
    SETCOLOR_FAILURE="echo -en \\033[1;31m"
    SETCOLOR_WARNING="echo -en \\033[1;33m"
    SETCOLOR_NORMAL="echo -en \E[0m"
    echo -n "$2" && $MOVE_TO_COL
    echo -n "["
    if [ $1 = "success" -o $1 = "0" ] ;then
        ${SETCOLOR_SUCCESS}
        echo -n $"  OK  "    
    elif [ $1 = "failure" -o $1 = "1"  ] ;then
        ${SETCOLOR_FAILURE}
        echo -n $"FAILED"
    else
        ${SETCOLOR_WARNING}
        echo -n $"WARNING"
    fi
    ${SETCOLOR_NORMAL}
    echo -n "]"
    echo                                                                                                                              
}

install_jdk(){
if !  [  -f "$DIR/$JDK_FILE" ];then
    color 1  "$JDK_FILE 文件不存在" 
    exit; 
elif [ -d $JDK_DIR/jdk ];then
        color 1  "JDK 已经安装" 
    exit
else 
        [ -d "$JDK_DIR" ] || mkdir -pv $JDK_DIR
fi
tar xvf $DIR/$JDK_FILE  -C $JDK_DIR
cd  $JDK_DIR && ln -s jdk* jdk 

cat >  /etc/profile.d/jdk.sh <<EOF
export JAVA_HOME=$JDK_DIR/jdk
#export JRE_HOME=\$JAVA_HOME/jre
#export CLASSPATH=.:\$JAVA_HOME/lib/:\$JRE_HOME/lib/
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
.  /etc/profile.d/jdk.sh
java -version && color 0  "JDK 安装完成" || { color 1  "JDK 安装失败" ; exit; }

}

install_zookeeper(){
    cd ${DIR}
    if [ -f "${ZOOKEEPER_FILE}.${TAR}" ]
    then
    echo '正在安装zookeeper,请稍等......'
        mv ${ZOOKEEPER_FILE}.${TAR} ${ZOOKEEPER_DIR};cd ${ZOOKEEPER_DIR}
        tar xf ${ZOOKEEPER_FILE}.${TAR};ln -s ${ZOOKEEPER_DIR}/${ZOOKEEPER_FILE} ${ZOOKEEPER_DIR}/zookeeper
        rm -rf ${ZOOKEEPER_FILE}.${TAR}
        mkdir -p /data/zookeeper;cd ${ZOOKEEPER_DIR}/zookeeper/conf
        cp zoo_sample.cfg zoo.cfg;sed -i 's/dataDir=\/tmp\/zookeeper/dataDir=\/data\/zookeeper/' zoo.cfg
        cat > /usr/lib/systemd/system/zookeeper.service <<EOF
[Unit]
Description=Zookeeper Service unit Configuration
After=network.target

[Service]
Type=forking
Environment=JAVA_HOME=${JDK_DIR}/jdk
ExecStart=${ZOOKEEPER_DIR}/zookeeper/bin/zkServer.sh start ${ZOOKEEPER_DIR}/zookeeper/conf/zoo.cfg
ExecStop=${ZOOKEEPER_DIR}/zookeeper/bin/zkServer.sh stop
KillMode=none
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
        systemctl daemon-reload;systemctl enable --now zookeeper
    if [ $? -eq 0 ]
    then
        echo 'zookeeper启动成功!安装完成'

        else
            echo 'zookeeper启动失败!安装失败'
        fi
    else
        echo '文件不存在,退出安装!'
        exit;

    fi
}
install_jdk
install_zookeeper
0

评论区