资源池

本章资源:点击这里 提取码:upbf

tomcat官网:https://tomcat.apache.org/

jpress博客系统安装包下载地址(不是官网):https://gitee.com/fuhai/jpress/blob/alpha/wars/jpress-web-newest.war

1、Tomcat简介

  • Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成;
  • Tomcat 属于轻量级应用服务器;其技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器;Tomcat处理静态HTML的能力不如Nginx/Apache服务器.
  • 另外它还是一个Servlet和JSP容器,独立的Servlet容器是Tomcat的默认模式。
  • Tomcat是开发和调试JSP程序的首选.

2、Tomcat安装

第一步:下载并上传Tomcat安装包

╭─root@localhost.localdomain ~
╰─➤ rz ╭─root@localhost.localdomain ~
╰─➤ unzip apache-tomcat-9.0.20.zip
╭─root@localhost.localdomain ~
╰─➤ mv apache-tomcat-9.0.20 /usr/local/tomcat #移动并改名
╭─root@localhost.localdomain ~
╰─➤ chmod -R a+x /usr/local/tomcat

第二步:下载Java环境

注意:选择yum安装tomcat需要jdk,就不用再手动配置环境变量

╭─root@localhost.localdomain ~
╰─➤ yum install java -y

第三步:启动Tomcat

╭─root@localhost.localdomain ~
╰─➤ cd /usr/local/tomcat/bin
╭─root@localhost.localdomain /usr/local/tomcat/bin
╰─➤ bash 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
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
╭─root@localhost.localdomain /usr/local/tomcat/bin
╰─➤ ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 :::8009 :::*

第四步:浏览器访问

3、Tomcat目录讲解

╭─root@localhost.localdomain /usr/local/tomcat/bin
╰─➤ cd /usr/local/tomcat
╭─root@localhost.localdomain /usr/local/tomcat
╰─➤ tree -L 1
.
├── bin #用以启动、关闭Tomcat或者其它功能的脚本(.bat文件和.sh文件)
├── BUILDING.txt
├── conf #用以配置Tomcat的XML及DTD文件
├── CONTRIBUTING.md
├── lib #存放web应用能访问的JAR包
├── LICENSE
├── logs #Catalina和其它Web应用程序的日志文件
├── NOTICE
├── README.md
├── RELEASE-NOTES
├── RUNNING.txt
├── temp #临时文件
├── webapps #Web应用程序根目录
└── work #用以产生有JSP编译出的Servlet的.java和.class文件 7 directories, 7 files
╭─root@localhost.localdomain /usr/local/tomcat
╰─➤ cd webapps
╭─root@localhost.localdomain /usr/local/tomcat/webapps
╰─➤ ll
total 4.0K
drwxr-xr-x 14 root root 4.0K May 3 23:27 docs #tomcat帮助文档
drwxr-xr-x 6 root root 83 May 3 23:27 examples #web应用实例
drwxr-xr-x 5 root root 87 May 3 23:27 host-manager #管理
drwxr-xr-x 5 root root 103 May 3 23:27 manager #管理
drwxr-xr-x 3 root root 283 May 3 23:27 ROOT #默认网站根目录

4、Tomcat主配置文件server.xml讲解

╭─root@localhost.localdomain /usr/local/tomcat
╰─➤ cd /usr/local/tomcat/conf/
╭─root@localhost.localdomain /usr/local/tomcat/conf
╰─➤ vim server.xml ...
<Server port="8005" shutdown="SHUTDOWN">
#8005: 接收shutdown指令 <Connector port="8080" protocol="HTTP/1.1"
#8080: 监听的端口 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
#8009: AJP协议
...

4、tomcat同机多服务部署(三台)

第一步:复制两份tomcat文件

╭─root@localhost.localdomain ~
╰─➤ cd /usr/local/
╭─root@localhost.localdomain /usr/local
╰─➤ ls
bin etc games include lib lib64 libexec sbin share src tomcat
╭─root@localhost.localdomain /usr/local
╰─➤ cp -a tomcat tomcat1
╭─root@localhost.localdomain /usr/local
╰─➤ cp -a tomcat tomcat2
╭─root@localhost.localdomain /usr/local
╰─➤ ls
bin etc games include lib lib64 libexec sbin share src tomcat tomcat1 tomcat2

第二步:修改配置文件

╭─root@localhost.localdomain /usr/local
╰─➤ vim tomcat1/conf/server.xml #tomcat1 ...
<Server port="8006" shutdown="SHUTDOWN"> #8005-->8006
...
<Connector port="8081" protocol="HTTP/1.1" #8080-->8081
...
╭─root@localhost.localdomain /usr/local
╰─➤ vim tomcat2/conf/server.xml #tomcat2 ...
<Server port="8007" shutdown="SHUTDOWN"> #8005-->8007
...
<Connector port="8082" protocol="HTTP/1.1" #8080-->8082
...

