CentOS Learning Note--tomcat installation

Source: Internet
Author: User

Tomcat installation

It's often easy to configure Tomcat, but it's not that easy to build a multi-user, multi-service Java Virtual host. One of the biggest problems is Tomcat execution permissions. The normal way to configure Tomcat is to run as root Super Administrator, obviously, this is very dangerous, it is conceivable, one but the site is hung horse, your entire server can be hacker control. and by compiling or online (such as the Redhat series of Yum, Debian series Apt-get) installation, a server can only have a Tomcat service, if you put multiple sites into the same Tomcat service, One but the problem of one site caused the Tomcat service to be stuck, then all the Web sites on the server could not be opened, unable to meet the needs of each website program exclusive Tomcat. To solve these problems, we need to configure Tomcat to run as specified, and any number of Tomcat services can be installed on a single server.

Test machine Environment:

VMware Workstation 10 virtual machines

Memory: 1G

Linux version: CentOS MINIMALCD 6.5

Java:java_home=/opt/jdk

First, configure the JDK environment on the Linux system (CentOS learning note--jdk installation).

Assume that you have installed the JDK development environment correctly on a Linux system and that the JDK is installed in:/opt/jdk/

Download and unzip the latest version of tomcat,http://tomcat.apache.org, download it (I'm down to apache-tomcat-6.0.41.tar.gz) and put it in the/opt/directory of the Linux system. Run the command decompression (and rename the extracted directory to tomcat):

Tar xzvf apache-tomcat-6.0.41. TAR.GZMV Apache-tomcat-6.0.41/tomcat

Third, compile and install Tomcat Daemon Service waiting program:

cd/opt/tomcat/bin/tar xvzf commons-daemon-native.tar.gz
1, after decompression will generate a COMMONS-DAEMON-1.0.15-NATIVE-SRC directory, CD to this directory of the Linux subdirectory:
CD Commons-daemon-1.0.10-native-src/unix
2. Note: Install GCC (the default mini version does not have GCC installed)
Yum-y Install GCC
3. Perform the compilation configuration
./Configure  # (Note: A compilation tool such as MAKE,GCC needs to be installed first). /configure--WITH-JAVA=/OPT/JDK If the prompt does not have a JDK, use this command. The main Java directory is not written to the system directory
4, after the completion of the operation will prompt the following information to explain the success of the operation:
... All do ** *"make"
5. Execute Make:
Make
6. After doing make, a jsvc file is generated and copied to the Tomcat bin directory.
CP jsvc/opt/tomcat/bin/

7, in the Tomcat/bin directory there is a daemon.sh this file is to start and close the Tomcat service waiting program.

Note: Some previous versions of Tomcat, such as Tomcat 6.0.x, may not have this file, in fact this file is placed in commons-daemon-x.x.x-native-src/unix/samples/ tomcat7.sh here (this directory also has a tomcat5.sh), but the new version of Tomcat moved it to the bin directory, and named Daemon.sh. So, if you're using Tomcat 6, copy the tomcat7.sh file to the bin directory and name it daemon.sh.

8. Modify the daemon environment variable:

Edit it with a text editor (vi or Emacs, etc.) and find a configuration segment similar to the following:

" . $TOMCAT _user " = . && tomcat_user=TOMCAT#  Set java_home to working JDK or JRE#  java_home=/ opt/jdk-1.6.0.22

9, modify the Tomcat_user=tomcat for you to specify the identity of the Linux account user name, here Specify the user name Tomcat.

and put java_home= ... The previous comment (the "#" number) is removed and set to the JDK's installation directory path, and finally, the modified configuration section becomes as follows:

" . $TOMCAT _user " = . && tomcat_user=TOMCAT#  Set java_home to working JDK or JREjava_home=/opt/jdk
10. Now modify the owner of the/opt/tomcat directory to Tomcat (that is, the Linux account you want to specify as running):
# create a Tomcat user without a home directory chsh tomcat-s/sbin/nologin  # Disable the Tomcat login operation, similar to the Windows System account Chown-r Tomcat/opt/tomcat   # change all files under/opt/tomcat to the same owner as the Tomcat user
11. Add the appropriate X-permission bits for the *.sh in the tomcat/bin/directory:
chmod +x/opt/tomcat/bin/*.sh
12, now, you can test whether the daemon can start the operation, the starting mode is as follows:
/opt/tomcat/bin/daemon.sh  start Curl http://localhost:8080   # Test if it starts

(If there is an error, focus on the *.sh in the Tomcat bin directory for x executable permissions, whether the Linux account has the Tomcat directory read and write permissions, whether there is write access to the Tomcat/logs log directory, and so on.) If there is no error, the Tomcat daemon daemon has been set up successfully.

13, this machine can access Tomcat, remote machine Access, is a firewall problem, in/etc/sysconfig/iptables add

-A input-m state--state new-m tcp-p TCP--dport 8080-j ACCEPT   #8080 is a tomcat access port
Restart Iptable
Service Iptables Restart

This will allow you to access the.

14. To stop Tomcat, the corresponding command is:

/opt/tomcat/bin/daemon.sh  Stop
15, add Tomcat for Linux services, this is simple, just need to create a soft chain to the/etc/init.d/directory can be
LN-  s  /opt/tomcat/bin/daemon.sh  /etc/init.d/tomcat
16. You can now use it to start/close tomcat:
/etc/init.d/tomcat  # startTomcat service tomcat start      # start Tomcat/etc/ Init.d/tomcat  Stop  # closeTomcat service tomcat stop       # turn off Tomcat
17, set up the Tomcat service boot, you need to add the following statement in daemon.sh:
# !/bin/sh      #这句是原文件里有的, the following 2 sentences are to be added to the #  chkconfig:2345  Description:tomcat-en Manager
18. Then run the chkconfig command to increase the Tomcat service and achieve self-booting:
Chkconfig--add  Tomcat

Restart the machine and test it.

Iv. If you want to create a Tomcat service again, simply copy the/opt/tomcat directory, for example:

Cp/opt/tomcat/opt/tomcat1

Modify the port number of the TOMCAT1 (the port number in the/opt/tomcat/opt/tomcat1/conf/server.xml cannot be duplicated with other services). Finally, start with the 8th step above and create another service.

In this way, you can create any number of Tomcat services for a single Linux server. Finally, you only need to install a front-end server (such as Nginx or Apache) and forward requests for different domain names to different Tomcat service programs.

CentOS Learning Note--tomcat installation

Related Article

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.