1 #!/bin/bash 2 #--------------------------------------------------------------------- 3 # 4 # Author : 大象无形 5 # Date : 2016-11-22 6 # Mail : wxqian_wxq@163.com 7 # Description: Install tomcat7 and JDK1.8 8 # Equipment : 9 # 1)Run this script as root10 #11 #---------------------------------------------------------------------12 13 #Script's structure14 #1)Determines if the root user15 #2)Test the machine JDK version16 #3)Determine if the file exists17 #4)install JDK 18 #5)Add the environment variable to /etc/profile19 #6)Install tomcat20 #7)Configure tomcat21 22 23 #1)Determines if the root user24 if [ "$(whoami)" != 'root' ]; then25 echo "install need root user"26 exit 127 fi28 #2)Test the machine JDK version29 for i in $(rpm -qa | grep java | grep -v grep) 30 do 31 echo "Deleting rpm -> "$i 32 rpm -e --nodeps $i 33 done 34 #3)Determine if the file exists35 file1=./jdk-8u101-linux-x64.tar.gz36 if [ ! -f "$file1" ]; then37 echo "need jdk-8u101-linux-x64.tar.gz"38 exit 139 fi40 41 file2=./apache-tomcat-7.0.73.tar.gz42 if [ ! -f "$flie2" ]; then43 echo "need apache-tomcat-7.0.73.tar.gz"44 exit 145 fi46 #4)install JDK 47 echo "========================jdk is installing======================"48 tar zxvf jdk-8u101-linux-x64.tar.gz 49 mv jdk1.8.0_101 /opt/jdk50 echo "jdk1.8.0_101 is rename jdk"51 sleep 2;52 53 #5)Add the environment variable to /etc/profile54 echo "export JAVA_HOME=/opt/jdk" >> /etc/profile55 echo "export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile56 echo "export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile57 sleep 2;58 source /etc/profile59 #6)Install tomcat60 echo "====================apache-tomcat is installing==================="61 tar zxvf apache-tomcat-7.0.73.tar.gz62 mv apache-tomcat-7.0.73 /usr/local/tomcat63 cp -p /usr/local/tomcat/bin/catalina.sh /etc/init.d/tomcat64 #7)Configure tomcat65 sed -i '1a\. /etc/init.d/functions' /etc/init.d/tomcat66 sed -i '2a\:' /etc/init.d/tomcat67 sed -i '3a\JAVA_HOME=/usr/local/jdk/' /etc/init.d/tomcat68 sed -i '4a\CATALINA_HOME=/usr/local/tomcat' /etc/init.d/tomcat69 sleep 5;70 chmod 755 /etc/init.d/tomcat71 chkconfig --add tomcat72 chkconfig tomcat on73 /usr/local/tomcat/bin/startup.sh