49.第41章 tomcat

#tomcat一键安装脚本
[root@centos7 ~]# cat install_tomcat.sh 
#!/bin/bash
#
#********************************************************************
#Author:		    zhanghui
#QQ: 			    19661891
#Date: 			    2021-07-31
#FileName:		    install_tomcat.sh
#URL: 			    www.neteagles.cn
#Description:		The test script
#Copyright (C): 	2021 All rights reserved
#********************************************************************
SRC_DIR=/usr/local/src
COLOR="echo -e \\033[01;31m"
END=‘\033[0m‘

JDK_FILE="jdk-8u301-linux-x64.tar.gz"
TOMCAT_URL="https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.69/bin/"
TOMCAT_FILE="apache-tomcat-8.5.69.tar.gz"
INSTALL_DIR=/apps

os(){
    if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release;then
        rpm -q redhat-lsb-core &> /dev/null || { ${COLOR}"安装lsb_release工具"${END};yum -y install  redhat-lsb-core &> /dev/null; }
    fi
    OS_ID=`lsb_release -is`
}

check_file (){
    cd ${SRC_DIR}
    if [ ${OS_ID} == "CentOS" ] &> /dev/null;then
        rpm -q wget &> /dev/null || yum -y install wget &> /dev/null
    fi
    if [ ! -e ${JDK_FILE} ];then
        ${COLOR}"缺少${JDK_FILE}文件"${END}
        exit
    elif [ ! -e ${TOMCAT_FILE} ];then
        ${COLOR}"缺少${TOMCAT_FILE}文件"${END}
        wget ${TOMCAT_URL}${TOMCAT_FILE} || { ${COLOR}"Tomcat源码包下载失败"${END}; exit; }
    else
        ${COLOR}"相关文件已准备好"${END}
    fi
}

install_jdk(){
    [ -d ${INSTALL_DIR}/jdk ] && { ${COLOR}"JDK已存在,安装失败"${END};exit; }
    [  -d ${INSTALL_DIR} ] || mkdir -p ${INSTALL_DIR} &> /dev/null
    cd ${SRC_DIR}
    tar xf ${JDK_FILE} -C ${INSTALL_DIR}
    ln -s ${INSTALL_DIR}/jdk1.8.* ${INSTALL_DIR}/jdk
    cat >  /etc/profile.d/jdk.sh <<-EOF
export JAVA_HOME=${INSTALL_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}"JDK 安装完成"${END} || { ${COLOR}"JDK 安装失败"${END} ; exit; }
}

install_tomcat(){
    [ -d ${INSTALL_DIR}/tomcat ] && { ${COLOR}"JDK已存在,安装失败"${END};exit; }
    cd ${SRC_DIR}
    tar xf ${TOMCAT_FILE} -C ${INSTALL_DIR}
    ln -s ${INSTALL_DIR}/apache-tomcat-*  /${INSTALL_DIR}/tomcat
    echo "PATH=${INSTALL_DIR}/tomcat/bin:"‘$PATH‘ > /etc/profile.d/tomcat.sh
    id tomcat &> /dev/null || useradd -r -s /sbin/nologin tomcat
    cat > ${INSTALL_DIR}/tomcat/conf/tomcat.conf <<-EOF
JAVA_HOME=${INSTALL_DIR}/jdk
EOF
    chown -R tomcat.tomcat ${INSTALL_DIR}/tomcat/
    cat > /lib/systemd/system/tomcat.service  <<-EOF
[Unit]
Description=Tomcat
#After=syslog.target network.target remote-fs.target nss-lookup.target
After=syslog.target network.target 

[Service]
Type=forking
EnvironmentFile=${INSTALL_DIR}/tomcat/conf/tomcat.conf
ExecStart=${INSTALL_DIR}/tomcat/bin/startup.sh
ExecStop=${INSTALL_DIR}/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target
EOF
    systemctl daemon-reload
    systemctl enable --now tomcat &> /dev/null
    systemctl is-active tomcat &> /dev/null &&  ${COLOR}"TOMCAT 安装完成"${END} || { ${COLOR}"TOMCAT 安装失败"${END} ; exit; }
}

main(){
    check_file
    install_jdk
    install_tomcat
}

main

49.第41章 tomcat

上一篇:Flink用Lambda表达式报错


下一篇:数学分析原理(1): 确界原理应用(n次幂一一对应)