1: The Tomcat port is forwarded using iptables because the non-root user cannot use the following port 1024
iptables-t nat-a prerouting-p tcp-m tcp--dport 80-j REDIRECT--to-ports 8080
Iptables-t nat-a prerouting-p udp-m UDP--dport 80-j REDIRECT--to-ports 8080
2: Change site permissions
Chown-r tomcat:tomcat/usr/local/tomcat/
3: Write a service startup script to specify who the Tomcat service is running
1#!/bin/Bash2 #3# Chkconfig:- the the 4# Description:tomcat start/stop/Status Script5 6 #Location of Java_home (bin files)7Java_home=/usr/java/jdk1.7. 0_798 Export Java_home9 Ten #Add Java binary files to PATH OnePath= $JAVA _home/Bin: $PATH A Export PATH - - #CATALINA_HOME is the location of the instance of Tomcat thecatalina_home=/usr/local/Tomcat - - #TOMCAT_USER is the default USER of TOMCAT -Tomcat_user=Tomcat + -#TOMCAT_USAGE is the messageifThis script was called without any options +Tomcat_usage="Usage: $ {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}" A at#SHUTDOWN_WAIT iswait Time inchSeconds forJava proccess to stop -shutdown_wait= - - - Tomcat_pid () { - Echo`PS-ef |grep$CATALINA _home |grep-Vgrep|TR-S" "|Cut-D" "-F2 ' - } in - start () { toPid=$ (tomcat_pid) + if[-N"$pid"]; Then - Echo-E"\e[00;31mtomcat is already running (PID: $pid) \e[00m" the Else * Echo-E"\e[00;32mstarting tomcat\e[00m" $ if[' user_exists $TOMCAT _user ' ="1"]; ThenPanax Notoginseng su$TOMCAT _user-c $CATALINA _home/bin/startup.SH - Else the$CATALINA _home/bin/startup.SH + fi A Status the fi +Return0 - } $ "/etc/init.d/tomcat" 111L, 2301C -,1Top $#!/bin/Bash - # -# Chkconfig:- the the the# Description:tomcat start/stop/Status Script - Wuyi #Location of Java_home (bin files) theJava_home=/usr/java/jdk1.7. 0_79 - Export Java_home Wu - #Add Java binary files to PATH AboutPath= $JAVA _home/Bin: $PATH $ Export PATH - - #CATALINA_HOME is the location of the instance of Tomcat -catalina_home=/usr/local/Tomcat A + #TOMCAT_USER is the default USER of TOMCAT theTomcat_user=Tomcat - $#TOMCAT_USAGE is the messageifThis script was called without any options theTomcat_usage="Usage: $ {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}" the the#SHUTDOWN_WAIT iswait Time inchSeconds forJava proccess to stop theshutdown_wait= - - in Tomcat_pid () { the Echo`PS-ef |grep$CATALINA _home |grep-Vgrep|TR-S" "|Cut-D" "-F2 ' the } About the start () { thePid=$ (tomcat_pid) the if[-N"$pid"]; Then + Echo-E"\e[00;31mtomcat is already running (PID: $pid) \e[00m" - Else the Echo-E"\e[00;32mstarting tomcat\e[00m"Bayi if[' user_exists $TOMCAT _user ' ="1"]; Then the su$TOMCAT _user-c $CATALINA _home/bin/startup.SH the Else -$CATALINA _home/bin/startup.SH - fi the Status the fi theReturn0 the } - the status () { thePid=$ (tomcat_pid) the if[-N"$pid"]; Then94 Echo-E"\e[00;32mtomcat is running with PID: $pid \e[00m" the Else the Echo-E"\e[00;31mtomcat is not running\e[00m" the fi98 } About - Stop () {101Pid=$ (tomcat_pid)102 if[-N"$pid"]; Then103 Echo-E"\e[00;31mstoping tomcat\e[00m"104$CATALINA _home/bin/shutdown.SH the 106Let kwait=$SHUTDOWN _wait107Count=0;108 until[ `PS-P $pid |grep-C $pid ' ='0'] || [$count-GT $kwait]109 Do the Echo-n-e"\e[00;31mwaiting for processes to exit\e[00m\n";111 Sleep 1 theLet count= $count +1;113 Done the the if[$count-gt $kwait]; Then the Echo-n-e"\n\e[00;31mkilling processes which didn ' t stop after $SHUTDOWN _wait seconds\e[00m"117 Kill-9$pid118 fi119 Else - Echo-E"\e[00;31mtomcat is not running\e[00m"121 fi122 123Return0124 } the 126 user_exists () {127 if ID-U $1>/dev/NULL 2>&1; Then - Echo "1"129 Else the Echo "0"131 fi the }133 134 Case$1 inch135 start)136 Start137 ;;138 139 stop) $ Stop141 ;;142 143 restart)144 Stop145 Start146 ;;147 148 status)149 Status Max ;;151 the*)153 Echo-e $TOMCAT _usage154 ;;155 Esac156Exit0
Run Tomcat as a normal identity