Installation and configuration of Tomcat on Linux

Source: Internet
Author: User
Tags tomcat server

The following Linux versions are used: The Redhat Enterprise Linux 7.0 x86_64,tomcat version is tomcat-7.0.54.


1. Download the JDK and Tomcat.
Jdk:
Http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

I recommend using this method to download:

#wget--no-check-certificate--no-cookies--header "Cookie:oraclelicense=accept-securebackup-cookie"/http Download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz

Tomcat:
http://tomcat.apache.org/download-70.cgi



2.JDK installation and configuration.
(1) JDK installation
RPM Package:
# RPM-IVH jdk-7u55-linux-x64.rpm


TAR.GZ Package: Unzip
# Mkdir/usr/java
# Cd/usr/java
# tar-zxvf/software/jdk-7u55-linux-x64.tar.gz
Generate links for version upgrades
# ln-s Jdk1.7.0_55 Latest
# ln-s Latest Default


(2) Configuring environment variables
# Vi/etc/profile
Export Java_home=/usr/java/default
Export java_bin= $JAVA _home/bin
Export path= $PATH: $JAVA _home/bin
Export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
Export path= $JAVA _home/bin: $JRE _home/bin: $PATH


Make configuration effective
# Source/etc/profile


Test the JDK.
# java-version
Java Version "1.7.0_55"
Java (TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot (TM) 64-bit Server VM (build 24.55-b03, Mixed mode)


Installation of 3.Tomcat
Unzip
# Mkdir/usr/local/tomcat
# Cd/usr/local/tomcat
# tar-zxvf/software/apache-tomcat-7.0.54.tar.gz
Generate links for version upgrades
# ln-s apache-tomcat-7.0.54 Server


Start Tomcat
# Cd/usr/local/tomcat/server/bin
#./startup.sh
Using catalina_base:/usr/local/tomcat/server
Using Catalina_home:/usr/local/tomcat/server
Using Catalina_temdir:/usr/local/tomcat/server/temp
Using Jre_home:/usr/java/default
Using Class_path:/usr/local/tomcat/server/bin/bootstrap.jar:/usr/local/tomcat/server/bin/tomcat-juli.jar
Tomcat started.


Test Tomcat:
Open the firewall to allow external access
#/sbin/iptables-i input-p TCP--dport 8080-j ACCEPT
# Service Iptables Save
# Service Iptables Restart
or directly modify the file/etc/sysconfig/iptables.
# Vi/etc/sysconfig/iptables
-A input-p tcp-m tcp--dport 8080-j ACCEPT
# Service Iptables Restart
In the browser input: http://192.168.16.133:8080
As can be entered in this machine: http://localhost:8080
The page that appears Tomcat indicates that the installation was successful.


Stop Tomcat
#./shutdown.sh


4. Configure the Web Admin account
To modify the file Conf/tomcat-users.xml, add the account password to the <tomcat-users> element, you need to specify the role.
# Vi/usr/local/tomcat/server/conf/tomcat-users.xml
<tomcat-users>
<user name= "admin" password= "admin" roles= "Admin-gui,manager-gui"/>
</tomcat-users>


5. Configure the Web Access port
You can modify the file Server.xml in the Conf directory, modify the connector element (the default port for Tomcat is 8080) and need to restart the Tomcat service to take effect.
# Vi/usr/local/tomcat/server/conf/server.xml
<connector port= "protocol=" http/1.1 "connectiontimeout=" 20000 "redirectport=" 8443 "/>


6. Configure HTTPS secure connection (SSL encrypted connection)
A digital certificate and digital signature (MD5 algorithm) is required for HTTPS connections
Web site HTTPS connection first need to request a digital certificate, configure the encryption connector, browser installation certificate.
• Use Java tools Keytool to generate digital certificates
# Keytool-genkey-alias Tomcat-keyalg RSA
Generate files. KeyStore
Note: CN is the host name, localhost can be used natively
• Put the file. KeyStore into the Conf directory of the Tomcat server
# CP. keystore/usr/local/tomcat/server/conf/
• Modify the Conf/server.xml file, modify the encryption connector, add Keystorefile and Keystorepass
<connector port= "8443" protocol= "http/1.1" sslenabled= "true"
maxthreads= "Scheme=" "https" secure= "true"
Clientauth= "false" sslprotocol= "TLS"
Keystorefile= "Conf/.keystore" keystorepass= "123456"/>
• Restart Tomcat. The browser enters https://localhost:8443 access and installs the certificate.


Directory Structure of 7.Tomcat
bin//Command script file to store tomcat
conf//Storage of various configuration files for Tomcat server, mostly Server.xml
Lib//store Tomcat Server support Jar package
logs//storing log files
Temp//Storing temporary files
webapps//web application directory, external access to Web Resources storage directory
Working directory of work//tomcat


Directory structure for 8.web applications
WebApp--The directory where the Web application resides
|---html, JSP, CSS, JS files, etc.-these files are generally in the root directory of the Web application, the files under the root directory can be directly accessed by the outside world.
|---web-inf directory-java classes, JAR packages, Web configuration files exist in this directory, the outside world is not directly accessible, the WEB server is responsible for the call.
|---Classes Directory--Java class
|---lib directory--the jar package required for Java classes to run
|---web. xml file--configuration file


9. Configuration of the virtual host
Specify the virtual hostname, modify Conf/server.xml, add <context path= "/webapp" docbase= "/webapps/webapp"/>
Cases:
You must set up DNS resolution (host file or DNS system).




Mapping of 10.web applications and virtual directories.
You can modify the <Context> elements of an XML configuration file to set up mappings for Web apps and virtual directories.
conf/server.xml//Add <context path= "/webdir" docbase= "/webappdir"/&gt under the conf/context.xml//Add <Context> elements All Web apps are valid.
Conf/[enginename]/[hostname]/context.xml.default//[enginename] is generally Catalina, and all Web applications of the host [hostname] are valid.
conf/[enginename]/[hostname]///Create a file (extension XML) in the directory, and the file name is the virtual directory name. The multi-level directory uses # segmentation. <context docbase= "/webappdir"/>
The default Web App catalog can be defined as Root.xml, add <context docbase= "/webappdir"/&gt, and restart the Tomcat server.
· Meta-inf/context.xml//
The Web application can be placed in the WebApps directory for the Tomcat server to automatically map, suitable for the development environment, the actual use of the environment without automatic mapping.
If the configuration file is not modified, the Web App directory is the default Web app when it is rooted.


11.web Application Home Page (welcome file) configuration
To modify a WEB app's configuration file: [Webapp]/web-inf/web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

Source: http://blog.csdn.net/gyming/article/details/36060843

Installation and configuration of Tomcat on Linux

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.