JDK Tomcat相关-下载、部署、环境变量

系统+安全 Liemer_Lius 67℃

下载地址-国内阿里云加速

jdk-11.0.10_windows-x64_bin.zip	https://code.aliyun.com/kar/ojdk-11.0.10/raw/master/jdk-11.0.10_windows-x64_bin.zip
jdk-11.0.10_osx-x64_bin.tar.gz	https://code.aliyun.com/kar/ojdk-11.0.10/raw/master/jdk-11.0.10_osx-x64_bin.tar.gz
jdk-11.0.10_linux-x64_bin.tar.gz	https://code.aliyun.com/kar/ojdk-11.0.10/raw/master/jdk-11.0.10_linux-x64_bin.tar.gz
jdk-11.0.10_linux-aarch64_bin.tar.gz	https://code.aliyun.com/kar/ojdk-11.0.10/raw/master/jdk-11.0.10_linux-aarch64_bin.tar.gz
jdk-8u281-linux-aarch64.tar.gz	https://code.aliyun.com/kar/ojdk-8u281/raw/master/jdk-8u281-linux-aarch64.tar.gz
jdk-8u281-linux-x64.tar.gz	https://code.aliyun.com/kar/ojdk-8u281/raw/master/jdk-8u281-linux-x64.tar.gz
jdk-8u281-macosx-x64.dmg	https://code.aliyun.com/kar/ojdk-8u281/raw/master/jdk-8u281-macosx-x64.dmg
jdk-8u281-windows-x64.exe	https://code.aliyun.com/kar/ojdk-8u281/raw/master/jdk-8u281-windows-x64.exe

解压后直接放到对应目录

环境变量

> vim /etc/profile.d/java.sh
export JAVA_HOME=/home/codebrother/jdk/jdk1.7.0_25
export JAVA_BIN=$JAVA_HOME/bin
export JAVA_LIB=$JAVA_HOME/lib
export CLASSPATH=.:$JAVA_LIB/tools.jar:$JAVA_LIB/dt.jar
export PATH=$JAVA_BIN:$PATH

Tomcat简单重启脚本:

#!/bin/bash
TOMCAT_HOME=/usr/local/tomcat-lius_8.5.65/
BINDIR=${TOMCAT_HOME}/bin
LOGFILE=${TOMCAT_HOME}/logs/status.log
> ${LOGFILE}
${BINDIR}/shutdown.sh > ${LOGFILE} 2>&1
sleep 2
if ! ps aux |grep tomcat |grep -v -q grep; then
    echo "Stop tomcat successfully, begin to start..."
else
    echo "Stop tomcat failed, begin to kill the process..."
    ps aux |grep tomcat |grep -v -q grep |awk '{print $2}' |xargs -i kill -9 {}
    sleep 1
    if ! ps aux |grep tomcat |grep -v -q grep; then
        echo "Tomcat had been killed successfully..."
    else
        echo "Kill tomcat process failed, exit..."
        exit 8
    fi
fi

${BINDIR}/startup.sh > ${LOGFILE} 2>&1
if ps aux |grep tomcat |grep -v -q grep; then
    echo "Start tomcat successfully..."
else
    echo "Start tomcat failed, exit..."
    exit 3
fi

根据实例启停Tomcat的脚本:

#!/bin/bash
set -euo pipefail
DIR_NAME=$1

# 停止
cd /usr/local/${DIR_NAME}/bin
./shutdown.sh &> /dev/null 2>&1
sleep 1
TIME_WAIT=0
while :; do
    if [ ${TIME_WAIT} -gt 10 ]; then
        echo "停止超时,脚本退出!"
        exit 5
    else
        if ps aux |grep "${DIR_NAME}" |grep -v grep |grep -vq "re_Tomcat.sh"; then
            sleep 1
            let TIME_WAIT+=1
        else
            echo "停止${DIR_NAME}成功..."
            break
        fi
    fi
done

# 启动
./startup.sh &> /dev/null 2>&1
sleep 1
TIME_WAIT=0
while :; do
    if [ ${TIME_WAIT} -gt 10 ]; then
        echo "启动超时,脚本退出!"
        exit 6
    else
        if ps aux |grep ${DIR_NAME} |grep -v grep |grep -vq "re_Tomcat.sh"; then
            echo "启动${DIR_NAME}成功,新Tomcat进程ID和启动时间为:`ps aux |grep ${DIR_NAME} |grep -v "re_Tomcat.sh"|grep -v grep |awk '{print $2,$9}'`"
            break
        else
            sleep 1
        fi
    fi
done

Tomcat自动部署war包到ROOT目录:

注意,这里是指的讲war包解压后,直接命名为ROOT。原来webapps里面就有ROOT目录,在重启前需要删除或者mv,因为重启不会覆盖原有的项目。

修改conf目录下server.xml,在文件末尾Host标签中加上如下配置:
<Context path="/" docBase="../wars/lius.war" reloadable="true" crossContext="true" />

这里的/指的是tomcat程序所在的目录,在tomcat程序目录下有wars/lius.war这个包,重启tomcat之后,会将这个包解压后,命名为webapps/ROOT,这样,访问这个app就可以通过ip:端口访问,不用再加app名字了。

转载请注明:skelchina.com » JDK Tomcat相关-下载、部署、环境变量

喜欢 (0)