Method of starting Tomcat under Linux


Tomcat is started randomly, so you should manually start Tomcat when you start the server, otherwise you can’t access it (it is said on the Internet that it can be set to start with the server, but I won’t know yet…)

1: Find Tomcat installation path

[ [email protected] ~]#CD.. (return to previous directory)
[ [email protected] /]# ls         (list all files in this directory)
bin   dev  home  lib64       media  mnt  opt   root  selinux  sys       tmp  var
boot  etc  lib   lost+found  misc   net  proc  sbin  srv      tftpboot  usr
[ [email protected] /]# cd var    (open this folder)
[ [email protected] var]# ls      (view a list of this file)
account   crash  empty  gdm       local  mail   opt       run    tux
arpwatch  cvs    ftp    kerberos  lock   named  preserve  spool  www
cache     db     games  lib       log    nis    racoon    tmp    yp
(it seems that it is not in the VaR folder and can only return the upper level directory)
[[email protected] var]# cd ..
[[email protected] /]# cd usr
[[email protected] usr]# ls


etc      java      lib64    sbin   tmp
apache-tomcat-7.0.14.tar  games    kerberos  libexec  share  tomcat7.0
bin                       include  lib       local    src    X11R6
[ [email protected] usr]# cd tomcat7.0    (open the Tomcat 7.0 folder)
[[email protected] tomcat7.0]# ls
bin    hsperfdata_root  LICENSE  NOTICE         RUNNING.txt  webapps
conf  lib              logs     RELEASE-NOTES  temp         work
[[email protected] tomcat7.0]# cd bin
[[email protected] bin]# ls
bootstrap.jar         tomcat-native.tar.gz
catalina.bat                  cpappend.bat      shutdown.bat     tool-wrapper.bat                   d:      
catalina-tasks.xml            digest.bat        startup.bat      version.bat
commons-daemon-native.tar.gz  setclasspath.bat  tomcat-juli.jar
[ [email protected] Bin]#. / (current directory, what is it used for here, not clear…)
-bash: ./: is a directory
[ [email protected] bin]# ./       (start Tomcat)
Using CATALINA_BASE:   /usr/tomcat7.0
Using CATALINA_HOME:   /usr/tomcat7.0
Using CATALINA_TMPDIR: /usr/tomcat7.0
Using JRE_HOME:        /usr/java/jdk1.6.0_24
Using CLASSPATH:       /usr/tomcat7.0/bin/bootstrap.jar:/usr/tomcat7.0/bin/tomcat-juli.jar

Start successful

2: View Tomcat logs

[[email protected] bin]# cd ..
[[email protected] tomcat7.0]# ls
bin   hsperfdata_root  LICENSE  NOTICE         RUNNING.txt  webapps
conf  lib              logs      RELEASE-NOTES  temp         work
[ [email protected] tomcat7.0]# cd logs   (open log folder)
[[email protected] logs]# ls
catalina.2011-05-30.log      localhost.2011-06-28.log
catalina.out                 localhost_access_log.2011-06-27.txt
host-manager.2011-05-30.log  localhost_access_log.2011-07-07.txt
(no more useless)
[ [email protected] logs]# tail -f catalina.out    (view the log file of Tomcat)

PS: startup, shutdown and killing process of Tomcat under Linux

cd /java/tomcat 
Bin / # start Tomcat  
Bin / # stop Tomcat  
Tail – f logs / catalina.out # see the console output of Tomcat;  
#See if Tomcat is already running  
ps -ef |grep tomcat 
#If yes, use kill;  
Kill – 9 PID #pid is the corresponding process number  
For example, the output of PS – EF | grep Tomcat is as follows  
sun 5144 1 0 10:21 pts/1 00:00:06 /java/jdk/bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/java/tomcat/common/endorsed -classpath :/java/tomcat/bin/bootstrap.jar:/java/tomcat/bin/commons-logging-api.jar -Dcatalina.base=/java/tomcat -Dcatalina.home=/java/tomcat org.apache.catalina.startup.Bootstrap start 
Then 5144 is the process number PID = 5144  
Kill – 9 5144 can completely kill Tomcat  
#Directly view the process PID of the specified port  
netstat -anp|grep 9217 
#The result is TCP         0       0 :::9217                      :::*                       

LISTEN      26127/java 
#26127 is the PID of the Tomcat process on port 9217, and then the process can be killed  
kill -9 26127 
#Then start Tomcat