Tomcat organization memo

Source: Internet
Author: User
Tags ssl connection

Tomcat is divided into two components, one is can contain other components of the container components: C-H-E-S (ChEss), non-container components are included in the container components, the most important of a non-container components: connector

1. The server tag is not a component. Do not confuse it into the S component. The service component contains child components to form a complete server instance.
2. a JSP/servlet container refers to an engine component, and a server refers to a service component.
3. per project per Tomcat requires many servers. Therefore, small and medium-sized companies usually configure multiple s components or H components.
1) Configure multiple H components:
You can configure different server instances. The advantage is that each instance is separately configured to use a connection Buffer Queue such as connector. The disadvantage is that the configuration is troublesome.
If you want to share ctor, you can define multiple hosts in a service. Each host component can represent different domain names. In this way, all hosts can share the same connector.
You can define multiple applications under the virtual host. for example, if you want to add a second-level domain name "a.abc.com" to an abc.com domain name, you are expected to access a project in the "D: \ A" folder through this second-level domain name, "127.0.0.1 abc.com" has been added to the system's "hosts" table, and "server. add in XML
<Host name = "a.abc.com" unpackwars = "true" autodeploy = "true"
Xmlvalidation = "false" xmlnamespaceaware = "false" appbase = "webapps">
<Context Path = "app" docbase = "D: \ A"/>
</Host>
Run Tomcat and access a.abc.com for the expected effect (that is, the webpage stored under "D: \)
You can specify a.abc.com 127.0.0.1 In the DNS. If no IP address is specified, Tomcat does not know the IP address of the host, and the configured default host (localhost) is used for processing.
2) Configure multiple s components.
Another configuration is to use multiple S (service) components. You can configure the ctor of different ports for each s component. For example, configure the HTTP ctor of HTTP protocol to configure another port 8081.

4. Meaning of reloadable = true

1) reloadable = true indicates "hot" deployment. If you do not do anything about the client, you need to manually deploy the client on the console and click the deploy button to redeploy.

1.1) the "auto reloading enabled" in WTP corresponds to the reloadable value in server. xml.

1.2) WTP is in debug mode (Note: run mode is not supported). You can remove the "auto reloading enabled" option in the module section of the tomcat configuration interface. Because Tomcat does not need to redeploy the entire app to modify a Java class unless the servlet is modified, which can save some time when the application is large. This is confusing because the value is usually true when the application is small.




2) Publish configuration in servers in WTP: decide which method to deploy. One is to package it into the webapps directory of Tomcat deployed by war or ear, and the other is to deploy it directly by expanding the directory. This parameter has nothing to do with hot deployment.

Two
New options which affect publishing are now available in the server
Options section of the Tomcat server editor. The Tomcat server must be
5.0.x or later for these
Options to be enabled.TheServe modules without publishingOption

Does what it says.Web content will be served directly from the "webcontent"FolderOf the dynamic Web project.A customized context is
Used to make the project's dependencies available in the web
Application's classloader.Publish module contexts to separate XML filesOption
Will publish contexts using the preferred method of separate XML files
Under the "CONF/Catalina/localhost" directory,
Rather than keeping them in the "server. xml" file. A couple
Improvements for this option are noted in Bugs 180931 and 180936.

5. Tomcat parses server. xml through the common-digester tool. It can convert the elements of the XML file into a class instance and create references between parent and child elements.
6. Hot deployment and hot loading:
Hot deployment refers to the re-deployment of the entire project when the container is running. Hot refers to the fact that, compared with the client, you do not need to manually click the deployment button to enable automatic deployment. A common problem in Java Web containers is that during the debugging phase, if a Java class or configuration file is modified, the whole application will be redeployed.

There is a concept of hot loading on the Internet, which should be the concept of hotswap.

7. JVM settings when Tomcat runs a memory-consuming application:

/* ------------- Linux start ----------------*/
$ CD/usr/local/Apache-Tomcat-6.0.18/bin // enter the bin directory of your Tomcat
$ Vim Catalina. Sh // edit your Catalina. Sh File
Find

# Set Juli logmanager if it is present
If [-R "$ catalina_base"/CONF/logging. properties]; then
Java_opts = "$ java_opts-djava. util. Logging. Manager = org. Apache. Juli. classloaderlogmanager"
Logging_config = "-djava. util. Logging. config. File = $ catalina_base/CONF/logging. properties"
Fi

Set java_opts = "$ java_opts-djava. util. Logging. Manager = org. Apache. Juli. classloaderlogmanager"
Change to java_opts = "$ java_opts-xms5120m-xmx5120m-xmn2048m-XX: permsize = 512 M-XX: maxpermsize = 512 M-XX: + useconcmarksweepgc-XX: + response-XX: cmsmaxabortableprecleantime = 500-XX: + cmsclassunloadingenabled-djava. util. logging. manager = org. apache. juli. classloaderlogmanager"


--------------------------------------------------------


Tomcat Architecture

Figure 1

Figure 2:

Tomcat 6.0 supports the servlet2.5 and jsp2.1 specifications and consists of a series of nested components.

  • Service component: the instance of the Tomcat server.Generate one in one JVM. You can configure different ports on one server to start multiple Tomcat instances..
  • Connector component: connects clients and applications. Accept requests from clients and return responses to customers.
  • Engine component: the engine component is responsible for accepting and processing all connection requests from the service to which it belongs. Each service can only containOneEngine component.
  • Host component: a virtual host that allows multiple web applications to be deployed on a physical host.
  • Context component: A web application. A vm can run multiple contexts, which are differentiated by their respective context paths.

