tomcat7+jdk1.8一键安装脚本

 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 root
10 #
11 #---------------------------------------------------------------------
12 
13 #Script's structure
14 #1)Determines if the root user
15 #2)Test the machine JDK version
16 #3)Determine if the file exists
17 #4)install JDK 
18 #5)Add the environment variable to /etc/profile
19 #6)Install tomcat
20 #7)Configure tomcat
21 
22 
23 #1)Determines if the root user
24 if [ "$(whoami)" != 'root' ]; then
25 echo "install need root user"
26 exit 1
27 fi
28 #2)Test the machine JDK version
29 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 exists
35 file1=./jdk-8u101-linux-x64.tar.gz
36 if [ ! -f "$file1" ]; then
37 echo "need jdk-8u101-linux-x64.tar.gz"
38 exit 1
39 fi
40 
41 file2=./apache-tomcat-7.0.73.tar.gz
42 if [ ! -f "$flie2" ]; then
43 echo "need apache-tomcat-7.0.73.tar.gz"
44 exit 1
45 fi
46 #4)install JDK 
47 echo "========================jdk is installing======================"
48 tar zxvf jdk-8u101-linux-x64.tar.gz 
49 mv jdk1.8.0_101 /opt/jdk
50 echo "jdk1.8.0_101 is rename jdk"
51 sleep 2;
52 
53 #5)Add the environment variable to /etc/profile
54 echo "export JAVA_HOME=/opt/jdk" >> /etc/profile
55 echo "export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile
56 echo "export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile
57 sleep 2;
58 source /etc/profile
59 #6)Install tomcat
60 echo "====================apache-tomcat is installing==================="
61 tar zxvf apache-tomcat-7.0.73.tar.gz
62 mv apache-tomcat-7.0.73 /usr/local/tomcat
63 cp -p /usr/local/tomcat/bin/catalina.sh /etc/init.d/tomcat
64 #7)Configure tomcat
65 sed -i '1a. /etc/init.d/functions' /etc/init.d/tomcat
66 sed -i '2a:' /etc/init.d/tomcat
67 sed -i '3aJAVA_HOME=/usr/local/jdk/' /etc/init.d/tomcat
68 sed -i '4aCATALINA_HOME=/usr/local/tomcat' /etc/init.d/tomcat
69 sleep 5;
70 chmod 755 /etc/init.d/tomcat
71 chkconfig --add tomcat
72 chkconfig tomcat on
73 /usr/local/tomcat/bin/startup.sh
原文地址:https://www.cnblogs.com/itor/p/6259421.html