Install and configure Tomcat 7 in centos R6

Source: Internet
Author: User

By default, centos has installed Java (if you have to use Java 1.7, download and install Java 1.7 ):

 

Install JDK

Download the JDK from the official website, use SFTP to upload it to the server, and create a/usr/Java directory.

[Root @ srv6 Java] # CD/usr
[Root @ srv6 Java] # Mkdir Java
[Root @ srv6 Java] # CP ~ /Tmp/jdk-6u35-linux-x64.bin/usr/Java
[Root @ srv6 Java] # CD/usr/Java
[Root @ srv6 Java] # Chmod A + x jdk-6u35-linux-x64.bin
[Root @ srv6 Java] # /Jdk-6u35-linux-x64.bin

Set Environment Variables

[Root @ srv6 Java] # VI/etc/profile

Add the following lines:

Export java_home =/usr/Java/jdk1.6.0 _ 35
Export Path = $ Java_home /Bin: $ Path
Export classpath = .: $ Java_home /JRE/lib/RT. jar: $ Java_home /Lib/dt. jar: $ Java_home /Lib/tools. Jar

Then the reboot takes effect.

 

Install Tomcat

Download the Tomcat file from the official Tomcat website, upload it to the centos server using SFTP, and run md5sum to check whether the file is consistent with the MD5 file on the official Tomcat Website:

 

Decompress the package to/usr/local/tomcat. You can also select another path:

Tar-xzf apache-tomcat-7.0.29.tar.gz

Set environment variables:

Sudo VI/etc/profile

Add the following three lines:

Export java_home =/usr/lib/JVM/jre-1.6.0-openjdk.x86_64
Export tomcat_home =/usr/local/tomcat/Apache-Tomcat-7.0.30
Export jre_home =/usr/lib/JVM/jre-1.6.0-openjdk.x86_64

Reboot takes effect after saving. Use $ echo $ java_home to check whether the preceding environment variables are correct.

Start Tomcat

Run the following command to start Tomcat:

CD $ Tomcat_home
CD Bin
Sudo-E./startup. Sh

Displayed after execution:

 

The default port is port 8080. Two methods are provided to check whether Tomcat is enabled. One is to open a browser to access http: // <ip>: 8080, and the other is to enter:

Grep 8080/etc/services

If Tomcat is not started, you can view the error log:

More $ Tomcat_home /Logs/Catalina. Out

The error message here is that port 8080 is occupied: (check who occupies port 8080)

# Lsof-I: 8080

You have to modify the default Tomcat port to 9090:

Sudo vi $ Tomcat_home /CONF/server. xml

Change port 8080 to 9090:

< Connector Port = "9090" Protocol = "Https/1.1"  
Connectiontimeout
= "20000"  
Redirectport
= "8443"   />

Restart Tomcat:

Sudo-E./shutdown. Sh
Sudo-E./startup. sh: Check the listening port. 8080 is already listening.

 

 

Open the browser and access http: // <ip>: 9090. Success:

 

Click the manage app to manage the website and deploy the war file to publish a new website.

By default, there are no users. We need to add one ourselves:

 

Sudo vi $ Tomcat_home /CONF/tomcat-users.xml

Add a user:

 

< Tomcat-Users >
< Role Rolename = "Manager-Gui" />
< User Username = "Tomcat" Password = "Secret" Roles = "Manager-Gui" />
</ Tomcat-Users >

Restart tomcat.

 

Configure Tomat as a service

We can create a script to start Tomcat as a service:

[Nick @ srv6 Tomcat] # CD/etc/init. d
[Nick @ srv6 init. d] # VI Tomcat

Enter the shell script content:

# ! /Bin/bash
#
Description: Tomcat start stop restart
#
Processname: Tomcat
#
Chkconfig: 234 20 80
Java_home =/usr/lib/JVM/jre-1.6.0-openjdk.x86_64
Export java_home
Path = $ Java_home /Bin: $ Path
Export path
Catalina_home =/usr/local/tomcat/Apache-Tomcat-7.0.30

Case $1 In
Start)
Sh $ Catalina_home /Bin/startup. Sh
;;
Stop)
Sh $ Catalina_home /Bin/shutdown. Sh
;;
Restart)
Sh $ Catalina_home /Bin/shutdown. Sh
Sh $ Catalina_home /Bin/startup. Sh
;;
Esac
Exit 0

Execute the script with the following permissions:

[Nick @ srv6 init. d] # Chmod 755 Tomcat

Start the service, stop the service, and restart the service:

[Nick @ srv6 init. d] # Chkconfig -- add Tomcat
[Nick @ srv6 init. d] # Chkconfig -- level 234 Tomcat on
[Nick @ srv6 init. d] # Chkconfig -- list Tomcat
[Nick @ srv6 ~] # Service Tomcat start
[Nick @ srv6 ~] # Service Tomcat stop
[Nick @ srv6 ~] # Service Tomcat restart

 

Other content
    • Configure Tomcat memory
    • Configure Apache and tomcat for use together
    • Configure tomcat to start with a non-Root User
    • Configure tomcat to start with port 80 and non-root users

 

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.