理论+实验 详解Tomcat部署及优化

一 Tomcat安装部署

1.1 Tomcat介绍

理论+实验 详解Tomcat部署及优化_第1张图片

1.2 Tomcat核心组件

理论+实验 详解Tomcat部署及优化_第2张图片

1.3 Tomcat处理请求过程

理论+实验 详解Tomcat部署及优化_第3张图片
说明:

理论+实验 详解Tomcat部署及优化_第4张图片

1.4 Tomcat安装

##提前将所需要的包传到root目录下
[root@localhost ~]# rpm -ivh jdk-8u201-linux-x64.rpm    ##解压安装包
[root@localhost ~]# cd /usr/java/jdk1.8.0_201-amd64/
[root@localhost jdk1.8.0_201-amd64]# ll    ##确认安装目录
total 25980
drwxr-xr-x 2 root root     4096 Sep  9 14:46 bin
-rw-r--r-- 1 root root     3244 Dec 16  2018 COPYRIGHT
drwxr-xr-x 3 root root      132 Sep  9 14:46 include
-rw-r--r-- 1 root root  5207434 Dec 12  2018 javafx-src.zip
drwxr-xr-x 5 root root      185 Sep  9 14:46 jre
drwxr-xr-x 5 root root      245 Sep  9 14:46 lib
-rw-r--r-- 1 root root       40 Dec 16  2018 LICENSE
drwxr-xr-x 4 root root       47 Sep  9 14:46 man
-rw-r--r-- 1 root root      159 Dec 16  2018 README.html
-rw-r--r-- 1 root root      424 Dec 16  2018 release
-rw-r--r-- 1 root root 21103945 Dec 16  2018 src.zip
-rw-r--r-- 1 root root   108109 Dec 12  2018 THIRDPARTYLICENSEREADME-JAVAFX.txt
-rw-r--r-- 1 root root   155002 Dec 16  2018 THIRDPARTYLICENSEREADME.txt

[root@localhost jdk1.8.0_201-amd64]# vi /etc/profile    ##设置JDK环境变量
##最后新加
export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64 
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$PATH
[root@localhost jdk1.8.0_201-amd64]# source /etc/profile    ##环境变量生效
[root@localhost jdk1.8.0_201-amd64]# java -version    ##查看java版本
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

[root@localhost jdk1.8.0_201-amd64]# cd ~
[root@localhost ~]# tar xzvf apache-tomcat-9.0.16.tar.gz 
[root@localhost ~]# mv apache-tomcat-9.0.16 /usr/local/tomcat    ##将安装包移动Tomcat目录到/usr/local下
[root@localhost ~]# /usr/local/tomcat/bin/startup.sh     ##启动tomcat

浏览器中输入:http://20.0.0.21:8080
理论+实验 详解Tomcat部署及优化_第5张图片

[root@localhost ~]# vi /usr/java/jdk1.8.0_201-amd64/jre/lib/security/java.security     ##优化Tomcat启动速度
securerandom.source=file:/dev/urandom
[root@localhost ~]# /usr/local/tomcat/bin/shutdown.sh     ##关闭tomcat
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_201-amd64
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@localhost ~]# /usr/local/tomcat/bin/startup.sh     ##启动tomcat
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_201-amd64
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

[root@localhost ~]# ll /usr/local/tomcat/
total 124
drwxr-x--- 2 root root  4096 Sep  9 14:57 bin
-rw-r----- 1 root root 19203 Feb  5  2019 BUILDING.txt
drwx------ 3 root root   254 Sep  9 15:00 conf
-rw-r----- 1 root root  6095 Feb  5  2019 CONTRIBUTING.md
drwxr-x--- 2 root root  4096 Sep  9 14:57 lib
-rw-r----- 1 root root 57092 Feb  5  2019 LICENSE
drwxr-x--- 2 root root   197 Sep  9 15:00 logs
-rw-r----- 1 root root  2333 Feb  5  2019 NOTICE
-rw-r----- 1 root root  3255 Feb  5  2019 README.md
-rw-r----- 1 root root  6854 Feb  5  2019 RELEASE-NOTES
-rw-r----- 1 root root 16262 Feb  5  2019 RUNNING.txt
drwxr-x--- 2 root root    30 Sep  9 14:57 temp
drwxr-x--- 7 root root    81 Feb  5  2019 webapps
drwxr-x--- 3 root root    22 Sep  9 15:00 work

1.5 Tomcat目录结构

理论+实验 详解Tomcat部署及优化_第6张图片

二 虚拟主机配置

##创建51xit和52xit项目目录和文件
[root@localhost ~]# mkdir /usr/local/tomcat/webapps/51xit
[root@localhost ~]# echo "This is 51xit page" > /usr/local/tomcat/webapps/51xit/index.jsp
[root@localhost ~]# mkdir /usr/local/tomcat/webapps/52xit
[root@localhost ~]# echo "This is 52xit page" > /usr/local/tomcat/webapps/52xit/index.jsp

[root@localhost ~]# vi /usr/local/tomcat/conf/server.xml     ##修改Tomat主配置文件
        <Host name="www.51xit.top" appBase="/usr/local/tomcat/webapps" 
           unpackWARs="true" autoDeploy="true" xmlValidation="false" 
           xmlNamespaceAware="false"> 
           <Context docBase="/usr/local/tomcat/webapps/51xit" 
           path="" reloadable="true" /> 
        </Host> 

        <Host name="www.52xit.top" appBase="/usr/local/tomcat/webapps" 
            unpackWARs="true" autoDeploy="true" xmlValidation="false" 
            xmlNamespaceAware="false"> 
            <Context docBase="/usr/local/tomcat/webapps/52xit" 
            path="" reloadable="true" />
        </Host>
        
[root@localhost ~]# /usr/local/tomcat/bin/shutdown.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_201-amd64
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@localhost ~]# /usr/local/tomcat/bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/java/jdk1.8.0_201-amd64
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

修改真机hosts文件:
在这里插入图片描述
浏览器测试:
理论+实验 详解Tomcat部署及优化_第7张图片
理论+实验 详解Tomcat部署及优化_第8张图片

三 Tomcat优化

3.1 Tomcat配置文件参数优化

理论+实验 详解Tomcat部署及优化_第9张图片

你可能感兴趣的:(实验,理论)