传统云环境下的CI/CD操作手册配置tomcat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了传统云环境下的CI/CD操作手册配置tomcat相关的知识,希望对你有一定的参考价值。

首先准备jdk环境
mkdir /apps & cd /apps
上传jdk压缩包到/apps内
tar xvf jdk-7u79-linux-x64.tar.gz
ln -sv /apps/jdk1.7.0_79 /apps/jdk
vim /etc/profile
export export LANG="en_US.utf-8"
export JAVA_HOME=/apps/jdk
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile && java -version

然后安装tomcat
将tomcat压缩包上传到/apps内
tar xvf apache-tomcat-7.0.59.tar.gz
ln -sv /apps/apache-tomcat-7.0.59 /apps/tomcat
将tomcat启动脚本上传到/root内
cp /root/tomcat /etc/init.d/
chmod +x /etc/init.d/tomcat
/etc/init.d/tomcat start
http://192.168.1.17:8080
http://192.168.1.18:8080
单独准备tomcat数据目录,生产环境,数据和软件不能放在一个目录
mkdir -p /data/tomcat/webapps
vim /apps/tomcat/conf/server.xml
<Host name="localhost" appBase="/data/tomcat/webapps"
cd /data/tomcat/webapps/
mkdir web01 & cd web01
vim index.html
Tomcat!!!
/etc/init.d/tomcat restart
http://192.168.1.17:8080/web01
http://192.168.1.18:8080/web01

tomcat启动脚本
#!/bin/bash

JDK_HOME=/apps/jdk
CATALINA_HOME=/apps/tomcat
export JDK_HOME CATALINA_HOME
source /etc/profile
#PID=ps -ef | grep -v grep | grep java | awk ‘print $2‘
#NUM=ps -ef | grep -v grep | grep java | awk ‘print $2‘ | wc -l

#case $1 in
start()
echo "正在判断服务状态,请稍等!"
echo "请稍等3秒钟"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
echo "Tomcat已经正在运行了!"
else
echo "Tomcat没有运行,1秒后启动!"
echo 1;sleep 1
$CATALINA_HOME/bin/catalina.sh start
echo "Tomcat 已经成功启动完成,5秒后判断是否启动成功"
echo "5";sleep 1;echo "4";sleep 1
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
PID=ps -ef | grep tomcat | grep jdk | awk ‘print $2‘
NUM=ps -ef | grep tomcat | grep jdk | awk ‘print $2‘ | wc -l
echo "Tomcat 已经成功启动$NUM 个Tomcat进程!,PID为$PID"
else
echo "Tomcat启动失败,请重新启动!"
echo 1
fi
fi

stop()
PID=ps -ef | grep -v grep | grep java | awk ‘print $2‘
NUM=ps -ef | grep -v "color" | grep tomcat | awk ‘print $2‘ | wc <br/>-l echo "正在判断服务状态,请稍等3秒钟!"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
if netstat -an | grep 8080 | grep LISTEN >/dev/null
then
echo "Tomcat运行中,1秒后关闭!"
echo 1;sleep 1
echo "即将关闭Tomcat服务,请稍等!"
$CATALINA_HOME/bin/catalina.sh stop ;echo "已经执行关闭命令,正在检查关闭了多少
Tomcat进程,请稍等30秒钟!" sleep 27
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
pkill java && pkill tomcat
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
PID=ps -ef | grep -v grep | grep java | awk ‘print $2‘
NUM=ps -ef | grep -v "color" | grep tomcat | awk ‘print $2<br/>‘ | wc -l kill -9 $PID ;echo "已成功关闭$NUM 个tomcat进程"
else
echo "Tomcat 已经关闭完成!"
echo "3";sleep 1;echo "2";sleep 1;echo "1";sleep 1
fi
else
echo "Tomcat 没有运行"
echo 1
fi
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
PID=ps -ef | grep -v grep | grep java | awk ‘print $2‘
#NUM=ps -ef | grep -v "color" | grep tomcat | awk ‘print $2‘ | wc -l
echo "关闭失败,即将强制删除tomcat进程!"
sleep 2
pkill tomcat ;sleep 2
if netstat -an | grep 8080 | grep LISTEN >/dev/null;then
echo "强制关闭失败,即将再次强制删除tomcat进程!"
pkill java; sleep 2
fi
fi

restart()
stop
start

case "$1" in
start)
start
;;

stop)
stop
;;

restart)
restart
;;

*)
echo $"Usage: $0 start|stop|restart|status"
esac

以上是关于传统云环境下的CI/CD操作手册配置tomcat的主要内容,如果未能解决你的问题,请参考以下文章

传统云环境下的CI/CD操作手册配置jenkins

传统云环境下的CI/CD操作手册jenkins手动构建示例及实现自动触发构建

PHP应用的CI/CD流程实践与学习:PHP运行环境的准备

自动化运维|云原生架构下的产品自动化发布快速部署和持续交付实战之路

tomcat+jenkins+gitlab自动化构建框架搭建

devops学习笔记-jenkins实现基础CI/CD操作