第三步:分别启动三个tomcat服务

╭─root@localhost.localdomain /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
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
╭─root@localhost.localdomain /usr/local
╰─➤ tomcat1/bin/startup.sh #tomcat1
Using CATALINA_BASE: /usr/local/tomcat1
Using CATALINA_HOME: /usr/local/tomcat1
Using CATALINA_TMPDIR: /usr/local/tomcat1/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat1/bin/bootstrap.jar:/usr/local/tomcat1/bin/tomcat-juli.jar
Tomcat started.
╭─root@localhost.localdomain /usr/local
╰─➤ tomcat2/bin/startup.sh #tomcat2
Using CATALINA_BASE: /usr/local/tomcat2
Using CATALINA_HOME: /usr/local/tomcat2
Using CATALINA_TMPDIR: /usr/local/tomcat2/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat2/bin/bootstrap.jar:/usr/local/tomcat2/bin/tomcat-juli.jar
Tomcat started.

第四步:查看端口

╭─root@localhost.localdomain /usr/local
╰─➤ ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 100 :::8080 :::*
LISTEN 0 100 :::8081 :::*
LISTEN 0 100 :::8082 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8006 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8007 :::*
LISTEN 0 100 :::8009 :::*

第五步:为每个tomcat服务写首页文件

╭─root@localhost.localdomain /usr/local
╰─➤ echo "hello tomcat" >> tomcat/webapps/ROOT/index.html
╭─root@localhost.localdomain /usr/local
╰─➤ echo "hi tomcat1" >> tomcat1/webapps/ROOT/index.html
╭─root@localhost.localdomain /usr/local
╰─➤ echo "morning tomcat2" >> tomcat2/webapps/ROOT/index.html

第五步:浏览器访问

tomcat:



tomcat1:



tomcat2:

5、tomcat集群部署

nginx服务器:192.168.80.4

tomcat服务器:192.168.80.3

第一步:部署tomcat后端节点

  • 参考:4、tomcat同机多服务部署(三台)

第二步:编辑nginx配置文件

