Installation and optimization of tomcat

I Introduction to Tomcat

1.1 introduction to Tomcat

  • Free, open source Web application server
  • The Apache Software Foundation is a core project of the Jakarta project
  • It is jointly developed by Apache, Sun and some companies and individuals
  • It is deeply loved by Java lovers and recognized by some software developers
    It is a popular Web application server at present

1.2 Tomcat core components

1.3 main directory of Tomcat

  • bin
    Save and close Tomcat script files. is commonly used sh, startup. sh, shutdown. SH three files
  • conf
    Store various configuration files of Tomcat server, and the more commonly used one is server xml ,context.xml, tomcat-users.xml, web.xml four files
  • lib
    The jar package that stores the Tomcat server is generally unchanged. Unless you connect to a third-party service, such as redis, you need to add the corresponding jar package
  • logs
    Store tomcat logs
  • temp
    Store the files generated by Tomcat runtime
  • webapps
    Directory where project resources are stored
  • work
    Tomcat working directory is generally used when clearing Tomcat cache

II Deployment steps of Tomcat

2.1 download and install jdk

Install resource pack

upload jdk-8u201-linux-x64.rpm reach/opt in
[root@localhost opt]# rpm -ivh jdk-8u201-linux-x64.rpm

Setting environment variables

2.2 install and start Tomcat

take apache-tomcat-9.0.16.tar.gz Upload to/opt
[root@localhost opt# tar zxvf apache-tomcat-9.0.16.tar.gz -C /usr/local
[root@localhost opt]# cd /usr/local
[root@localhost local]#  mv apache-tomcat-9.0.16/ tomcat9

**Create soft connection**
[root@localhost local]# ln -s /usr/local/tomcat9/bin/ /usr/bin 	// Create a soft connection to open Tomcat script
[root@localhost local]# ln -s /usr/local/tomcat9/bin/ /usr/bin 	// Create a soft connection to close Tomcat scripts

Turn on the service and turn off the firewall

systemctl stop firewalld.service 
setenforce 0 	//Open Tomcat
netstat -ntap |grep 8080

The tester accesses the Tomcat home page
Enter directly in the browser:

III Virtual host configuration

Sometimes the company may have multiple projects running, so it is certainly impossible to run multiple Tomcat services on one server, which will consume too many system resources. At this point, you need to use Tomcat virtual host. For example, now add two domain names com www.zhenguo. COM, hoping to access different project contents through these two domain names.
When multiple projects are running at the same time, one server is not recommended to run multiple Tomcat services, and virtual hosts need to be configured

3.1 create site directories and files

[root@localhost ~]# cd /usr/local/tomcat/webapps
[root@localhost webapps]# mkdir peihua
[root@localhost webapps]# mkdir zhenguo
[root@localhost webapps]# cat peihua/index.jsp 
<h1>this is peihzhua<h1>
[root@localhost webapps]# cat zhenguo/index.jsp 
<h1>this is zhenguo<h1>

3.2 setting dns resolution COM and com

1. Configure DNS

[root@localhost local]# yum install bind -y
[root@localhost local]# vim /etc/named.conf
 Modify listening address: Change to any,localhost Change to any

[root@localhost local]# vim /etc/named.rfc1912.zones 
zone "" IN {		'//'add this paragraph'
        type master;
        file "";
        allow-update { none; };
zone "" IN {		'//'add this paragraph'
        type master;
        file "";
        allow-update { none; };

[root@localhost local]# cd /var/named
[root@localhost named]# cp -p named.localhost
[root@localhost named]# vim 
www IN  A		'//'add last line'
[root@localhost named]# cp -p
[root@localhost named]# systemctl start named

Note:[ root@localhost named]# cp -p named. localhost peihua. com. Zone, no - P will cause the named service to work, but it just can't resolve the domain name

2. The test machine specifies the resolution address

3. Test the two domain names of the virtual host

Enter com

Enter com

IV Tomcat optimization

4.1 interpretation of Tomcat optimization parameters (written in the main configuration file of server.xml)

maxThreads: Tomcat uses threads to process each request received. This value represents the maximum number of threads that Tomcat can create. The default value is 200.
minSpareThreads: the minimum number of idle threads. It refers to the number of initialized threads when Tomcat is started. It means that so many empty threads are opened to wait even if no one is using them. The default value is 10.
maxSpareThreads: the maximum number of spare threads. Once the created thread exceeds this value, Tomcat will close the socket thread that is no longer needed. The default value is - 1 (unlimited). Generally, it is not necessary to specify.
URIEncoding: Specifies the URL encoding format of Tomcat container. The language encoding format is not as convenient as other Web server software configuration, and needs to be specified separately.
Connexiontimeout: network connection timeout, unit: milliseconds. Setting it to 0 means never timeout. This setting has hidden dangers. Usually, the default is 20000 milliseconds.
enableLookups: whether to backcheck the domain name to return the host name of the remote host. The value is: true or false. If it is set to false, the IP address will be returned directly. In order to improve the processing capacity, it should be set to false.
disableUploadTimeout: whether to use the timeout mechanism when uploading. Should be set to true.
connectionUploadTimeout: upload timeout. After all, file upload may take more time. This can be adjusted according to your own business needs, so that the Servlet can take a long time to complete its execution. It will take effect only when it is used together with the previous parameter.
acceptCount: Specifies the maximum queue length of incoming connection requests when all available threads for processing requests are used. Requests exceeding this number will not be processed. The default is 100.
Compression: whether to GZIP compress the response data. Off: it means to prohibit compression; on: indicates that compression is allowed (the text will be compressed), force: indicates that compression is carried out in all cases, and the default value is off. After compressing the data, the page size can be effectively reduced, which can generally be reduced by about 1 / 3 to save bandwidth.
compressionMinSize: indicates the minimum value of the compression response. The message will be compressed only when the response message size is greater than this value. 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.

4.2 performance optimization of Tomcat

[root@localhost ~]# vim /usr/local/tomcat9/conf/server.xml 
<Connector port="8080" protocol="HTTP/1.1"		'//'find this paragraph'
               redirectPort="8443" />
'//Add the following paragraph between redirectPort="8443" and / > '
[root@localhost ~]#
[root@localhost ~]#

Tags: Linux Tomcat

Posted by DiceyJono on Mon, 09 May 2022 01:29:50 +0300