鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 服务器相关 > 批处理 > >

自动安装JDK和Tomcat的shell脚本

来源:互联网 作者:佚名 时间:2016-03-03 12:13
Auto Install JDK、tomcat and they connector. #执行这个脚本需要在root家目录下放好JDK、tomcat、的tar.gz源码包, #以及已经执行过的jdk(本人无法做到在jdk执行时输入yes和空格,所以这一步骤需要手动做。 #tomcat安装到/data1/apache-tomcat-5.5.31/,
Auto Install JDK、tomcat and they connector. #执行这个脚本需要在root家目录下放好JDK、tomcat、的tar.gz源码包, #以及已经执行过的jdk(本人无法做到在jdk执行时输入yes和空格,所以这一步骤需要手动做。 #tomcat安装到/data1/apache-tomcat-5.5.31/,已设置环境变量。 #JDK在/usr/java,已设置环境变量。 #jsp页面的存放目录为“/web”,且该目录已经有了一个叫做test1.jsp的测试文件, #可以通过http://ip/test1.jsp进行访问。 #apache和tomcat开机自启动。 #防火墙80端口打开。 <无>
#!/bin/bash
#Auto Install JDK、tomcat and they connector.
#执行这个脚本需要在root家目录下放好JDK、tomcat、的tar.gz源码包,
#以及已经执行过的jdk(本人无法做到在jdk执行时输入yes和空格,所以这一步骤需要手动做。
#tomcat安装到/data1/apache-tomcat-5.5.31/,已设置环境变量。
#JDK在/usr/java,已设置环境变量。
#jsp页面的存放目录为“/web”,且该目录已经有了一个叫做test1.jsp的测试文件,
#可以通过http://ip/test1.jsp进行访问。
#apache和tomcat开机自启动。
#防火墙80端口打开。
#Author
#       20101117 yuchao1@staff.sina.com.cn       Version 1.0

##################
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
########Check software development environment.
         #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
         if  [ "$?" != 0 ] ;
         then
         echo "Please check your need software"
         exit 0
         fi
 #        echo "proceed"
 ############Check install files:apache tomcat JDK tomcat-connectors
./jdk-6u22-linux-i586.bin
 ##########首先给JDK文件当前用户可执行的权限,如chmod 700 jdk* ,然后执行该文件,读取许可协议后输入“yes”即可安装,安装完成后最后在当前目录获得一个jdk目录。
 if [ ! -e apache-tomcat-6.0.*.tar* ];then
 echo "I cann't find tomcat source file."
 exit 0
 fi
 if [ ! -d jdk1.6* ];then
 echo "I cann't find JDK directory."
 exit 0
 fi
 ############Install and setup JAVA environment
  mv jdk1.6*  /usr/java
  cat >> /etc/profile  << EFF
########################################
 JAVA_HOME=/usr/java
 JRE_HOME=\$JAVA_HOME/jre
 CLASSPATH=:\$JAVA_HOME/lib:\$JRE_HOME/lib
 PATH=\$JAVA_HOME/bin:\$JRE_HOME/bin:\$PATH
 export JAVA_HOME JRE_HOME CLASSPATH PATH
########################################
EFF
 source /etc/profile
 #######################

 java -version
  if  [ "$?" != 0 ] ;
         then
         echo "I cann't set java path."
         exit 0
         fi
###########Install Tomcat,and setup tomcat environment。
  cd -
  tar zxvf apache-tomcat*
  mv apache-tomcat-6.0.29/  /data1/apache-tomcat-6.0.29/
 cat >> /etc/profile << TTD
 TOMCAT_HOME=/data1/apache-tomcat-6.0.29/
 PATH=\$PATH:\$TOMCAT_HOME/bin/:/usr/local/apache2/bin:
 export JAVA_HOME JRE_HOME CLASSPATH PATH TOMCAT_HOME
TTD
 source /etc/profile
