shell 脚本安装tomcat

 

自动安装JDK和Tomcat的脚本
view source
print ?
001 #!/bin/bash
002 #Auto Install JDK、tomcat and they connector.
003 #执行这个脚本需要在root家目录下放好JDK、tomcat、的tar.gz源码包,
004 #以及已经执行过的jdk(本人无法做到在jdk执行时输入yes和空格,所以这一步骤需要手动做。
005 #tomcat安装到/data1/apache-tomcat-5.5.31/,已设置环境变量。
006 #JDK在/usr/java,已设置环境变量。
007 #jsp页面的存放目录为“/web”,且该目录已经有了一个叫做test1.jsp的测试文件,
008 #可以通过http://ip/test1.jsp进行访问。
009 #apache和tomcat开机自启动。
010 #防火墙80端口打开。
011 #Author
012 #       20101117 [email protected]       Version 1.0
013   
014 ##################
015 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
016 export PATH
017 ########Check software development environment.
018          #rpm -q  gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel > /dev/null
019          if  [ "$?" != 0 ] ;
020          then
021          echo "Please check your need software"
022          exit 0
023          fi
024  #        echo "proceed"
025  ############Check install files:apache tomcat JDK tomcat-connectors
026 ./jdk-6u22-linux-i586.bin
027  ##########首先给JDK文件当前用户可执行的权限,如chmod 700 jdk* ,然后执行该文件,读取许可协议后输入“yes”即可安装,安装完成后最后在当前目录获得一个jdk目录。
028  if [ ! -e apache-tomcat-6.0.*.tar* ];then
029  echo "I cann't find tomcat source file."
030  exit 0
031  fi
032  if [ ! -d jdk1.6* ];then
033  echo "I cann't find JDK directory."
034  exit 0
035  fi
036  ############Install and setup JAVA environment
037   mv jdk1.6*  /usr/java
038   cat >> /etc/profile  << EFF
039 ########################################
040  JAVA_HOME=/usr/java
041  JRE_HOME=\$JAVA_HOME/jre
042  CLASSPATH=:\$JAVA_HOME/lib:\$JRE_HOME/lib
043  PATH=\$JAVA_HOME/bin:\$JRE_HOME/bin:\$PATH
044  export JAVA_HOME JRE_HOME CLASSPATH PATH
045 ########################################
046 EFF
047  source /etc/profile
048  #######################
049   
050  java -version
051   if  [ "$?" != 0 ] ;
052          then
053          echo "I cann't set java path."
054          exit 0
055          fi
056 ###########Install Tomcat,and setup tomcat environment。
057   cd -
058   tar zxvf apache-tomcat*
059   mv apache-tomcat-6.0.29/  /data1/apache-tomcat-6.0.29/
060  cat >> /etc/profile << TTD
061  TOMCAT_HOME=/data1/apache-tomcat-6.0.29/
062  PATH=\$PATH:\$TOMCAT_HOME/bin/:/usr/local/apache2/bin:
063  export JAVA_HOME JRE_HOME CLASSPATH PATH TOMCAT_HOME
064 TTD
065  source /etc/profile
066 ############Start Tomcat
067  sh  /data1/apache-tomcat-5.5.31/bin/startup.sh 
068  sleep 5
069  curl  127.0.0.1:8080  |grep   "Thanks for using Tomcat"
070   if  [ "$?" != 0 ] ;
071          then
072          echo "I think install tomcat is unfinished  ."
073          exit 0
074          fi
075   
076  ################Set tomcat
077  ########Creat Catalina directory and  configuration file.
078  mkdir -p $TOMCAT_HOME/conf/Catalina/localhost
079  cat >> $TOMCAT_HOME/conf/Catalina/localhost/ROOT.xml << DDQ
080   "/"   docBase="/web"   debug="0"  workDir="/tmp"   reloadable="false"/> 
081 DDQ
082  ##########modify server.xml
083  #sed -i 's/appBase="webapps"/appBase="\/web"/' /data1/apache-tomcat-5.5.31//conf/server.xml 
084  #sed -i '/xmlValidation="false" xmlNamespaceAware="false">/a\'  /data1/apache-tomcat-5.5.31//conf/server.xml
085  #########################################################################################
086  cat >> /data1/apache-tomcat-5.5.31/conf/server.xml << SERVER
087  "1.0" encoding="ISO8859-1"?>
088
089   "org.apache.catalina.core.AprLifecycleListener"/>
090   "org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
091   "org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
092   "org.apache.catalina.mbeans.ServerLifecycleListener"/>
093   
094     
095       name="simpleValue"
096       type="java.lang.Integer"
097       value="30"/>
098     
099       auth="Container"
100       description="User database that can be updated and saved"
101       name="UserDatabase"
102       type="org.apache.catalina.UserDatabase"
103       pathname="conf/tomcat-users.xml"
104       factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
105     
106       name="JDBC/vpayBank"
107       type="javax.sql.DataSource"
108       driverClassName="com.mysql.jdbc.Driver"
109       password="asdf1234"
110       maxIdle="5"
111       maxWait="5000"
112       username="pay"
113       url="jdbc:mysql://*.*.*.*"
114       maxActive="200"/>
115   
116   
117       name="Catalina">
118     
119         port="80"
120         redirectPort="8443"
121         connectionTimeout="30000"
122         maxSpareThreads="75"
123         maxThreads="150"
124         URIEncoding="UTF-8"
125         minSpareThreads="25">
126     
127     
128         port="8009"
129         redirectPort="8443"
130         protocol="AJP/1.3">
131     
132     
133         defaultHost="localhost"
134         name="Catalina">
135       "org.apache.catalina.realm.UserDatabaseRealm"/>
136       
137           appBase="webapps"
138           name="localhost">
139       
140     
141   
142
143 SERVER
144 #creat test website.
145  mkdir /web
146  cat >>/web/test1.jsp<< WEB
147  <%@ page contentType="text/html;charset=gbk" %>
148  <%
149  String str1="Hello World!";
150  out.println(str1);
151  %>
152 WEB
153  #######################
154 #JDBC   配置
155 cat >>/data1/apache-tomcat-5.5.31/conf/Catalina/localhost/vpayBank.xml<< JDBC
156 "1.0" encoding="ISO8859-1"?>
157
158   
159     name="JDBC/Test"
160     type="javax.sql.DataSource"
161     driverClassName="com.mysql.jdbc.Driver"
162     password="12345"
163     maxIdle="5"
164     maxWait="5000"
165     username="pay"
166     url="jdbc:mysql://*.*.*.*"
167     maxActive="200"/>
168
169 JDBC
170   
171  ##########restart tomcat
172  /data1/apache-tomcat-5.5.31/bin/shutdown.sh
173  sleep 5
174  /data1/apache-tomcat-5.5.31/bin/startup.sh
175   
176  ########查看效果:
177  sleep 5
178  curl  127.0.0.1/test1.jsp
179  curl  127.0.0.1/test1.jsp |grep  Hello   && echo  "Completed"
180  #########Add auto start开机自启动
181  sed -i '2a source /etc/profile' /data1/apache-tomcat-5.5.31/bin/startup.sh
182  echo  "/data1/apache-tomcat-5.5.31//bin/startup.sh" >> /etc/rc.local
183    
184  #########setting firewall
185 #sed -i '/--dport 22 -j ACCEPT/a\-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT'  /etc/sysconfig/iptables
186 #/etc/init.d/iptables restart
187

你可能感兴趣的:(shell 脚本安装tomcat)