Tomcat
Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的情况下被普遍应用,是开发和调试JSP程序的首选。Tomcat是Apache服务器的扩展,但运行时他是独立运行的,所以当你运行tomcat时,它实际上是作为一个与Apache独立的进程单独运行。
Java+JDK+Tomcat+Mysql
1.所有服务部署在同一个主机上,也可以分开部署。
2.Apache默认开启的是80端口,用来接收用户的web请求。
3.Tomcat默认开启的是8080端口,用来接收Nginx转发来的web请求。![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/01dfbbe3f1256cbc36f257278aa03af1.png#pic_center)
环境部署
环境准备:
centos8(192.168.1.6)
配置yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost yum.repos.d]# yum clean all
关闭防火墙和selinux:
[root@localhost yum.repos.d]# systemctl stop firewalld.service
[root@localhost yum.repos.d]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost yum.repos.d]# setenforce 0
安装JDK(jave解析器)
首先安装gcc
[root@localhost /]# yum -y install gcc
2.下载jdkrpm包
[root@localhost opt]# wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
安装
[root@localhost opt]# yum -y install jdk-17_linux-x64_bin.rpm
验证
[root@localhost opt]# java -version
java version "17.0.8" 2023-07-18 LTS
Java(TM) SE Runtime Environment (build 17.0.8+9-LTS-211)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.8+9-LTS-211, mixed mode, sharing)
安装Tomcat
下载安装包
[root@localhost opt]# wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.1.13/bin/apache-tomcat-10.1.13.tar.gz
解压
[root@localhost opt]# tar -xf apache-tomcat-10.1.13.tar.gz
[root@localhost opt]# mv apache-tomcat-10.1.13 /usr/local/tomcat-10
配置tomcat的配置文件
export TOMCAT_HOME=/usr/local/timcat
export PATH=$PATH:TOMCAT_HOME/bin
[root@localhost tomcat-10]# source /etc/profile
授权
[root@localhost tomcat-10]# chmod +x /usr/local/tomcat-10/bin/*
开启tomcat
[root@localhost tomcat-10]# /usr/local/tomcat-10/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat-10
Using CATALINA_HOME: /usr/local/tomcat-10
Using CATALINA_TMPDIR: /usr/local/tomcat-10/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat-10/bin/bootstrap.jar:/usr/local/tomcat-10/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost tomcat-10]# ss -ntl #查看端口是否启动
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 128 [::]:22 [::]:*
客户端验证
安装mysql
[root@localhost tomcat-10]# yum -y install mariadb-server
[root@localhost tomcat-10]# systemctl restart mariadb.service
[root@localhost tomcat-10]# mysql_secure_installation
[root@localhost tomcat-10]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.28-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
安装httpd
[root@localhost tomcat-10]# yum -y install nginx
[root@localhost tomcat-10]# systemctl restart nginx.service
[root@localhost tomcat-10]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 128 [::]:22 [::]:*
部署jave的war包
[root@localhost conf]# vim server.xml
<Context path="" docBase="sample.war" debug="0" privileged="true"/>
[root@localhost local]# find / -name *.war
/usr/local/tomcat-10/webapps/docs/appdev/sample/sample.war
/usr/local/tomcat-10/webapps/sample.war
/usr/local/tomcat-20/webapps/docs/appdev/sample/sample.war
/usr/local/tomcat-20/webapps/sample.war
cp
[root@localhost conf]# cp /usr/local/tomcat-10/webapps/docs/appdev/sample/sample.war /usr/local/tomcat-10/webapps/
# 删除网站的root目录
~~~1
[root@localhost webapps]# rm -rf ROOT
[root@localhost webapps]# ls
docs examples host-manager manager sample sample.war
重启服务
[root@localhost webapps]# /usr/local/tomcat-10/bin/catalina.sh stop
Using CATALINA_BASE: /usr/local/tomcat-10
Using CATALINA_HOME: /usr/local/tomcat-10
Using CATALINA_TMPDIR: /usr/local/tomcat-10/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat-10/bin/bootstrap.jar:/usr/local/tomcat-10/bin/tomcat-juli.jar
Using CATALINA_OPTS:
[root@localhost webapps]# /usr/local/tomcat-10/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat-10
Using CATALINA_HOME: /usr/local/tomcat-10
Using CATALINA_TMPDIR: /usr/local/tomcat-10/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat-10/bin/bootstrap.jar:/usr/local/tomcat-10/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
验证
多实例部署
将tomcat-10复制一份
[root@localhost local]# cp -a tomcat-10 ./tomcat-20
清除log日志文件
[root@localhost local]# cd tomcat-20/
[root@localhost tomcat-20]# ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
[root@localhost tomcat-20]# rm -rf logs/*
修改tomcat-20/conf/server.conf文件中的端口
[root@localhost tomcat-20]# vim conf/server.xml
<Server port="8006" shutdown="SHUTDOWN">
<Connector port="8090" protocol="HTTP/1.1"
重启服务
[root@localhost bin]# /usr/local/tomcat-20/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat-20
Using CATALINA_HOME: /usr/local/tomcat-20
Using CATALINA_TMPDIR: /usr/local/tomcat-20/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat-20/bin/bootstrap.jar:/usr/local/tomcat-20/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost bin]# /usr/local/tomcat-10/bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat-10
Using CATALINA_HOME: /usr/local/tomcat-10
Using CATALINA_TMPDIR: /usr/local/tomcat-10/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat-10/bin/bootstrap.jar:/usr/local/tomcat-10/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost bin]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 1 [::ffff:127.0.0.1]:8006 *:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 100 *:8080 *:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 *:8090
、