tomcat的负载均衡、动静分离(nginx联动)

动静分离:

访问静态页面和动态页面分开

实现动态和静态页面负载均衡

实验5台虚拟机

一、动态负载均衡

3台虚拟机模拟:

代理服务器:30

tomcat动态页面:21、22

代理服务器:

proxy_pass http://tomcat;

proxy_set_header HOST $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

进html/index.html配置前端页面

tomcat后端服务器:

tomcat:两个都进入webapps 创建test目录,在下面创建index.jsp文件

cd /usr/local/tomcat/webapps

mkdir test

cd test

touch index.jsp

输入:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%

>

<html>

<head>

<title>JSP test1 page</title>

</head>

<body>

<% out.println("动态页面1,http://www.test1.com");%>

</body>

</html>

更改server.xml:

148自带host删除

最后几行host更改:(复制进去要看有没有自动换行什么的)

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

<Context docBase="/usr/local/tomcat/webapps/test" path="" reloadable="true" />

</Host>

重启tomcat

访问20.0.0.30/index.jsp

实现动态页面负载均衡

二、四层+七层+动静分离

需要5台服务器:

  1. nginx代理
  2. 静态页面请求转发服务器
  3. tomcat服务器

代理30

tomcat动态21 22

静态 23 40

代理服务器:

下面端口号要加

下面server中端口也是80,需要改一下

配置2 3nginx静态页面服务器

location ~* \.jsp$ {

proxy_pass http://tomcat;

proxy_set_header HOST $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

配置静态页面:html/inde.html

代理服务器的index.html要清空删除

20.0.0.30:8080请求静态

看是否负载均衡

浏览器有时候做不了负载均衡,curl 20.0.0.30查看就行

访问20.0.0.30/index.jsp

相关推荐
call me by ur name1 分钟前
多模态大模型轻量化
前端·网络·人工智能
岳来2 分钟前
docker 容器重启策略RestartPolicy
运维·docker·容器·restartpolicy
IMPYLH2 分钟前
Linux 的 tty 命令
linux·运维·服务器·bash
@王先生13 分钟前
rancher安装--针对报错API Aggregation not ready
linux·运维·rancher
Lee川4 分钟前
登录注册模块的 JWT 认证机制详解
前端·后端·react.js
能喵烧香5 分钟前
鸿潮万相:全品类OpenHarmony定制发行版全景详解
linux·系统架构·开源
夜猫子ing8 分钟前
《嵌入式 Linux 控制服务从零搭建(二):从目录结构到 CMakeLists,搭一个像样的 C++ 工程骨架》
java·前端·c++
风曦Kisaki10 分钟前
#Linux Shell 编程入门 Day04:正则表达式(egrep模糊匹配)与 sed流式编辑器
linux·正则表达式·编辑器
海盗船长没有船y2 小时前
避坑指南:Ubuntu 启动报错 “Unable to mount root fs“ 的深层诱因与修复
linux·ubuntu·故障排除·dkms
东风微鸣2 小时前
Ubuntu 26.04 游戏配置指南:魔兽争霸3 Dota1
linux·ubuntu·游戏