Tomcat builds multiple applications (Web Server), multiple hosts, multiple site methods

Source: Internet
Author: User
Tags server memory

52317433

http://piperzero.iteye.com/blog/1475773

A blog post, the format, the content of the writing is quite refreshing

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

When you use Tomcat as a Web server, are you thinking about how to build multiple Web apps with Tomcat?
This is easy to achieve and there are many ways to do it. (The following instructions use%tomcat_home% to represent the Tomcat installation directory.)

I. First introduce TOMCAT and Server.xml

The Tomcat server is made up of a series of configurable components, and Tomcat's components can be configured in the%tomcat_home%/conf/server.xml file, which corresponds to one configuration element for each Tomcat component and Server.xml file.
Mainly divided into 4 categories:
1. Top-level class elements: include and, they are located at the top level of the entire profile.
The element represents the entire Catalina Servlet container, defined by the Org.apache.catalin.Server interface. Contains one or more elements.
The element is defined by the Org.apache.catalin.Service interface. Contains one element, and one or more elements. Multiple elements share an element.
2. Connector class elements
The connector class represents a communication interface between the customer and the service, which sends the customer's request to the server and delivers the server's response to the customer.
The element is defined by the Org.apache.catalin.Connector interface. Represents the component that actually interacts with the client, is responsible for receiving the customer request, and returning the response result to the customer.
3. Container class elements
A container class element represents a component that processes a customer request and generates a response. Include and.
The element is defined by the Org.apache.catalin.Engine interface. Each can contain only one element, and the element handles all the elements in the same one received by the customer request.
The element is defined by the Org.apache.catalin.Host interface. An element can contain multiple elements. Each element defines a virtual host that can contain one or more web apps.
The element is defined by the Org.apache.catalin.Context interface. Represents a Web application running on a virtual host. An element can contain multiple elements
4. Nested class elements
Nested class elements represent components that can be added to a container, such as and.

For more information about Server.xml, you can refer to the documentation for Tomcat:/webapps/tomcat-docs/config/index.html

Examples:

  1. <Server>
  2. <servicename= "Catalina" >
  3. <connectoracceptcount= "connectiontimeout=" 20000 "disableuploadtimeout=" true "port=" 8080 "redirectPort=" 8443 "maxsparethreads=" "maxthreads=" "minsparethreads="/>
  4. <connectorport= "8009" protocol= "ajp/1.3" protocolhandlerclassname= "Org.apache.jk.server.JkCoyoteHandler" redirectport= "8443"/>
  5. <enginedefaulthost= "localhost" name= "Catalina" >
  6. <loggerclassname= "Org.apache.catalina.logger.FileLogger" prefix= "Localhost_log." suffix= ". txt" timestamp= "true"/>
  7. </Host>
  8. <loggerclassname= "Org.apache.catalina.logger.FileLogger" prefix= "Catalina_log." suffix= ". txt" timestamp= "true"/>
  9. <realmclassname= "Org.apache.catalina.realm.UserDatabaseRealm"/>
  10. </Engine>
  11. </Service>
  12. </Server>

Two. Build multiple Web application methods:

Before that, I changed the default of 8080 to 80.

1. By configuring multiple elements (this is the most common method)
Configure multiple elements under

    1. <contextpath= "WebApps" docbase= "C:\Program files\apache software foundation\tomcat 5.5\webapps\root" debug= "0" Reloadable= "true" ></Context>
    2. <contextpath= "WEBAPPS2" docbase= "C:\Program files\apache software foundation\tomcat 5.5\webapps2\root" debug= "0" Reloadable= "true" ></Context>

Then access via host Name: Port/Application name, e.g. HTTP://LOCALHOST/APP1 or http://localhost/app2

2. By configuring multiple elements
Configure multiple elements under

    1. <Alias>www.xok.la</Alias>
    2. <contextpath= "" docbase= "C:\Program files\apache software foundation\tomcat 5.5\webapps\root" debug= "0" reloadable = "true" ></Context>
    3. </Host>
    4. <Alias>www.xok.cc</Alias>
    5. <contextpath= "" docbase= "C:\Program files\apache software foundation\tomcat 5.5\webapps2\root" debug= "0" Reloadable= "true" ></Context>
    6. </Host>

Then through the hostname: port access, such as: Http://xok.la or http://xok.cc
It is important to note that this requires the machine to be connected to the LAN.