The blue font indicates that the component is a container component. Container components can contain other components. The following describes some components that can only be nested in the container.

  • Global Resources global resource component: it can only be nested in the server component and used to configure the global JNDI resources used by other components in the server.
  • Loader loading component: it can only be nested in the context component. It is used to specify a web application class loader and load the classes and resources of the application to the memory.
  • Logger log component: log4j can be used to implement logs.
  • Manager components: can only be nested in Context components. The session manager is used to create and maintain sessions.
  • Realm domain component: a database containing the user name, password, and user role.
  • Resources resource components: they can only be nested in the context component. They represent static resources in web applications and the formats they can be stored.
  • Valve component: the request is intercepted and processed before it reaches the destination. A bit similar to the filter defined in the servlet specification. It is dedicated to Tomcat and cannot be used in other JSP/servlet containers currently.

Configure Tomcat

After the Tomcat 6 server is started, multiple xml configuration files are read. These configuration files are located in the catalina_home/conf directory and contain the following configuration files:

Catalina. Policy: Configure security management policies.

Catalina. properties: configure the Tomcat class loader.

Context. xml: configuration context, which can be used by all web applications.

Server. xml: basic configurations of Tomcat, including services, connectors, engines, domains, valves, and hosts.

Logging. properties: configuration log, specifying the log output lelehander and filehandler.

Tomcat-user.xml: Contains user authentication and role ing configurations. Tomcat admin and manager applications use this file by default.

Web. xml: the default web application deployment descriptor file. It is used to automatically deploy Web applications in Tomcat 6. If the web application has its own deployment descriptor, the content overwrites the default deployment settings.

 

Tomcat6 finds the conf directory and loads the configuration under the directory specified by the catalina_base environment variable. If this environment variable is not specified, it finds the conf directory and loads the configuration under the directory specified by catalina_home, you can configure multiple concurrent Tomcat servers on the same machine by specifying different configurations and ports.

 

Configure server. xml

1. Configure <Server>

 

<Server> attributes

Classname: Specifies the class that implements the org. Apache. Catalina. server interface. No

Port: Specifies the port on which the Tomcat server listens for the shutdown command. Yes

Shutdown: Specifies the string of the shutdown listening port sent to the Tomcat server when the Tomcat server is terminated. Yes

 

Child element of <Server>

<Globalnamingresources>: Global JNDI resource of the server. 1

<Service>: Service component. One or more

 

2. Configure the global naming resource <globalnamingresources>

 

Child element of <globalnamingresources>

<Environment>: global variable. 0 or more

<Resource>: Global JNDI resource. 0 or more

 

  • <Environment> attributes

Description: Environment entry description. No

Name: the name of the stage entry, relative to the Java: COMP/ENV context. Yes

Override: The default value is true. If you do not want to overwrite the web application deployment descriptor, set it to false. No

Type: entry type. It must be a valid type specified in the servlet specification. Yes

Value: the value of the entry. Yes

  • <Resource> attributes

Auth: Specifies whether the web application code is logged on to the corresponding resource manager, or whether the container logs on to the resource manager on behalf of the Web application. The value of this attribute must be application or container. This attribute is required if <resource-ref> is used in the Web application deployment descriptor. If you use <resource-env-ref>, this attribute is optional.

Desprition: Resource description. No

Name: name of the resource. Yes

Scope: Specifies whether the connection obtained through the resource manager is shared. The value of this attribute must be retriable or unretriable. By default, connections are shared. No

Type: When a web application looks for this resource, the full name of the Java class name is returned. Yes

 

Tomcat 6 no longer uses the <resourceparams> element of Tomcat 5 and earlier versions. Instead, the <resource> element attribute is used to provide information.

 

 

3. Configure the service <service>

A service component consists of multiple connector components and an engine component. The service name is displayed in the log and error message, which is used to clearly indicate the component.

 

<Service> element attributes

Classname: Specifies the Java class name used by the Service class. The default value is org. Apache. Catalina. Core. standardservice. No

Name: defines the service name for logon and management. Yes

 

<Service> child element of an element

Connector: requests from users or other Web servers. One or more

Engine: Processes requests. 1

 

4. Configure the connector <connector>

Two requests are sent to Tomcat: the source of the connector

  • Front-end web servers. It may be Apache, IIS, or other Web servers.
  • From a web browser.

You can configure multiple connectors in an engine. For example, a server provides HTTP and HTTPS services to users. In this case, you need to configure the HTTP connector and HTTPS connector in the engine.

Four Common connectors are pre-defined in server. xml: Connector types

  • HTTP Connector
  • SSL Connector
  • The ajp1.3 connector is used to connect to other web servers.
  • Proxy Connector

<Connector> common attributes of Elements

Address: if there are more than two IP addresses on the server, you can set the IP address of the port listener. By default, the port listens to all IP addresses on the server.

Allotrace: Boolean value, set to true, trace HTTP method is available. The default value is false.

Enablelookups: if it is set to true, domain name resolution is supported. You can resolve the IP address to the host name. False indicates that domain name resolution is skipped and the IP address is directly returned as a string. The default value is true.

Mastpostsize: maximum size of the POST request bytes. The default value is 2097152.

Redirectport: Specifies the forwarding port. If the current port only supports non-SSL requests, the customer request is automatically forwarded to the SSL-based redirectport when secure communication is required.

Scheme: the protocol name used by the connector. For example, you can set the property to https for an SSL connector. The default value is HTTP.

Secure: if it is an SSL connection, set it to true. This value is returned when request. getscheme () is called. The default value is false.

Uriencoding: URI-byte decoded character encoding, default: iso-8859-1

Usebodyencodingforuri: indicates that uriencoding is not required if the encoding specified by contenttype is used for URI query parameters. Compatible with tomcat4.1.x. The default value is false.

 

 

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.