3、移动实例所需文件及目录到2个实例目录中
[tomcat@master ~]$ cd apache-tomcat-8.5.16
[tomcat@master apache-tomcat-8.5.16]$ ls
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[tomcat@master apache-tomcat-8.5.16]$ mv conf/ webapps/ temp/ logs/ work/ ../tomcat-1
[tomcat@master apache-tomcat-8.5.16]$ cd ..
[tomcat@master ~]$ cp -a tomcat-1/* tomcat-2/
4、新建Tomcat启动、停止脚本
[tomcat@master ~]$ cd tomcat-shell/
1)启动脚本
[tomcat@master tomcat-shell]$ vim start_tomcat.sh
#!/bin/bash
#description: This script is for start tomcat instance, $1 is the tomcat/web instance directory
#history: 2017/8/13 first release
#author: wang xiaohua
#contact: wxh2673@163.com
export CATALINA_HOME=/home/tomcat/apache-tomcat-8.5.16
export CATALINA_BASE=${1%/}
export log=$CATALINA_BASE/startup.log
# use %/ is for next grep match
echo $CATALINA_BASE
Tomcat_PID=$(ps aux | grep "java" | grep -v "grep" | grep "Dcatalina.base=${CATALINA_BASE}" |awk '{print $2}')
if [ -n "$Tomcat_PID" ];then
echo "The tomcat instance $CATALINA_BASE is running,please checkout the status";
exit 1;
fi
/usr/bin/sh $CATALINA_HOME/bin/startup.sh > $log 2>&1
if [ "$?" = 0 ];then
echo "The tomcat instance $CATALINA_BASE start succeed!!!";
else
echo "The tomcat instance $CATALINA_BASE start faild!!!"
tail -f $log
fi
2)停止脚本
[tomcat@master tomcat-shell]$ vim stop_tomcat.sh
#!/bin/bash
#description: This script is for stop tomcat instance, $1 is the tomcat/web instance directory
#history: 2017/8/13 first release
#author: wang xiaohua
#contact: wxh2673@163.com
export CATALINA_HOME=/home/tomcat/apache-tomcat-8.5.16
export CATALINA_BASE=${1%/}
export log=$CATALINA_BASE/stop.log
# use %/ is for next grep match
echo $CATALINA_BASE
Tomcat_PID=$(ps aux | grep "java" | grep -v "grep" | grep "Dcatalina.base=${CATALINA_BASE}" |awk '{print $2}')
if [ -n "$Tomcat_PID" ];then
/usr/bin/sh $CATALINA_HOME/bin/shutdown.sh > $log 2>&1
else
echo "The tomcat instance $CATALINA_BASE is not running,please checkout the status"
exit 1;
fi
if [ "$?" = 0 ];then
echo "The tomcat instance $CATALINA_BASE stop succeed!!!";
else
echo "The tomcat instance $CATALINA_BASE stop faild!!!"
tail -f $log
fi