Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Configuration and Optimization of Tomcat Virtual Machine

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Tomcat virtual host configuration

Sometimes, when a company has multiple projects running at the same time, it is not recommended to run multiple Tomcat services on one server. Virtual hosts need to be configured.

Access to different project content through two domain names

Steps

1. Create www and bbs project directories and files

two。 Modify the Tomcat main configuration file

3. Restart the Tomcat service

4. test

Tomcat optimization

The default configuration of Tomcat is not suitable for the production environment, it will frequently appear fake death phenomenon and need to be rebooted. Only through continuous stress testing and optimization can it run stably and efficiently. There are three main aspects of optimization, including operating system optimization (kernel parameter optimization), Tomcat profile parameter optimization, Java virtual machine (JVM) tuning.

Optimization related parameters commonly used in Tomcat

[maxThreads] Tomcat uses a thread to process each request received, a value that represents the most

Large number of threads, the default value is 200.

[minSpareThreads] the minimum number of idle threads, the number of threads initialized when Tomcat starts, indicating that even if there is no

People use to open so many empty threads to wait, the default value is 10

[maxSpareThreads] maximum number of standby threads. Once the created thread exceeds this value, Tomcat will close no

The socket thread that is needed again. The default value is-1 (unlimited). Generally, there is no need to specify

[URIEncoding] specifies the URL encoding format of the Tomcat container. The language encoding format is not as good as other Web.

The server software is easy to configure and needs to be specified separately

[connnectionTimeout] Network connection timeout (in milliseconds). Set to 0 means never time out. Set it like this

There are hidden dangers. Usually the default is 20000 milliseconds.

[enableLookups] whether to reverse check the domain name to return the hostname of the remote host. Value: true or false

If set to false, the IP address is returned directly. To improve processing power, it should be set to false.

[disableUploadTimeout] whether to use timeout mechanism when uploading. Should be set to true.

[connectionUploadTimeout] upload timeout. After all, file upload may take more time.

This is adjusted according to your own business needs, so that Servlet has a longer time to complete its execution.

It will not take effect until used in conjunction with the previous parameter.

[acceptCount] specifies that connection requests can be passed in when all available threads for processing requests are used

The maximum queue length of the. Requests beyond this number will not be processed. The default is 100.

[compression] whether to perform GZIP compression on the response data. Off: disable compression; on: allow

Compression (text will be compressed), force: compression is performed in all cases. The default value is off, and data is compressed.

After that, it can effectively reduce the size of the page, generally, it can be reduced by about 1 inch, saving bandwidth.

[compressionMinSize] represents the minimum value of the compressed response, only when the response message size is greater than this value.

The message will be compressed. If the compression function is enabled, the default value is 2048.

[compressableMimeType] Compression type, which specifies which types of files are compressed.

[noCompressionUserAgents= "gozilla, traviata"] Compression is not enabled for the following browsers

If the code has been separated, static pages and images and other data do not need to be processed by Tomcat, then

There is no need to configure compression in Tomcat. Because there is only one Tomcat server here, and the stress test is

Tomcat home page, there will be pictures and static resource files, so compression is enabled here

Step 1: install and configure the domain name resolution service [root@localhost ~] # yum install bind-y [root@localhost ~] # vim / etc/named.conf listen-on port 53 {any;};... allow-query {any;}; [root@localhost ~] # vim / etc/named.rfc1912.zones zone "kgc.com" IN {type master; file "kgc.com.zone"; allow-update {none;};} Zone "accp.com" IN {type master; file "accp.com.zone"; allow-update {none;};}; [root@localhost ~] # cd / var/named/ [root@localhost named] # cp-p named.localhost kgc.com.zone [root@localhost named] # vim kgc.com.zone$TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.235.158 [root@localhost named] # cp-p kgc.com.zone accp.com.zone# copy kgc file and rename it accp file Without modification [root@localhost named] # systemctl start named# starts domain name resolution service [root@localhost named] # systemctl stop firewalld.service [root@localhost named] # setenforce "turn off firewall and enhanced security. Step 2: create kgc and accp project directories and files [root@localhost named] # mkdir / usr/local/tomcat/webapps/kgc# create kgc site directory [root@localhost named] # echo" This is kgc web "> / usr/local/ Tomcat/webapps/kgc/index.jsp# Edit kgc homepage [root@localhost named] # mkdir / usr/local/tomcat/webapps/accp [root@localhost named] # echo "This is accp web" > / usr/local/tomcat/webapps/accp/index.jsp step 3: modify Tomcat main configuration file server.xml [root@localhost named] # vim / usr/local/tomcat/conf/server.xml # define www.kgc.com virtual host configuration # close the xml namespace # specify the classes loaded by path by default and enable the reloadable monitoring class # Note the closing tag # define the www.accp.com virtual host configuration [root@localhost named] # shutdown.sh # close Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usr/java/jdk1.8.0_201-amd64Using CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar [root@localhost named] # startup.sh # enable Tomcat service Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usr/java/jdk1.8.0_201-amd64Using CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started. Step 4: browse the test web page

1. Use a browser to access the http://www.kgc.com:8080 page to display This is kgc web

two。 Use a browser to access the http://www.accp.com:8080 page to display This is accp web

Step 5: optimize Tomcat

1. Use apache-jmeter to pressure test before optimization.

two。 Modify the main configuration file server.xml

[root@localhost ~] # vim / usr/local/tomcat/conf/server.xml # supported compression types

3. The optimized Tomcat after pressure test again

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report