Two Methods for automatically starting Tomcat in Linux

Source: Internet
Author: User
Article Title: Two Methods for automatically starting Tomcat in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

There are many ways to enable Tomcat to run automatically when the system starts. Here I will introduce two methods: one is simple and the other is complex and professional. Install JDK and Tomcat before introducing these two methods. Tomcat installation is simple. Download the binary compressed package xxx.tar.gz and use tar zxvf xxx.tar.gz-C [target]. [target] is the directory for installing Tomcat. Set the environment variables JDK_HOME and JAVA_HOME to point to the JDK installation directory.

  1. Simple Method

The bin directory under the Tomcat installation directory has two scripts respectively used to start and stop Tomcat: startup. sh, shutdown. sh. You can use these two scripts to manually start and stop the Tomcat service and perform tests after installation.

The simplest method is to use startup. sh to automatically start Tomcat and edit/etc/rc. d/rc. add content in local (assume that the JDK directory is/usr/jdk, And the Tomcat directory is/apache/tomcat)

export JDK_HOME=/usr/jdk
export JAVA_HOME=/usr/jdk
/apache/tomcat/bin/startup.sh

In this way, Tomcat can be automatically started after the system is restarted.

  2. Complicated and professional methods

The most simple method to enable Tomcat Automatic startup is introduced earlier, but it has two disadvantages. unable to specify the user who starts the Tomcat service. This will cause the Super User to run Tomcat, which has a major security risk. 2. the Tomcat service cannot be automatically stopped when the system is disabled.

In Linux, Tomcat can be started and stopped as a daemon. The jsvc tool in the project commons-daemon must be used. After Tomcat is installed, the source code of this tool {tomcat}/bin/jsvc.tar.gz is provided. Run the following command to install the tool:

Decompress: tar zxvf jsvc.tar.gz
Configuration: cd jsvc-src
Chmod + x configure
./Configure -- with-java =/usr/jdk
Compile: make
Test:./jsvc-help

The jsvc tool contains a script to start and stop the Tomcat daemon process. However, during the test, the script cannot be set to automatic start. The error message displayed is: tomcat does not support chkconfig, therefore, you can download tomcat.txt after modifying this script.

Modify the path information in the downloaded script and the user (the user must already exist) Who wants to start Tomcat, and copy the script to/etc/rc. d/init. d directory tomcat file, give the script executable permissions (chmod + x tomcat), you can use the command/etc/rc. d/init. d/tomcat start | stop to verify whether the daemon can be started and stopped normally.

Next, set the script to automatically run when the system starts and stop automatically when the system is disabled. Run the following command: chkconfig -- add tomcat

After the system is restarted, You can see Starting Tomcat ...... [OK] to complete the configuration process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.