Search code examples
javalinuxtomcatlog4jtomcat6

Unable to start or Stop Tomcat on Linux Server


I'm unable to start or stop Tomcat on Linux. As the server is new and first time we are running it , shutdown.sh throws an exception below though I have placed the log4j.properties:

/tomcat/V6.0/bin$ ./shutdown.sh
After calling setenv.sh: Using JAVA_HOME:       
After calling setenv.sh: Using JRE_HOME:       /usr/java/jdk1.8.0_91/jre
After cygwin: Using JAVA_HOME:       
After cygwin: Using JRE_HOME:       /usr/java/jdk1.8.0_91/jre
log4j:WARN No appenders could be found for logger (org.apache.tomcat.util.digester.Digester.sax).
log4j:WARN Please initialize the log4j system properly.

But when I run the startup.sh it doesnot show anything on console saying tomcat started. Only the below lines have been printed.

/tomcat/V6.0/bin$ ./startup.sh
After calling setenv.sh: Using JAVA_HOME:       
After calling setenv.sh: Using JRE_HOME:       /usr/java/jdk1.8.0_91/jre
After cygwin: Using JAVA_HOME:       
After cygwin: Using JRE_HOME:       /usr/java/jdk1.8.0_91/jre

Using localhost when I try launching the tomcat it throws 404 error Please can anyone help me on this?


Solution

  • I will really suggest to upgrade tomcat, if it is mandatory then someone has to take the risk of the implementation, with that said lets list how to validate tomcat properly.

    1. Review the tomcat 6 versions that you really need, this is the list of tomcat 6 releases, if you are force to use tomcat 6.x then try to use the latest release in this case I would recommend v.6.0.53
    2. Unzip the tomcat into your disk
    3. Make sure that you give the execution permission to the .sh scripts that are in bin folder. For example if you are located at the bin folder of tomcat apache-tomcat-6.0.53/bin$> then you can run chmod +x ./*.sh
    4. Make sure that JAVA_HOME is set
    5. In your bin folder run the startup.sh script like this ./startup.sh
    6. Check if tomcat is running with this command ps -ef | grep tomcat it will list the running process that are related to tomcat.
    7. Try to stop tomcat, in your bin folder run the shutdown script ./shutdow.sh
    8. Check if tomcat is running with this command ps -ef | grep tomcat, if you don't get listed the tomcat process then it is stopped successfully otherwise you can force the shutdown, using kill - 9 <process-number> so for example when you run ps -ef | grep tomcat

    Sample output of ps-ef command

    servername    4328     1  0 21:43 pts/1    00:00:07 /usr/var/jdk1.8.0_111/bin/java -Djava.util.logging.config.file=... tomcat
    servername    4497  4117  0 22:07 pts/1    00:00:00 grep --color=auto tomcat
    

    Then stop tomcat with this kill -9 4328 it is because 4328 is the process number that you get from the ps -ef output.

    How access tomcat without port number?

    If you need to access your tomcat server through the browser with a default port number then configure the connector to http default port number 80. Please see the following instructions:

    1. Go to apache-tomcat-6.0.53/conf folder
    2. Open server.xml file
    3. Go to Connector configuration, by default it look like this:

    Default connector configuration

    <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
    
    1. Change the port number to 80, like this:

    Connector configuration with port number 80

    <Connector port="80" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />
    
    1. Restart tomcat. One observation here, only for linux. The first 1024 ports are restricted to root user, with this approach you can start tomcat only with root user. There is another solution for this with iptables, only in a case when you have to start tomcat without root user, see this post if you need to use port 80 and start tomcat without root user redirect-port-80-to-8080-and-make-it-work-on-local