安装Tomcat & JDK
安装时候选择tomcat软件版本要与程序开发使用的版本一致。jdk版本要进行与tomcat保持一致。
1、系统环境说明
[root@java-tomcat1 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@java-tomcat1 ~]# uname -a
Linux java-tomcat1 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@java-tomcat1 ~]# getenforce
Disabled
[root@java-tomcat1 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service;
disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
2 、安装JDK
命令集:
上传jdk1.8到服务器。安装jdk
[root@java-tomcat1 ~]# tar xzf jdk-8u191-linux-x64.tar.gz -C /usr/local/
[root@java-tomcat1 ~]# cd /usr/local/ [root@java-tomcat1 local]# mv jdk1.8.0_191/ java
设置环境变量:
[root@java-tomcat1 local]# vim /etc/profile
export JAVA_HOME=/usr/local/java #指定java安装目录
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH #用于指定java系统查找命令的路径
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar #类的路径,在编译运 行java程序时,如果有调用到其他类的时候,在classpath中寻找需要的类。 检测JDK是否安装成功:
[root@java-tomcat1 local]# source /etc/profile
[root@java-tomcat1 local]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
3、安装Tomcat
命令集:
[root@java-tomcat1 ~]# mkdir /data/application -p
[root@java-tomcat1 ~]# cd /usr/src/
[root@java-tomcat1 src]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat8/v8.5.42/bin/apache-tomcat-8.5.42.tar.gz
[root@java-tomcat1 src]# tar xzf apache-tomcat-8.5.42.tar.gz -C /data/application/
[root@java-tomcat1 src]# cd /data/application/
[root@java-tomcat1 application]# mv apache-tomcat-8.5.42/ tomcat
设置环境变量:
[root@java-tomcat1 application]# vim /etc/profile
export TOMCAT_HOME=/data/application/tomcat #指定tomcat的安装目录
[root@java-tomcat1 application]# source /etc/profile
查看tomcat是否安装成功:
[root@java-tomcat1 tomcat]# /data/application/tomcat/bin/version.sh
Using CATALINA_BASE: /data/application/tomcat
Using CATALINA_HOME: /data/application/tomcat
Using CATALINA_TMPDIR: /data/application/tomcat/temp Using JRE_HOME: /usr/local/java
Using CLASSPATH: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.42
Server built: Jun 4 2019 20:29:04 UTC
Server number: 8.5.42.0
OS Name: Linux
OS Version: 3.10.0-693.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_191-b12
JVM Vendor: Oracle Corporation
Tomcat目录介绍
1、tomcat主目录介绍
[root@java-tomcat1 ~]# cd /data/application/tomcat/ [root@java-tomcat1 tomcat]# yum install -y tree
[root@java-tomcat1 tomcat]# tree -L 1
.
├── bin #存放tomcat的管理脚本
├── BUILDING.txt
├── conf #tomcat的配置文件
├── CONTRIBUTING.md
├── lib #web应用调用的jar包存放路径
├── LICENSE
├── logs #tomcat日志存放目录,catalin.out日志为只要输出日志
├── NOTICE
├── README.md
├── RELEASE-NOTES
├── RUNNING.txt
├── temp #存放临时文件
├── webapps #默认网站发布目录
└── work #存放编译生产的.java与.class文件
7 directories, 7 files
2、webapps目录介绍
[root@java-tomcat1 tomcat]# cd webapps/
[root@java-tomcat1 webapps]# tree -L 1
.
├── docs #tomcat的帮助文档
├── examples #web应用实例
├── host-manager #主机管理
├── manager #管理
└── ROOT #默认站点根目录
5 directories, 0 files
3、Tomcat配置文件目录介绍(conf)
[root@java-tomcat1 webapps]# cd ../conf/
[root@java-tomcat1 conf]# tree -L 1
.
├── Catalina
├── catalina.policy
├── catalina.properties
├── context.xml
├── logging.properties
├── logs
├── server.xml # tomcat 主配置文件
├── server.xml.bak
├── server.xml.bak2
├── tomcat-users.xml # tomcat 管理用户配置文件
├── tomcat-users.xsd
└── web.xml
2 directories, 10 files
4、Tomcat的管理
启动程序 #/data/application/tomcat/bin/startup.sh
关闭程序 #/data/application/tomcat/bin/shutdown.sh
启动停止
[root@java-tomcat1 conf]# cd ../bin/
[root@java-tomcat1 bin]# ./startup.sh
Using CATALINA_BASE: /data/application/tomcat
Using CATALINA_HOME: /data/application/tomcat
Using CATALINA_TMPDIR: /data/application/tomcat/temp Using JRE_HOME: /usr/local/java
Using CLASSPATH: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jar Tomcat started.
[root@java-tomcat1 bin]# ./shutdown.sh
Using CATALINA_BASE: /data/application/tomcat
Using CATALINA_HOME: /data/application/tomcat
Using CATALINA_TMPDIR: /data/application/tomcat/temp Using JRE_HOME: /usr/local/java
Using CLASSPATH: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jar
注意:tomcat未启动的情况下使用shutdown脚本,会有大量的输出信息。
检查tomcat是否启动正常
[root@java-tomcat1 bin]# netstat -lntp |grep java
tcp6 0 0 :::8080 :::* LISTEN 30560/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 30560/java
tcp6 0 0 :::8009 :::* LISTEN 30560/java
端口:
8005:这个端口负责监听关闭Tomcat的请求 shutdown:向以上端口发送的关闭服务器的命令字符串。
8009: 与其他http服务通信接口,接受其他服务器转发过来的请求
8080: 建立http连接用。可以修改
说明:所有与java相关的,服务启动都是java命名的进
查看日志
[root@java-tomcat1 bin]# tail -f
03-Aug-2019 17:56:54.124 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/data/application/tomcat/webapps/docs] has finished in [70] ms
03-Aug-2019 17:56:54.125 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/data/application/tomcat/webapps/examples]
03-Aug-2019 17:56:54.626 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/data/application/tomcat/webapps/examples] has finished in [502] ms
03-Aug-2019 17:56:54.626 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/data/application/tomcat/webapps/host-manager]
03-Aug-2019 17:56:54.662 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/data/application/tomcat/webapps/host-manager] has finished in [36] ms
03-Aug-2019 17:56:54.662 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/data/application/tomcat/webapps/manager]
03-Aug-2019 17:56:54.706 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/data/application/tomcat/webapps/manager] has finished in [44] ms
03-Aug-2019 17:56:54.725 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
03-Aug-2019 17:56:54.753 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
03-Aug-2019 17:56:54.756 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1325 ms
Tomcat主配置文件详解
1、server.xml组件类别
顶级组件:位于整个配置的顶层,如server。
容器类组件:可以包含其它组件的组件,如service、engine、host、context。
连接器组件:连接用户请求至tomcat,如connector
1.png
2.png
3.png
WEB站点部署
上线的代码有两种方式:
第一种方式是直接将程序目录放在webapps目录下面,这种方式大家已经明白了,就不多说了。
第二种方式是使用开发工具将程序打包成war包,然后上传到webapps目录下面。
网友评论