Linux Tomcat Introduction
background:
I've done javaweb development before, knowing that the Windows Eclipse development tool comes with a Tomcat service running JSP pages and SERVERLT for developers to debug the program, but how to use the Tomcat service in a real production environment is a problem. After learning about the Linux tomcat, you will learn the records with this.
What is tomcat:
Tomcat Server is a free open source Web application server, belongs to the Lightweight application server , in small and medium-sized systems and concurrent access users are not widely used, is the first choice to develop and debug JSP programs.
To install Tomcat:
Before installing Tomcat, you need to know that Tomcat is written in the Java language itself, so to use Tomcat you have to install the Java environment, including JAVA-VERSION-OPENJDK, Java-version-openjdk-headless,java-version-openjdk-devel. The simplest way is to install it with Yum so that he can install these interdependent packages together.
The first step:
Install Java environment: Yum install Java
Step Two:
Installing Tomcat:yum Install Tomcat
Installation related management tools: Yum install tomcat-lib Tomcat-admin-webapps tomcat-webapps Tomcat-docs-webapp
This way, Tomcat is ready to install. To facilitate our use of Tomcat, we need to configure the environment variables.
Create Environment Profile:/etc/profile.d/tomcat.sh
Write: Export path=/usr/local/tomcat/bin: $PATH;
Save the profile to take effect after the exit:. /etc/profile.d/tomcat.sh
about Tomcat:
Is the directory structure of Tomcat:
650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/05/0745819fea51697af479febb41fedf98.png "title=" 1.png " alt= "0745819fea51697af479febb41fedf98.png"/>
Directory Structure Description:
Bin: Scripts, and classes used at startup;
Conf: configuration file directory;
LIB: library file, Java class Library, jar;
Logs: Log file directory;
Temp: Temp file directory;
default directory for Webapps:webapp;
Work: Working directory, storing compiled bytecode files;
You can then start the Tomcat service, which will have three listening ports when you turn on the service:
8080: Normal service Listening port, is also our normal access to use the port, walking is the http/1.1 protocol;
8009: Go is the ajp/1.3 agreement;
8005: Only receive shutdown, only listen to 127.0.0.1 address, that is, the local access;
650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/05/222bc4e861644ec89508bee315274ee0.png "title=" 2.png " alt= "222bc4e861644ec89508bee315274ee0.png"/>
the configuration file for Tomcat consists of:
Server.xml:master configuration file;
Web. xml:Each webapp is only "deployed" to be accessed, and its deployment is typically defined by Web. XML and is stored in the web-inf/directory, which provides default deployment-related configuration for all WebApps;
context.xml:A configuration file that can be used by each webapp, which is typically defined by a dedicated profile context.xml, which is stored in the web-inf/directory; This file provides default configuration for all WebApps;
Tomcat-users.xml:User authenticated account and password file; role, user; This file is loaded into memory when Tomcat is started;
Catalina.policy:Use the-security option to set the security policy for Tomcat when you start Tomcat;
catalina.properties:A definition file for the Java attribute that sets the class loader path and some parameters related to tuning the JVM;
logging.properties:Log system-related configuration;
core components of Tomcat: Server.xml
<Server>
<Service>
<connector/>
<connector/>
...
<Engine>
<Host>
<Context/>
<Context/>
...
</Host>
<Host>
...
</Host>
...
</Engine>
</Service>
</Server>
Each component is implemented by a Java "class" that can be broadly divided into the following types:
Top-level components: Server
Service Class components: Services
Connector components: HTTP, HTTPS, AJP (Apache Jserv Protocol)
Container class: Engine, Host, Context
Nested classes: Valve, logger, realm, loader, manager, ...
Cluster class components: Listener, cluster, ...
common component configurations for Tomcat:
Server: Represents Tomcat instance, which is a Java process that appears, listening on port 8005, receiving only "SHUTDOWN". The ports that each server listens on cannot be the same, so when multiple instances are started on the same physical host, it is necessary to modify their listening ports to different ports;
Service: Used to implement the association of one or more connector components to an engine component;
Connector components:
In charge of receiving requests, there are three kinds of HTTP/HTTPS/AJP common;
Requests to enter Tomcat fall into two categories:
(1) Standalone: The request comes from the client browser;
(2) by other Web server counter-generation: from the front-end of the anti-generation server;
Nginx--HTTP connector----Tomcat
HTTPD (Proxy_http_module)--HTTP connector---Tomcat
HTTPD (Proxy_ajp_module)--AJP connector--Tomcat
HTTPD (MOD_JK)--AJP connector--Tomcat
Property:
port= "8080"
Protocol= "http/1.1"
connectiontimeout= "20000"
Address: The IP addresses of the listening, the default is the native all available addresses;
MaxThreads: Maximum number of concurrent connections, default is 200;
Enablelookups: Whether the DNS query function is enabled;
Acceptcount: The maximum length of the wait queue;
Engine component: The servlet instance, the Servlet engine, which can define the site within one or more host components, usually by Defaulthost to define the default virtual host;
Property:
Name= Name
defaulthost= "localhost"//default host name
Host components: Hosts or virtual hosts that are used inside the engine to receive requests and handle them appropriately, for example:
Unpackwars= "true" autodeploy= "true" >
</Host>
Common Property Descriptions:
(1) AppBase: The default directory of WebApps for this host, which is the directory of the non-archived Web application or the path to the archived war file directory; You can use a relative path based on the path defined by the $catalina_base variable;
(2) Autodeploy: When Tomcat is in the running state, it is automatically deployed to Tomcat when a webapp is placed in a directory defined by AppBase;
Example:
Context Components:
Example:
<context path= "/path" docbase= "/path/to/somedir" reloadable= "/>
Valve components:
<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs" prefix= "Localhost_access_log" suffix= ". txt" pattern= "%h%l%u%t "%r" %s%b "/>
There are several types of valve:
Define access logs: Org.apache.catalina.valves.AccessLogValve
Define access control: Org.apache.catalina.valves.RemoteAddrValve
<valve classname= "Org.apache.catalina.valves.RemoteAddrValve" deny= "172\.16\.100\.67"/>
the organization structure of JSP WebApp:
/usr/share/tomcat/webapps/root: root directory of WebApps
index.jsp: Homepage;
...
web-inf/: The private resource path of the current webapp; typically used to store the Web. XML and Context.xml configuration files for the current webapp;
meta-inf/: similar to web-inf/;
Classes/: Class file, the class provided by the current WebApp;
lib/: Class file, the class currently provided by WebApp, is packaged as a jar format;
related Operations for deployment (deploy) WebApp:
Deploy: Place the source files of the WebApp in the target directory (the Web program file directory), configure the Tomcat server to access this webapp based on the paths defined in the Web. XML and Context.xml files, and pass their class-specific classes and dependent classes through class Loader loading to the JVM;
There are two ways of deploying:
Automatic deployment: auto Deploy;
Manual deployment:
Cold deployment: Copy the WebApp to the specified location before starting Tomcat;
Hot deployment: Deploy without stopping Tomcat;
Deployment tools: Manager, Ant script, TCD (Tomcat client deployer), etc.;
Undeploy: Remove (reverse deploy), Stop WebApp, and uninstall WebApp from the Tomcat instance;
Start: Start the WebApp in the stopped state;
Stop: Stops WebApp, does not provide service to the user, and its class is still on the JVM;
Redeploy: redeployment;
Linux Tomcat Introduction