############Start Tomcat
 sh  /data1/apache-tomcat-5.5.31/bin/startup.sh 
 sleep 5
 curl  127.0.0.1:8080  |grep   "Thanks for using Tomcat"
  if  [ "$?" != 0 ] ;
         then
         echo "I think install tomcat is unfinished  ."
         exit 0
         fi

 ################Set tomcat
 ########Creat Catalina directory and  configuration file.
 mkdir -p $TOMCAT_HOME/conf/Catalina/localhost
 cat >> $TOMCAT_HOME/conf/Catalina/localhost/ROOT.xml << DDQ
  <Context   path="/"   docBase="/web"   debug="0"  workDir="/tmp"   reloadable="false"/> 
DDQ
 ##########modify server.xml
 #sed -i 's/appBase="webapps"/appBase="\/web"/' /data1/apache-tomcat-5.5.31//conf/server.xml 
 #sed -i '/xmlValidation="false" xmlNamespaceAware="false">/a\<Context   path="/"   docBase="/web"   debug="0"  workDir="/tmp"   reloadable="false"/>'  /data1/apache-tomcat-5.5.31//conf/server.xml
 #########################################################################################
 cat >> /data1/apache-tomcat-5.5.31/conf/server.xml << SERVER
 <?xml version="1.0" encoding="ISO8859-1"?>
<Server>
  <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <GlobalNamingResources>
    <Environment
      name="simpleValue"
      type="java.lang.Integer"
      value="30"/>
    <Resource
      auth="Container"
      description="User database that can be updated and saved"
      name="UserDatabase"
      type="org.apache.catalina.UserDatabase"
      pathname="conf/tomcat-users.xml"
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
    <Resource
      name="JDBC/vpayBank"
      type="javax.sql.DataSource"
      driverClassName="com.mysql.jdbc.Driver"
      password="asdf1234"
      maxIdle="5"
      maxWait="5000"
      username="pay"
      url="jdbc:mysql://*.*.*.*"
      maxActive="200"/>
  </GlobalNamingResources>
  <Service
      name="Catalina">
    <Connector
        port="80"
        redirectPort="8443"
        connectionTimeout="30000"
        maxSpareThreads="75"
        maxThreads="150"
        URIEncoding="UTF-8"
        minSpareThreads="25">
    </Connector>
    <Connector
        port="8009"
        redirectPort="8443"
        protocol="AJP/1.3">
    </Connector>
    <Engine
        defaultHost="localhost"
        name="Catalina">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
      <Host
          appBase="webapps"
          name="localhost">
      </Host>
    </Engine>
  </Service>
</Server>
SERVER
#creat test website.
 mkdir /web
 cat >>/web/test1.jsp<< WEB
 <%@ page contentType="text/html;charset=gbk" %>
 <%
 String str1="Hello World!";
 out.println(str1);
 %>
WEB
 #######################
#JDBC	配置
cat >>/data1/apache-tomcat-5.5.31/conf/Catalina/localhost/vpayBank.xml<< JDBC
<?xml version="1.0" encoding="ISO8859-1"?>
<Context>
  <Resource
    name="JDBC/Test"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    password="12345"
    maxIdle="5"
    maxWait="5000"
    username="pay"
    url="jdbc:mysql://*.*.*.*"
    maxActive="200"/>
</Context>
JDBC

 ##########restart tomcat
 /data1/apache-tomcat-5.5.31/bin/shutdown.sh
 sleep 5
 /data1/apache-tomcat-5.5.31/bin/startup.sh

 ########查看效果:
 sleep 5
 curl  127.0.0.1/test1.jsp
 curl  127.0.0.1/test1.jsp |grep  Hello   && echo  "Completed"
 #########Add auto start开机自启动
 sed -i '2a source /etc/profile' /data1/apache-tomcat-5.5.31/bin/startup.sh
 echo  "/data1/apache-tomcat-5.5.31//bin/startup.sh" >> /etc/rc.local
 
 #########setting firewall
#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
#/etc/init.d/iptables restart
 
 
网友评论
<