╭─root@localhost.localdomain ~
╰─➤ yum install nginx -y
╭─root@localhost.localdomain ~
╰─➤ vim /etc/nginx/nginx.conf ...
# for more information.
include /etc/nginx/conf.d/*.conf;
upstream du {
server 192.168.80.3:8080 weight=3 max_fails=2 fail_timeout=2;
server 192.168.80.3:8081 weight=5 max_fails=2 fail_timeout=2;
server 192.168.80.3:8082 weight=1 max_fails=2 fail_timeout=2;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / {
proxy_pass http://du;
} error_page 404 /404.html;
location = /40x.html {
} error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
...

第三步:检测nginx配置并启动

╭─root@localhost.localdomain ~
╰─➤ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
╭─root@localhost.localdomain ~
╰─➤ systemctl restart nginx

第四步:浏览器访问

6、tomcat上线jpress博客系统

第一步:下载jpress

  • 本章章首有资源池

第二步:上传软件包并解压

╭─root@localhost.localdomain ~
╰─➤ cd /usr/local/tomcat/webapps/ROOT
╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ rm -rf ./*
zsh: sure you want to delete all the files in /usr/local/tomcat/webapps/ROOT/. [yn]? y
╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ rz ╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ unzip fuhai-jpress-alpha.zip

第三步:解压相关文件

╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ cp jpress/wars/jpress-web-newest.war .
╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ unzip jpress-web-newest.war
╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ ls
fuhai-jpress-alpha.zip jpress jpress-web-newest.war META-INF robots.txt static templates WEB-INF

第四步:下载数据库并使用

╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ yum install mariadb-server -y
╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ systemctl restart mariadb
╭─root@localhost.localdomain /usr/local/tomcat/webapps/ROOT
╰─➤ mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database du;
Query OK, 1 row affected (0.01 sec) MariaDB [(none)]> grant all on *.* to du@'localhost' identified by '123';
Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit
Bye

第五步、重启tomcat

╭─root@localhost.localdomain ~
╰─➤ cd /usr/local/tomcat/bin
╭─root@localhost.localdomain /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
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
╭─root@localhost.localdomain /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
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

第六步:浏览器访问

Tomcat简介、安装部署、上线网站的更多相关文章

  1. TOMCAT的安装部署配置(配图解)

    TOMCAT的安装部署配置 前提已经成功搭建配置JDK 下载好压缩包后,直接解压至某一目录下,目录中不能包含中文 双击安装文件,出现如下界面 点击[NEXT],出现如下界面 点击[I AGREE],出 ...

  2. 01 . Tomcat简介及部署

    Tomcat简介 Tomcat背景 tomcat就是常用的的中间件之一,tomcat本身是一个容器,专门用来运行java程序,java语言开发的网页.jsp就应该运行于tomcat中.而tomcat本 ...

  3. tomcat的安装部署

    第一步: 先把压缩包拖到知道的目录,解压 tar xf apache-tomcat-8.0.27.tar.gz -C /usr/local/ ln -s /usr/local/apache-tomca ...

  4. tomcat+jdk安装部署

    安装tomcat tar zxf jdk-8u66-linux-x64.tar.gz mkdir /application/java/ -p mv /home/oldboy/tools/jdk1.8. ...

  5. tomcat的安装部署(windows10)

    一.Tomact下载 地址:https://tomcat.apache.org/

  6. HappyAA服务器部署笔记1(nginx+tomcat的安装与配置)

    这是本人的服务器部署笔记.文章名称叫"部署笔记1"的原因是之后我对这个进行了改进之后,会有"部署笔记2","部署笔记3"...循序渐进,估计 ...

  7. Tomcat安装部署和安全加固优化以及反向代理应用

    1.Tomcat介绍 Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache.Sun和其他一些公司及个人共同 ...

  8. 二十二. 安装部署Tomcat服务器、使用Tomcat部署虚拟主机、使用Varnish加速Web

    web proxy web1 web2   1.安装部署Tomcat服务器 web1 1.1 使用RPM安装JDK环境 ]# yum -y install java-1.8.0-openjdk ]# ...

  9. 高级运维(四):Nginx常见问题处理、安装部署Tomcat服务器、使用Tomcat部署虚拟主机

    一.Nginx常见问题处理 目标: 本案例要求对Nginx服务器进行适当优化,以提升服务器的处理性能: 1> 不显示Nginx软件版本号 2> 如果客户端访问服务器提示“Too many ...

随机推荐

  1. OpenManipulator RM-X52 ROS 开源机械臂

    DYNAMIXEL PRO PH54-200-S500-R  简介

  2. Salesforce 大数据量处理篇(一)Skinny Table

    本篇参考:https://developer.salesforce.com/docs/atlas.en-us.salesforce_large_data_volumes_bp.meta/salesfo ...

  3. Spark学习进度-实战测试

    spark-shell  交互式编程 题目:该数据集包含了某大学计算机系的成绩,数据格式如下所示: Tom,DataBase,80 Tom,Algorithm,50 Tom,DataStructure ...

  4. dede 织梦的安装 出现dir

    安装dede系统.(如果您已经安装,请跳过本步.)直接运行:http://您的域名/install如果没有出现该页面,而是出现了一个空白页面写着dir 那么请删除install文件夹中的 instal ...

  5. STP、PVST、MST协议

    • STP:生成树协议        ○ 阻止环形链路的广播风暴    • PVST:VLAN生成树        ○ 是STP的进阶版不仅能阻止广播风暴,还可以做到基于VLAN进行流量均衡.     ...

  6. 【JavaWeb】Servlet 程序

    Servlet 程序 Servlet Servlet 是在 Web 服务器中运行的小型 Java 程序.Servlet 通常通过 HTTP(超文本传输​​协议)接收和响应来自 Web 客户端的请求. ...

  7. zabbix_agent items not supported状态

    不记得自己究竟更改了什么东西,然后突然发现所有的有关mysql的监控items都变成了not supported,怎么做不行,最后在web主页把主机删除,又重新添加一下,重新添加了一下模版就好了.这究 ...

  8. Github Python计算器开源项目 二次开发--增加函数图形

    先上原项目链接:https://github.com/xhf79/Calculator_pyqt python+Qt 开发的计算器 原项目界面和功能如图所示: 科学计算的内容基本都有,但按照项目的提示 ...

  9. Ubuntu16.04安装MySQL8.0

    1.Ubuntu换源(阿里云) sudo cp /etc/apt/sources.list /etc/apt/sources.list.baksudo vi /etc/apt/sources.list ...

  10. iptables自动屏蔽访问网站最频繁的IP

    iptables自动屏蔽访问网站频繁的IP 屏蔽每分钟访问超过200的IP 方法1:根据访问日志(Nginx为例 #!/bin/bash DATE=$(date +%d/%b/%Y:%H:%M) AB ...