3. By configuring multiple elements (multi-port multiple applications)
Configure multiple elements under

  1. <servicename= "Catalina" >
  2. <connectoracceptcount= "connectiontimeout=" 20000 "disableuploadtimeout=" true "port=" redirectport= "8453" maxsparethreads= "maxthreads=" "minsparethreads="/>
  3. <connectorport= "8019" protocol= "ajp/1.3" protocolhandlerclassname= "Org.apache.jk.server.JkCoyoteHandler" redirectport= "8453"/>
  4. <enginedefaulthost= "localhost" name= "Catalina" >
  5. <contextpath= "" docbase= "C:\Program files\apache software foundation\tomcat 5.5\webapps\root" debug= "0" reloadable = "true" ></Context>
  6. </Host>
  7. <realmclassname= "Org.apache.catalina.realm.UserDatabaseRealm"/>
  8. </Engine>
  9. </Service>
  10. <servicename= "Catalina2" >
  11. <connectoracceptcount= "connectiontimeout=" 20000 "disableuploadtimeout=" true "port=" redirectport= "9443" maxsparethreads= "maxthreads=" "minsparethreads="/>
  12. <connectorport= "9009" protocol= "ajp/1.3" protocolhandlerclassname= "Org.apache.jk.server.JkCoyoteHandler" redirectport= "9443"/>
  13. <enginedefaulthost= "localhost" name= "Catalina" >
  14. <contextpath= "" docbase= "C:\Program files\apache software foundation\tomcat 5.5\webapps2\root" debug= "0" Reloadable= "true" ></Context>
  15. </Host>
  16. <realmclassname= "Org.apache.catalina.realm.UserDatabaseRealm"/>
  17. </Engine>
  18. </Service>

The 2nd app just adds 1 to the default port 1th digit.
The two service definitions are Catalina and CATALINA2, and the listening ports are 80 and 90, respectively.
Then through the hostname: port access, such as: http://localhost:80 or http://localhost:90

2nd, 3 kinds have been tested by me.

53483646

Benefits:

1.tomcat deployment, update a site without restarting all sites

2.tomcat Command Window After startup, if off, the Tomcat service will not be hung off

Method:

1. Using the Tomcat multi-instance deployment approach, 1 sites = 1 Tomcat instances = 1 port numbers;

2. Make each tomcat instance into a different Windows service;

Steps:

Now I'm going to deploy 2 sites, Ebm-web and Ebm-mobile-web, respectively.

1. Download Tomcat, after decompression

2. Create a new folder in the directory Ebm-web, drag a folder other than Bin,lib into the ebm-web (for multi-instance implementation)

3. Open the Conf/server.xml file for modification and modify the 3 port numbers (critical!). Cannot repeat with other instances!!! );

(Close Tomcat's port)

(website Port)

(Tomcat AJP Port, I don't know what it is)

Also to add a context configuration under the host node;

<context path= "" docbase= "D:\tomcat\apache-tomcat-8.0.29\ebm-mobile-web\webapps" debug= "0" reloadable= "true" Crosscontext= "true" sessioncookiename= "Ebm-mobile-web"/>

The upper sentence red place to modify, (Docbase for the Site program path, Sessioncookiename is for the site between the session will not be messy)

Next, copy the contents of the Ebm-web project to WebApps, (note: The contents of the direct copy, so I directly access the localhost:xxx, not localhost:xxx/ebm-web);

Then go to the/bin under the Tomcat path and open the command line here (shift+ right);

Execute command (create Windows service):

[Plain]View PlainCopy
  1. Set catalina_home=d:\tomcat\apache-tomcat-8.0.29 #设置环境变量CATALINA_HOME为当前tomcat根目录
  2. Set Catalina_base=d:\tomcat\apache-tomcat-8.0.29\ebm-web #设置环境变量CATALINA_BASE为当前tomcat实例目录
  3. Service Install Ebm-web #此处ebm-web for Windows server name
  4. Tomcat8.exe//us//ebm-web--startup=auto #设置为开机自动启动
  5. #正式环境需要调整jvm内存 (the test environment is not adjustable), and then execute the following statement, representing the initial memory and the maximum memory, in megabytes
  6. Tomcat8.exe//us//ebm-web--jvmms=1024--jvmmx=2048

Successful words, such as:

Finally, open the Windows Service (Task Manager-service) Ebm-web ran up;

Next is Ebm-mobile-web, repeat the above step, remember to change the port and the like,

The command to delete a service is:

[Plain]View PlainCopy
    1. Service.bat Remove your service name

Note: Tuning JVM memory

Tomcat's default memory is small and can cause out-of-memory exceptions, so we need to make the memory larger in the formal environment.

Method One:

Execute in the bin directory of the Tomcat installation directory:

[Plain]View PlainCopy
    1. Tomcat8.exe//us//Your service name--jvmms=1024--jvmmx=2048

Restart your service.

Method Two:

Locate the Service.bat file in the Tomcat Bin directory, open it with the editor, find the Jvmms and jvmmx two parameters at the end of the file, indicate the initial memory and maximum memory size, in MB, and adjust the value according to the server memory, reinstall your service to take effect.

Tomcat builds multiple applications (Web Server), multiple hosts, multiple site methods

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.