设为首页 收藏本站
查看: 488|回复: 0

[经验分享] Ubuntu安装apache tomcat整合

[复制链接]

尚未签到

发表于 2018-5-4 09:56:20 | 显示全部楼层 |阅读模式
  #!/bin/bash
  

  

  

  ##############################################################
  ## /usr/local/src software source
  ## /opt      software
  ## /var/www    web root dir
  ##############################################################
  mkdir -p /var/www
  mkdir -p /opt
  

  ##wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.42/bin/apache-tomcat-7.0.42.tar.gz
  ##wget http://mirror.esocc.com/apache//httpd/httpd-2.4.6.tar.gz
  ##http://apr.apache.org/download.cgi
  ##wget http://apache.dataguru.cn/apr/apr-1.4.8.tar.gz
  ##wget http://apache.dataguru.cn/apr/apr-util-1.5.2.tar.gz
  ##wget http://sourceforge.net/projects/pcre/files/pcre/8.33/pcre-8.33.tar.gz
  ##wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
  ##wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/source/jk-1.2.31/tomcat-connectors-1.2.31-src.tar.gz
  ##wget http://zlib.net/zlib-1.2.8.tar.gz
  echo "##############thank you for using my shell################# "
  echo "DO you want to install httpd-2.4.6 now?"
  echo "These softwares will be installed :"
  echo "apache-tomcat-7.0.42.tar.gz"
  echo "apr-1.4.8.tar.gz"
  echo "apr-util-1.5.2.tar.gz"
  echo "bzip2-1.0.6.tar.gz"
  echo "httpd-2.4.6.tar.gz"
  echo "pcre-8.33.tar.gz"
  echo "tomcat-connectors-1.2.37-src.tar.gz"
  echo "zlib-1.2.8.tar.gz"
  echo "are you ready??"
  echo "press any key to continue."
  echo "press n to stop."
  read -p "(input y or n):" choose
  if [ "$choose" = "n" ]; then
  echo "good bye"
   exit 0
  else
  echo "start............"
  fi
  echo "==========================="
  echo "install now............."
  echo "==========================="
  

  

  

  echo "please choose no in the following table install to continue install!!!"
  read abc
  

  dpkg-reconfigure dash
  

  

  

  
  function NeedGetsystemsoftware()
  {
  echo "============================apt get files=================================="
  apt-get install -y gcc
  apt-get install -y make
  apt-get install -y perl
  apt-get install -y build-essential
  apt-get install -y libxtst-dev
  }
  

  function CheckAndDownloadFiles()
  {
  echo "============================check files=================================="
  

  if [ -s apr-1.4.8.tar.gz ]; then
   echo "apr-1.4.8.tar.gz [found]"
  else
   echo "Error: apr-1.4.8.tar.gz not found!!!download now......"
   wget -c http://apache.dataguru.cn/apr/apr-1.4.8.tar.gz
  fi
  if [ -s apache-tomcat-7.0.42.tar.gz ]; then
   echo "apache-tomcat-7.0.42.tar.gz [found]"
  else
   echo "Error: apache-tomcat-7.0.42.tar.gz not found!!!download now......"
   wget -c http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.42/bin/apache-tomcat-7.0.42.tar.gz
  fi
  if [ -s httpd-2.4.6.tar.gz ]; then
   echo "httpd-2.4.6.tar.gz [found]"
  else
   echo "Error: httpd-2.4.6.tar.gz not found!!!download now......"
   wget -c http://mirror.esocc.com/apache//httpd/httpd-2.4.6.tar.gz
  fi
  if [ -s apr-1.4.8.tar.gz ]; then
   echo "apr-util-1.5.2.tar.gz [found]"
  else
   echo "Error: apr-util-1.5.2.tar.gz not found!!!download now......"
   wget -c http://apache.dataguru.cn/apr/apr-util-1.5.2.tar.gz
  fi
  if [ -s pcre-8.33.tar.gz ]; then
   echo "pcre-8.33.tar.gz [found]"
  else
   echo "Error: pcre-8.33.tar.gz not found!!!download now......"
   wget -c http://sourceforge.net/projects/pcre/files/pcre/8.33/pcre-8.33.tar.gz
  fi
  if [ -s bzip2-1.0.6.tar.gz ]; then
   echo "bzip2-1.0.6.tar.gz [found]"
  else
   echo "Error: bzip2-1.0.6.tar.gz not found!!!download now......"
   wget -c http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
  fi
  
  if [ -s zlib-1.2.8.tar.gz ]; then
   echo "zlib-1.2.8.tar.gz [found]"
  else
   echo "Error: zlib-1.2.8.tar.gz not found!!!download now......"
   wget -c http://zlib.net/zlib-1.2.8.tar.gz
  fi
  
  
  
  if [ -s tomcat-connectors-1.2.37-src.tar.gz ]; then
   echo "tomcat-connectors-1.2.37-src.tar.gz [found]"
  else
   echo "Error: tomcat-connectors-1.2.37-src.tar.gz not found!!!download now......"
   wget -c http://mirrors.cnnic.cn/apache//tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.37-src.tar.gz
  fi
  }
  

  function Installsoftware
  {
  echo "============================install software files=================================="
  cd /usr/local/src
  ##########apache need apr and apr-util
  tar zxvf apr-1.4.8.tar.gz
  cd apr-1.4.8/
  ./configure --prefix=/opt/apr-httpd
  make&&make install
  

  cd /usr/local/src
  tar zxvf apr-util-1.5.2.tar.gz
  cd apr-util-1.5.2
  ./configure --prefix=/opt/apr-util --with-apr=/opt/apr-httpd
  make&&make install
  

  #########pcre need libbz2
  cd /usr/local/src
  tar zxvf bzip2-1.0.6.tar.gz
  cd bzip2-1.0.6
  make&&make install
  

  #########apache need pcre
  cd /usr/local/src
  tar zxvf pcre-8.33.tar.gz
  cd pcre-8.33
  ./configure --prefix=/opt/pcre-httpd --enable-pcregrep-libbz2
  make&&make install
  

  #################apache need ###########################
  cd /usr/local/src
  tar zxvf zlib-1.2.8.tar.gz
  cd zlib-1.2.8
  ./configure --prefix=/opt/zlib
  make&&make install
  

  

  cd /usr/local/src
  tar zxvf httpd-2.4.6.tar.gz
  cd httpd-2.4.6
  ./configure --prefix=/opt/apache --with-apr=/opt/apr-httpd/ --with-apr-util=/opt/apr-util/ --with-z=/opt/zlib --with-pcre=/opt/pcre-httpd --with-mpm=worker --enable-module=so --enable-mods-shared=all --enable-deflate=shared
  

  make&&make install
  

  cat >> /etc/rc.local <<EOF
  /opt/apache/bin/apachectl start
  EOF
  

  }
  

  NeedGetsystemsoftware 2>&1 | tee -a /usr/local/src/aptget.log
  CheckAndDownloadFiles 2>&1 | tee -a /usr/local/src/find.log
  Installsoftware 2>&1 | tee -a /usr/local/src/installsoft.log
  

  

  function InstallJDKTOMCAT()
  {
  echo "Install tomcat and Jdk now>>>>>>>>>>>>>"
  
  ############### install JDK  ###############
  if [ -s jdk-6u35-linux-x64.bin ]; then
  V64=1
  echo "v64 found"
  else
  V64=0
  echo "v64 no found"
  fi
  if [ -s jdk-6u45-linux-i586.bin ]; then
  V32=1
  echo "v32 found"
  else
  V32=0
  echo "v32 no found"
  fi
  

  if [ "$V64" = 0 ] && [ "$V32" = 0 ]; then
  echo "no jdk-6u found!!"
  exit 0
  fi
  

  

  

  

  echo "==========================="
  echo "instal now............."
  echo "==========================="
  

  if [ "$V64" != 0 ] && [ "$V32" != 0 ]; then
  echo "which JDK version(default 32) you want to install (32=1 64=2) ?"
  read -p "(please input 1 or 2):" JDKVER
  if [ "$JDKVER" = "" ]; then
  JDKVER=1
  fi
  echo "The version you choose is $JDKVER"
  fi
  

  cd /usr/local/src
  

  

  if [ "$JDKVER" = 1 ]; then
  chmod +x jdk-6u45-linux-i586.bin
  ./jdk-6u45-linux-i586.bin
  mv jdk1* /opt/jdk6
  fi
  

  

  if [ "$JDKVER" = 2 ]; then
  chmod +x jdk-6u35-linux-x64.bin
  ./jdk-6u35-linux-x64.bin
  mv jdk1* /opt/jdk6
  fi
  

  if [ "$V64" = 0 ] && [ "$V32" = 1 ]; then
  chmod +x jdk-6u45-linux-i586.bin
  ./jdk-6u45-linux-i586.bin
  mv jdk1* /opt/jdk6
  fi
  

  if [ "$V64" = 1 ] && [ "$V32" = 0 ]; then
  chmod +x jdk-6u35-linux-x64.bin
  ./jdk-6u35-linux-x64.bin
  mv jdk1* /opt/jdk6
  fi
  

  

  

  

  

  

  

  

  cat >> /etc/profile <<EOF
  export JAVA_HOME=/opt/jdk6
  export CLASSPATH=\$CLASSPATH:$JAVA_HOME/lib:\$JAVA_HOME/jre/lib
  export PATH=\$JAVA_HOME/bin:\$JAVA_HOME/jre/bin:\$PATH:\$HOME/bin
  EOF
  

  source /etc/profile
  

  java -version
  

  #echo "is that right please input enter to continue?"
  #read test
  

  ############### install TOMCAT  ###############
  cd /usr/local/src
  tar zxvf apache-tomcat-7.0.42.tar.gz
  mv apache-tomcat-7.0.42 /opt/tomcat
  

  cat >> /opt/tomcat/bin/startup.sh <<EOF
  

  JAVA_HOME=/opt/jdk6
  KRE_HOME=/opt/jkd6/jre
  

  EOF
  

  

  

  }
  

  InstallJDKTOMCAT 2>&1 | tee -a /usr/local/src/installjdktomcat.log
  

  function TOMCATINAPACHE()
  {
  

  BJIP=$(/sbin/ifconfig eth0|sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/p')
  echo "do you have a domain name"
  read -p "(please input your domainanme):" DOMANNAME
  if [ "$DOMANNAME" = "" ]; then
  DOMANNAME=test.com
  fi
  

  

  ########################## set apache ##################
  echo "Include conf/extra/httpd-vhosts.conf" >> /opt/apache/conf/httpd.conf
  

  mv /opt/apache/conf/extra/httpd-vhosts.conf /opt/apache/conf/extra/httpd-vhosts.conf.bak
  

  cat >> /opt/apache/conf/extra/httpd-vhosts.conf <<EOF
  <VirtualHost *:80>
  ServerAdmin webmaster@dummy-host.example.com
  DocumentRoot "/var/www"
  ServerName $DOMANNAME
  ServerAlias $BJIP
  ErrorLog "logs/$DOMANNAME-error_log"
  CustomLog "logs/$DOMANNAME-access_log" common
  </VirtualHost>
  

  #<VirtualHost *:80>
  #  ServerAdmin webmaster@dummy-host2.example.com
  #  DocumentRoot "/opt/apache/docs/dummy-host2.example.com"
  #  ServerName dummy-host2.example.com
  #  ErrorLog "logs/dummy-host2.example.com-error_log"
  #  CustomLog "logs/dummy-host2.example.com-access_log" common
  #</VirtualHost>
  EOF
  sed -i 's/\/opt\/apache\/htdocs/\/var\/www/' /opt/apache/conf/httpd.conf
  sed -i 's/ServerName www.example.com:80/& \nServerName '"$BJIP"'/' /opt/apache/conf/httpd.conf
  

  cd /usr/local/src
  tar zxvf tomcat-connectors-1.2.37-src.tar.gz
  cd tomcat-connectors-1.2.37-src/native
  ./configure --with-apxs=/opt/apache/bin/apxs --with-java-home=/opt/jdk6 --with-tomcat=/opt/tomcat
  sed -i 's/remote_ip/client_ip/g' apache-2.0/mod_jk.c
  make
  make install
  

  sed -i '/DirectoryIndex index.html/s//& index.jsp/' /opt/apache/conf/httpd.conf
  

  ###########################jk set
  cat >> /opt/apache/conf/httpd.conf <<EOF
  AddType application/x-httpd-jsp .jsp
  Include conf/extra/mod_jk.conf
  EOF
  

  cat >> /opt/apache/conf/extra/mod_jk.conf <<EOF
  

  LoadModule jk_module modules/mod_jk.so
  

  <IfModule jk_module>
  

  # We need a workers file exactly once
  # and in the global server
  JkWorkersFile conf/extra/workers.properties
  

  # Our JK error log
  # You can (and should) use rotatelogs here
  JkLogFile logs/mod_jk.log
  

  # Our JK log level (trace,debug,info,warn,error)
  JkLogLevel info
  

  # Our JK shared memory file
  JkShmFile logs/mod_jk.shm
  JkMount /*.jsp worker1
  JkmountCopy All
  # Define a new log format you can use in any CustomLog in order
  # to add mod_jk specific information to your access log.
  # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\" \"%{Set-Cookie}o\" %{pid}P %{tid}P %{JK_LB_FIRST_NAME}n %{JK_LB_LAST_NAME}n ACC %{JK_LB_LAST_ACCESSED}n ERR %{JK_LB_LAST_ERRORS}n BSY %{JK_LB_LAST_BUSY}n %{JK_LB_LAST_STATE}n %D" extended_jk
  

  

  JkWatchdogInterval 60
  

  <Location /jk-status>
  # Inside Location we can omit the URL in JkMount
  JkMount jk-status
  Order deny,allow
  Deny from all
  Allow from 127.0.0.1
  </Location>
  <Location /jk-manager>
  # Inside Location we can omit the URL in JkMount
  JkMount jk-manager
  Order deny,allow
  Deny from all
  Allow from 127.0.0.1
  </Location>
  

  

  

  </IfModule>
  

  EOF
  

  

  

  

  cat >> /opt/apache/conf/extra/workers.properties <<EOF
  worker.list=worker1
  worker.worker1.port=8009
  worker.worker1.host=localhost
  worker.worker1.type=ajp13
  worker.woker1.lbfactor=1
  EOF
  

  sed -i "s/webapps/\/var\/www/g" /opt/tomcat/conf/server.xml
  ##<Context path="" docBase="/var/www/" debug="0"/>
  

  cp -Rp /opt/tomcat/webapps/* /var/www
  mv /opt/tomcat/conf/tomcat-users.xml /opt/tomcat/conf/tomcat-users.xml.bak
  mv /opt/tomcat/conf/server.xml /opt/tomcat/conf/server.xml.bak
  cp /usr/local/src/tomcat-users.xml /opt/tomcat/conf/
  cp /usr/local/src/server.xml  /opt/tomcat/conf/
  

  }
  

  TOMCATINAPACHE 2>&1 | tee -a /usr/local/src/TOMCATapache.log
  

  function Checkinstall()
  {
  echo " "
  echo " "
  echo " "
  echo "Check your install now,please input enter to see the logs which have the key words "ERROR" "
  echo " "
  echo " "
  echo " "
  read nothing
  cat /usr/local/src/aptget.log|grep error >>Error.log
  cat /usr/local/src/find.log|grep error >>Error.log
  cat /usr/local/src/installsoft.log|grep error >>Error.log
  cat /usr/local/src/TOMCATapache.log|grep error >>Error.log
  Logs=$(cat /usr/local/src/Error.log)
  echo "$Logs"
  echo "No error? input y or n"
  read ToSee
  if [ "$ToSee" = "n" ]; then
  echo "##########################################################################"
  echo "##########    please check the Error logs         #############"
  echo "##########    /usr/local/src/Error.log          #############"
  echo "##########################################################################"
  exit 0
  else
  echo "##########################################################################"
  echo "##########    Congratulations!!!!!!!!          #############"
  echo "##########   please startup your tomcat and apache server! #############"
  echo "##########  as it is the first time use jdk please use:   #############"
  echo "##########   source /etc/profile              #############"
  echo "##########   /opt/tomcat/bin/startup.sh          #############"
  echo "##########   /opt/apache/bin/apachectl start        #############"
  echo "##########################################################################"
  echo " "
  echo "visit your website at http://\$ip to test your web server"
  echo "note: May it can not access to tomcat manager website"
  echo " "
  echo "visit website at http://\$ip:8080 to manage your tomcat server"
  echo "use the default username :admin passwd:admin"
  echo " "
  echo " "
  echo " "
  echo "note:use apt-get install mysql-server to install your mysqlserver"
  echo " "
  echo " "
  echo " "
  fi
  

  

  

  }
  

  Checkinstall 2>&1 | tee -a /usr/local/src/checkinstall.log
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-455663-1-1.html 上篇帖子: Ubuntu12.10安装Mysql数据库 下篇帖子: ubuntu 编译安装mysql 5.6.14
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表