Installation and configuration of Tomcat on RedHat Linux

Source: Internet
Author: User
Tags nginx reverse proxy

Installation and configuration of Tomcat on RedHat Linux

The following Linux versions are used: RedHat Enterprise Linux 7.0 x86_64 and Tomcat-7.0.54.

1. Download JDK and Tomcat.
Jdk:
Http://www.Oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Tomcat:
Http://tomcat.apache.org/download-70.cgi

2. install and configure jdk.
(1) jdk Installation
Rpm package:
# Rpm-ivh jdk-7u55-linux-x64.rpm

Tar.gz package: Decompress
# Mkdir/usr/java
# Cd/usr/java
# Tar-zxvf/software/jdk-7u55-linux-x64.tar.gz
Generate link for Version Upgrade
# Ln-s jdk1.7.0 _ 55 latest
# Ln-s latest default


(2) Configure 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 the configuration take effect
# Source/etc/profile


Test 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)

3. Tomcat installation
Extract
# Mkdir/usr/local/tomcat
# Cd/usr/local/tomcat
# Tar-zxvf/software/apache-tomcat-7.0.54.tar.gz
Generate link for Version Upgrade
# 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
Enter: http: // 192.168.16.20.: 8080 in the browser
For example, you can enter: http: // localhost: 8080 on the local machine.
The tomcat page indicates that the installation is successful.


Stop Tomcat
#./Shutdown. sh


4. configure a web management account
Modify the file conf/tomcat-users.xml, add the account password in 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 and modify the Connector element (Tomcat's default port is 8080). You need to restart the Tomcat service to take effect.
# Vi/usr/local/tomcat/server/conf/server. xml
<Connector port = "80" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443"/>


6. Configure https secure connections (ssl encrypted connections)
Digital Certificates and digital signatures (MD5 Algorithm) are required for https connections)
To connect to an https website, you must first apply for a digital certificate, configure the encrypted connector, and install the certificate in the browser.
· Use the java tool keytool to generate a digital certificate
# Keytool-genkey-alias tomcat-keyalg RSA
Generate file. keystore
Note: CN is the host name, And localhost is available on the local machine.
· Place the file. keystore In the conf directory of the Tomcat server
# Cp. keystore/usr/local/tomcat/server/conf/
· Modify the conf/server. xml file, modify the encryption connector, and add keystoreFile and keystorePass
<Connector port = "8443" protocol = "HTTP/1.1" SSLEnabled = "true"
MaxThreads = "150" scheme = "https" secure = "true"
ClientAuth = "false" sslProtocol = "TLS"
KeystoreFile = "conf/. keystore" keystorePass = "123456"/>
· Restart tomcat. Enter https: // localhost: 8443 in the browser and install the certificate.


7. Tomcat directory structure
· Bin // store the Tomcat Command Script File
· Conf // stores various configuration files of the Tomcat server, mainly server. xml
· Lib // store the jar packages supported by the Tomcat server
· Logs // store log files
· Temp // store temporary files
· Webapps // The directory where the web application is located, and the directory where external web resources are stored
· Work // Tomcat working directory


8. directory structure of web Applications
Webapp-web application directory
| --- Html, jsp, css, and js files-these files are generally stored in the root directory of the web application and can be directly accessed from outside.
| --- WEB-INF directory -- java class, jar package, web configuration file under this directory, external access is not allowed, the web server is responsible for calling.
| --- Classes directory -- java class
| --- Lib directory -- jar package required for java class running
| --- Web. xml file -- web application configuration file

9. VM Configuration
Specify the virtual host name, modify conf/server. xml, and add the <Host name = "hostname. domainname" appBase = "/webapps">
<Context path = "/webapp" docBase = "/webapps/webapp"/>
</Host>
Example:
<Host name = "www.bkjia.com" appBase = "/webapps">
</Host>
<Host name = "mail.bkjia.com" appBase = "/mailapps">
</Host>
DNS resolution (host file or DNS System) must be set ).

10. ing between web applications and virtual directories.
You can modify the <Context> element of the xml configuration file to set the web ing between web applications and virtual directories.
· Conf/server. xml // Add <Context path = "/webdir" docBase = "/webappdir"/> to the · Conf/context. xml // Add the <Context> element. All web applications 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 (xml extension) in the directory. The file name is the virtual directory name. multi-level directory use # segmentation. <Context docBase = "/webappdir"/>
// The default web application directory can be defined as ROOT. xml. Add <Context docBase = "/webappdir"/> and restart the Tomcat server.
· META-INF/context. xml //
You can place web applications in the webapps directory to allow the Tomcat server to map automatically. This is applicable to the development environment and does not require automatic ing in the actual application environment.
If the configuration file is not modified, the default web application is used when the web application directory is ROOT.

11. configuration of the web application homepage (welcome file)
Modify the web application 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>

Load Balancing between Apache and multiple Tomcat clusters in Linux

Nginx Tomcat Cluster load balancing solution notes

Instance details Tomcat component installation + Nginx reverse proxy Tomcat + Apache use mod_jk and mod_proxy Reverse Proxy and load balancing

Deploy a log server using Rsyslog + LogAnalyzer + MySQL in CentOS 6.5

Build an Apache + Tomcat environment (JK deployment process)

Tomcat details: click here
Tomcat: click here

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.