tomcat环境自动化部署
时间:2017-03-04 21:14 来源:潇湘夜雨 作者:华嵩阳 点击:次
一、准备工作
下载好jdk和tomcat的安装文件放到指定的目录
[root@localhost sh]# ls jdk+tomcat_install #脚本目录
java.sh pack tomcat.bak tomcat.sh
[root@localhost sh]# ls jdk+tomcat_install/pack/ #软件包目录
apache-tomcat-7.0.75-src.tar.gz apache-tomcat-7.0.75.tar.gz jdk-7u45-linux-x64.tar.gz
代码分为两部分,实验中是将两部分代码都写在java.sh中
[root@localhost jdk+tomcat_install]# bash -x java.sh #执行前先测试代码流程
+ '[' -d /usr/local/java ']'
+ '[' -d /usr/local/java/jdk1.7.0_45 ']'
+ echo 'jdk had install'
jdk had install #已经安装了jdk
+ read -t 50 -p 'Please input tomcat install path:' tomcatpath
Please input tomcat install path:/usr/local/tomcat
+ '[' -d /usr/local/tomcat ']'
+ echo 'path have used!!'
path have used!! #输入的路径已经备用了
+ '[' -d ./apache-tomcat-7.0.75 ']'
+ echo 'uncompress fail!'
uncompress fail!
+ exit 1
[root@localhost jdk+tomcat_install]# bash java.sh #执行脚本
二、脚本内容
1.jdk自动部署脚本
#!/bin/bash
#jdk7 install
[ -d /usr/local/java ] || mkdir /usr/local/java
if [ -d /usr/local/java/jdk1.7.0_45 ]
then
echo "jdk had install"
else
tar -zxf ./pack/jdk-7u45-linux-x64.tar.gz -C /usr/local/java
[ -f /etc/profile.d/java.sh ] || touch java.sh
echo 'JAVA_HOME=/usr/local/java/jdk1.7.0_45
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASS_PATH PATH' > /etc/profile.d/java.sh
source /etc/profile
java -version
echo "jdk7.0 install complete! prepare install tomcat"
fi
2.tomcat自动部署脚本
#!/bin/bash
#tomcat install
read -t 50 -p "Please input tomcat install path:" tomcatpath
[ -d $tomcatpath ] && echo "path have used!!"||tar -zxf ./pack/apache-tomcat-7.0.75.tar.gz -C ./
if [ -d ./apache-tomcat-7.0.75 ]
then
mv ./apache-tomcat-7.0.75 $tomcatpath
else
echo "uncompress fail!"
exit 1
fi
#tomcat enviroment path
[ -d /etc/profile.d/tomcat.sh ] || touch tomcat.sh
echo "export CATALINA_HOME=$tomcatpath" >/etc/profile.d/tomcat.sh
echo 'export PATH=$PATH:$CATALINA_HOME/bin' >>/etc/profile.d/tomcat.sh
source /etc/profile
catalina.sh version
echo "tomcat install complete!"
#tomcat service add
if [ ! -f /etc/init.d/tomcat ]
then
echo "
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
JAVA_HOME=$JAVA_HOME
CATALINA_HOME=$CATALINA_HOME
export JAVA_HOME CATALINA_HOME
# export CATALINA_OPTS="-Xms128m -Xmx256m"
" >/etc/init.d/tomcat
echo 'exec $CATALINA_HOME/bin/catalina.sh $*' >>/etc/init.d/tomcat
chmod +x /etc/init.d/tomcat
/sbin/service tomcat start && echo "tomct already start" || echo "tomcat start fail!"
netstat -tnlp |grep 8080
else
echo "tomcat service have exist!!!"
fi
|