Tomcat项目简单部署
Tomcat安装
1 2 3 4 5 6 7 8
| shell> tar zxvf jdk-VERSION-linux-x64.tar.gz -C /usr/local/ shell> ln -s /usr/local/jdkVERSION /usr/local/java shell> tar zxvf apache-tomcat-VERSION.tar.gz -C /usr/local shell> ln -s apache-tomcat-VERSION /usr/local/tomcatN shell> vi /etc/profile.d/env.sh shell> source /etc/profile.d/env.sh
|
环境变量配置
1 2 3
| export JAVA_HOME=/usr/local/java export CATALINA_HOME=/usr/local/tomcat export PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH
|
项目简单部署
1 2 3 4
| # 把项目war包上传到/usr/local/tomcatN/webapps目录,重启tomcat shell> cd /usr/local/tomcatN shell> bin/shutdown.sh shell> bin/startup.sh
|
Tomcat项目程序和环境分离部署
Tomcat的服务安装目录和项目程序的发布目录不在同一个目录下,原来的简单发布中项目程序的发布目录为Tomcat安装目录的webapps目录下,这样存在的问题为Tomcat升级麻烦,把环境目录的发布目录分离,Tomcat的升级不受程序发布的war包影响
Tomcat安装
1 2 3 4 5 6 7 8
| shell> tar zxvf jdk-VERSION-linux-x64.tar.gz -C /usr/local/ shell> ln -s /usr/local/jdkVERSION /usr/local/java shell> tar zxvf apache-tomcat-VERSION.tar.gz -C /usr/local shell> ln -s apache-tomcat-VERSION /usr/local/tomcatN shell> vi /etc/profile.d/env.sh shell> source /etc/profile.d/env.sh
|
环境变量配置
1 2
| export JAVA_HOME=/usr/local/java export PATH=$JAVA_HOME/bin:$PATH
|
配置项目发布服务目录
1 2 3 4 5 6 7 8 9 10
| shell> mkdir -p /usr/local/warservices/YOUR_SER shell> cd /usr/local/warservices/testser shell> cd /usr/local/tomcatN shell> cp -r conf logs temp webapps work /usr/local/warservices/testser shell> cd /usr/local/warservices/testser shell> vi tomcat.sh shell> chmod u+x tomcat.sh shell> ./tomcat.sh restart
|
tomcat.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #!/bin/bash export JAVA_HOME=/usr/local/java export CATALINA_HOME=/usr/local/tomcat8 export CATALINA_BASE="`pwd`" case $1 in start) $CATALINA_HOME/bin/catalina.sh start echo start success ! ;; stop) $CATALINA_HOME/bin/catalina.sh stop echo stop success ! ;; restart) $CATALINA_HOME/bin/catalina.sh stop echo stop success ! sleep 2 $CATALINA_HOME/bin/catalina.sh start echo start success ! ;; esac exit 0
|
Tomcat产品级发布,支持版本记录和回滚
Tomcat发布项目上面的方式可以让程序和环境分离,但是还是不能达到要求,产品发布需要记录不同的版本和同一个版本可能发布多次,为了满足产品级发布,除了是环境和程序分离外还需要添加额外的一些操作
Tomcat安装
1 2 3 4 5 6 7 8
| shell> tar zxvf jdk-VERSION-linux-x64.tar.gz -C /usr/local/ shell> ln -s /usr/local/jdkVERSION /usr/local/java shell> tar zxvf apache-tomcat-VERSION.tar.gz -C /usr/local shell> ln -s apache-tomcat-VERSION /usr/local/tomcatN shell> vi /etc/profile.d/env.sh shell> source /etc/profile.d/env.sh
|
环境变量配置
1 2
| export JAVA_HOME=/usr/local/java export PATH=$JAVA_HOME/bin:$PATH
|
配置项目发布服务目录
1 2 3 4 5 6 7 8 9 10 11 12
| shell> mkdir -p /usr/local/warservices/YOUR_SER shell> cd /usr/local/warservices/testser shell> cd /usr/local/tomcatN shell> cp -r conf logs temp webapps work /usr/local/warservices/testser shell> cd /usr/local/warservices/testser shell> vi tomcat.sh shell> chmod u+x tomcat.sh shell> vi deploy.sh shell> chmod u+x deploy.sh shell> ./deploy.sh
|
deploy.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #!/bin/bash app_name=$1 app_version=$2 deploy_time=`date "+%Y_%m_%d_%H_%M_%S"` war_packages_dir=`pwd`/warPackages war=$war_packages_dir/${app_name}_${app_version}.war echo $war deploy_app() { target_dir=$war_packages_dir/$app_name-$app_version-$deploy_time if [ ! -f $war ]; then echo "App war file not exist !" exit 1 fi /usr/bin/unzip -q $war -d $target_dir /usr/bin/cp -r `pwd`/appConf/* $target_dir/WEB-INF/classes/ /usr/bin/rm -rf `pwd`/appwar /usr/bin/ln -sf $target_dir appwar if [ -f deploy.sh ]; then `pwd`/tomcat.sh stop fi target_ln=`pwd`/appwar /usr/bin/echo '<?xml version="1.0" encoding="UTF-8" ?> <Context docBase="'$target_ln'" allowLinking="true"></Context>' > `pwd`/conf/Catalina/localhost/ROOT.xml /usr/bin/chmod +x deploy.sh `pwd`/tomcat.sh start } deploy_app
|
最后更新时间:
这里可以写作者留言,标签和 hexo 中所有变量及辅助函数等均可调用,示例:
http://yoursite.com/2018/02/26/tomcat-deploy-project/