Tomcat多实例一键部署shell脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tomcat多实例一键部署shell脚本相关的知识,希望对你有一定的参考价值。
#!bin/bash #Tomcat部署脚本,提前将apache-tomcat-8.5.30.tar.gz、jdk-8u172-linux-x64.tar.gz上传至服务器的/tmp/目录下 #1.安装JDK tar -zxf /tmp/jdk-8u172-linux-x64.tar.gz -C /usr/local/ ln -s /usr/local/jdk1.8.0_172/ /usr/local/jdk #配置java环境 cat >> /etc/profile.d/java.sh <<EOF export JAVA_HOME=/usr/local/jdk/ export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH EOF #注意此处的source /etc/profile,脚本运行完成后,需要退出再重新登录服务器加载/etc/profile。否则java环境失效 source /etc/profile #2.安装Tomcat tar -zxf /tmp/apache-tomcat-8.5.30.tar.gz -C /usr/local/ ln -s /usr/local/apache-tomcat-8.5.30/ /usr/local/tomcat cd /usr/local/tomcat/ mkdir -pv /usr/local/tomcat_dir mv conf/ logs/ temp/ webapps/ work/ /usr/local/tomcat_dir #n为建立Tomcat实例的个数 n=7 for((i=1;i<=n;i++)) do /usr/bin/mkdir -pv /usr/local/tomcat$i /usr/bin/cp -a /usr/local/tomcat_dir/* /usr/local/tomcat$i sed -i 's/Server port="8005"/Server port="708'$i'"/' /usr/local/tomcat$i/conf/server.xml sed -i 's/Connector port="8080"/Connector port="808'$i'"/' /usr/local/tomcat$i/conf/server.xml sed -i 's/Connector port="8009"/Connector port="908'$i'"/' /usr/local/tomcat$i/conf/server.xml done rm -rf /usr/local/tomcat_dir/ mkdir -pv /usr/local/tomcat_sh/ #注意下面的“\”,代表不转译。 cat > /usr/local/tomcat_sh/start_tomcat.sh <<EOF #!/bin/bash source /etc/profile PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin export CATALINA_HOME=/usr/local/tomcat 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 EOF cat > /usr/local/tomcat_sh/stop_tomcat.sh <<EOF #!/bin/bash source /etc/profile PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin export CATALINA_HOME=/usr/local/tomcat 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 EOF chmod +x -R /usr/local/tomcat_sh/
以上是关于Tomcat多实例一键部署shell脚本的主要内容,如果未能解决你的问题,请参考以下文章