[GO] Server deployment Tomcat and other applications

Source: Internet
Author: User

How to modify the port of 1.Tomcat?

The default port number for Tomcat is 8080.
To modify the Tomcat port number:
1. Locate the Conf folder in the Tomcat directory
2. Go to the Conf folder and locate the Server.xml file.
3. Open Server.xml File
4. Find the following information in the Server.xml file
maxthreads= "150″minsparethreads=" 25″maxsparethreads= "75″
Enablelookups= "false" redirectport= "8443″acceptcount=" 100″
Connectiontimeout= "20000″disableuploadtimeout=" true "/>
5. Change the port= "8080″ to Port=" 8888″ and save
6. Launch Tomcat and enter http://127.0.0.1:8888/in the address bar inside IE browser

2.tomcat How to optimize? 1. Optimize the connection Configuration

Here, with the TOMCAT7 parameter configuration as an example, you need to modify the Conf/server.xml file, modify the number of connections, and turn off client DNS queries.

Parameter explanation:

Uriencoding= "Utf-8″: Makes it easy for Tomcat to parse the URL of a file with Chinese name, unlike Apache and a mod_encoding, but also to compile manually

Maxsparethreads: If the number of threads in the idle state is greater than the number of settings, the threads are aborted, reducing the total number of threads in the pool.

Minsparethreads: The minimum number of standby threads, the number of threads initialized at tomcat startup.

Enablelookups: This effect is set to off like the hostnamelookups in Apache.

Connectiontimeout:connectiontimeout the number of milliseconds that the network connection time out.

Maxthreads:maxthreads Tomcat uses threads to process each request that is received. This value represents the maximum number of threads that Tomcat can create, that is, the maximum number of concurrent.

Acceptcount:acceptcount is when the number of threads reaches MaxThreads, subsequent requests will be placed in a waiting queue, the Acceptcount is the size of this queue, if the queue is full, it is directly refuse connection

Maxprocessors and Minprocessors: In the Java thread is the path of the program runtime, which is independent of the other control threads in one program and can run independently of the code snippet. They share the same address space. Multithreading helps programmers write efficient programs that maximize CPU utilization, keeping idle time to a minimum, and thus accepting more requests.

Usually Windows is about 1000, and Linux is about 2000.

Useurivalidationhack:

Let's take a look at the source code in Tomcat:

"Security"

if (Connector.getuseurivalidationhack ()) {String URI = Validate (Request.getrequesturi ()); if (URI = = null) { Res.setstatus (+); Res.setmessage ("Invalid uri"); throw new IOException ("Invalid uri");} else {Req.requesturi (). setString (URI);//redoing the URI Decodingreq.decodeduri (). Duplicate (Req.requesturi ()); Req.geturldecoder (). Convert (Req.decodeduri (), True);}}

  

You can see that if you set the Useurivalidationhack to "false", you can reduce the unnecessary checking of some URLs, thereby reducing the cost.

Enablelookups= "false": in order to eliminate the effect of DNS queries on performance we can turn off DNS queries by modifying the enablelookups parameter values in the Server.xml file.

Disableuploadtimeout: Similar to keeyalive in Apache

Configuring the gzip compression (HTTP compression) feature for Tomcat

Compression= "on" compressionminsize= "2048″compressablemimetype=" Text/html,text/xml,text/javascript,text/css, Text/plain "

  

HTTP compression can greatly improve the speed of browsing the website, it is the principle that after the client requests the Web page, the Web page files are compressed from the server side, and then downloaded to the client, the client's browser is responsible for extracting and browsing. Relative to the normal browsing process html,css,javascript, Text, it can save about 40% of the traffic. More importantly, it can be dynamically generated, including CGI, PHP, JSP, ASP, servlet,shtml and other output of the Web page can also be compressed, compression efficiency is amazing.

1) compression= "on" to turn on the compression function

2) compressionminsize= "2048″ Enable compressed output content size, which defaults to 2KB

3) nocompressionuseragents= "Gozilla, Traviata" for the following browsers, do not enable compression

4) compressablemimetype= "Text/html,text/xml" compression type

Finally, don't forget to add the 8443 port to the same configuration, because if we take the HTTPS protocol, we will use the 8443 port this section of the configuration, right?

<!–enable Tomcat ssl–><connector port= "8443″protocol=" http/1.1″uriencoding= "utf-8″minsparethreads=" 25″ Maxsparethreads= "75″enablelookups=" false "disableuploadtimeout=" true "connectiontimeout=" 20000″acceptcount= "300″" maxthreads= "300″maxprocessors=" 1000″minprocessors= "5″useurivalidationhack=" false "compression=" on " Compressionminsize= "2048″compressablemimetype=" Text/html,text/xml,text/javascript,text/css,text/plain " Sslenabled= "true" scheme= "https" secure= "true" Clientauth= "false" sslprotocol= "TLS" keystorefile= "d:/tomcat2/conf/ Shnlap93.jks "keystorepass=" aaaaaa "/>

  

Well, all of the Tomcat optimizations are added.

2. Optimize JDK

Tomcat defaults to the memory used by 128mb,windows, under file {Tomcat_home}/bin/catalina.bat,unix, in file $catalina_home/bin/ In front of the catalina.sh, add the following settings:
Java_opts= "' $JAVA _opts"-xms[initialize memory size]-xmx[maximum memory that can be used]
Or
Set environment variables: Export java_opts= "" $JAVA _opts "-xms[initialize memory size]-xmx[maximum memory available]"
Generally speaking, you should use 80% of the physical memory as the heap size. If you have an Apache server on this computer, you can first convert the memory that Apache needs and then modify the heap size. The recommended setting is 70%, and the recommended setting [[Initialize memory size] equals [maximum memory that can be used], which reduces performance by reducing the trivial allocation heap.
This example uses the method of adding environment variables:
# Vi/etc/profile
Join: Export java_opts= "" $JAVA _opts "-xms700-xmx700
# Source/etc/profile

"Parameter description"

-XMS refers to the amount of memory that is consumed when the program starts. Generally speaking, a big point, the program will start a little faster, but it may also cause the machine to slow down temporarily.

-xmx refers to the maximum amount of memory that can be consumed during a program's run. A OutOfMemory exception is thrown if the program is running with more memory than the setting value.

-XSS refers to setting the stack size for each thread. This depends on your program, how much memory a thread needs to occupy, how many threads may run concurrently, and so on.

-xx:permsize sets the non-heap memory initial value, which defaults to 1/64 of the physical memory.

-xx:maxpermsize sets the maximum size of non-heap memory, which is 1/4 of physical memory by default.


How many connector operating modes does 3.tomcat have?

There are 3 modes of operation for Tomcat. Modify their run mode. 3 modes of operation is successful, you can see his startup console, or start the log. or log in to their default page http://localhost:8080/to see the server status.

1) bio

The default mode, performance is very low, without any optimization processing and support.

2) NiO

Using Java's asynchronous IO Care technology, no blocking IO technology.

Want to run in this mode, directly modify the connector node in the Server.xml, modify the protocol to

<connector port= "80″protocol=" Org.apache.coyote.http11.Http11NioProtocol "
Connectiontimeout= "20000″
Uriencoding= "Utf-8″
Usebodyencodingforuri= "true"
Enablelookups= "false"
Redirectport= "8443″/>

Once started, it can take effect.

3) Apr

Installation is the most difficult, but from the operating system level to solve the asynchronous IO problem, greatly improve performance.

Apr and native must be installed and the APR will be supported directly on the launch. The following modifications are superfluous, only to expand the knowledge, but you still need to install APR and native

[GO] Server deployment Tomcat and other applications

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.