当前位置: 首页 > news >正文

负载均衡-动静分离实验

文章目录

    • 访问流程
    • 实验环境
    • 实验需求
    • 实验步骤
      • 1、搭建web01的静态资源
      • 2、搭建web02的动态资源
      • 3、部署lb01
      • 4、验证

访问流程

实验环境

系统服务服务内网地址
CentOS7.7负载均衡Nginx Proxy10.0.0.5
CentOS7.7静态资源Nginx Static10.0.0.7
CentOS7.7动态资源Tomcat Server10.0.0.8

实验需求

动静分离,通过中间件将动态请求和静态请求进行分离, 分离资源, 减少不必要的请求消耗, 减少请求延时。
好处: 动静分离后, 即使动态服务不可用, 但静态资源不会受到影响,通过中间件将动态请求和静态请求分离

实验步骤

1、搭建web01的静态资源

#安装nginx[root@web01~]# yum -y localinstall nginx-1.20.2-1.el7.ngx.x86_64.rpm#编辑配置文件[root@web01~]# cat /etc/nginx/conf.d/www.confserver{listen80;server_name www.jy.com;}location/{root/code/www;index index.html;location~*\.(png|jpg|gif)${root/code/www/images;}}#创建目录,上传图片[root@web01~]# mkdir /code/www/images[root@web01 images]# ls1.png#启动服务[root@web01~]# systemctl restart nginx[root@web01~]# systemctl enable nginxCreated symlink from/etc/systemd/system/multi-user.target.wants/nginx.service to/usr/lib/systemd/system/nginx.service.

2、搭建web02的动态资源

#安装tomcat[root@web02~]# yum install -y tomcat#启动tomcat[root@web02~]# systemctl start tomcat#编写默认页面[root@web02~]# mkdir /usr/share/tomcat/webapps/ROOT[root@web02~]# vi /usr/share/tomcat/webapps/ROOT/java_test.jsp<%@ page language="java"import="java.util.*"pageEncoding="utf-8"%><HTML><HEAD><TITLE>JSPTest Page</TITLE></HEAD><BODY><%Random rand=newRandom();out.println("<h1>Random number:</h1>");out.println(rand.nextInt(99)+100);%></BODY></HTML>

3、部署lb01

#安装nginx[root@lb01~]# yum -y localinstall nginx-1.20.2-1.el7.ngx.x86_64.rpm#编写配置文件vim/etc/nginx/proxy_params proxy_set_headerHost$http_host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_connect_timeout30;proxy_send_timeout60;proxy_read_timeout60;proxy_buffering on;proxy_buffer_size32k;proxy_buffers4128k;#编写反向代理配置文件[root@lb01~]# vim /etc/nginx/conf.d/proxy.confupstreamstatic{server10.0.0.7:80;}upstream java{server10.0.0.8:8080;}server{listen80;server_name www.jy.com;location/{root/web/www;index index.html;}location~.*\.(png|jpg|gif)${proxy_passhttp://static;includeproxy_params;}location~.*\.jsp${proxy_passhttp://java;includeproxy_params;}}## 编写页面文件[root@lb01~]# mkdir -p /web/www[root@lb01~]# vi /web/www/index.html<html lang="en"><head><meta charset="UTF-8"/><title>测试ajax和跨域访问</title><script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script></head><script type="text/javascript">$(document).ready(function(){$.ajax({type:"GET",url:"http://www.jy.com/java_test.jsp",#域名可以修改自己的,后面是Tomcat创建的路径success:function(data){$("#get_data").html(data)},error:function(){alert("fail!!,请刷新再试!");}});});</script><body><h1>测试动静分离</h1><img src="http://www.jy.com/1.png">#修改为存放静态图片的 文件名字<div id="get_data"></div></body></html>#重启nginx[root@lb01~]# systemctl restart nginx#修改hosts文件172.16.1.5www.jy.com

4、验证

动态网页

访问 “http://www.tf.com/java_test.jsp”,

http://www.cnnetsun.cn/news/127423.html

相关文章:

  • 20、微软 Windows Vista 使用指南:账户管理与数据保护
  • 15、活动目录用户与组管理操作指南
  • 17、活动目录计算机对象与组织单位管理指南
  • 12、Ourmon:网络监控与异常检测工具全解析
  • 22、恶意软件分析与检测全解析
  • 产品解读 | Ftrans SFT:信创浪潮下的FTP替代革命者
  • 继何恺明DyT后,LayerNorm再遭暴击!简单erf函数竟成Transformer新宠
  • C语言链表2
  • 蜣螂优化(DBO)算法在工程实际中求目标函数最小值的例子:压力容器设计成本最小化的4变量4约束...
  • 12、游戏内存中常见数据结构解析
  • 21、游戏响应式黑客技术全解析
  • 26、游戏隐藏与反检测技术全解析
  • Kotaemon网络安全问答:CVE漏洞快速查询
  • Kotaemon能否自动识别问题紧急程度?
  • 复杂时序场景的突围:金仓数据库是凭借什么超越InfluxDB?
  • 特价股票投资中的跨境投资策略与风险管理
  • 为分析经理制定全面的仪表板策略
  • MATLAB实现神经网络的模式识别
  • 17、在 Linux 系统中运行 Windows 程序及优化工作流
  • Kotaemon索引构建优化:FAISS vs HNSW性能对比
  • Kotaemon在低资源环境下的轻量化改造方案
  • 16、企业 Linux 桌面迁移与后台基础设施搭建指南
  • 19、数据迁移与备份:从 Windows 到 Linux 的全面指南
  • Kotaemon销售谈判策略建议:促成交易技巧
  • 特征工程中的特征构造技巧:大数据分析的创新实践
  • 32、Linux在不同场景下的应用优势与案例分析
  • 26、深入了解GNU Lesser General Public License
  • Hive实战任务 - 9.2 统计总分与平均分
  • Hive实战任务 - 9.3 实现学生信息排序和统计
  • 1、深入解析 Windows 2000 终端服务与 Citrix MetaFrame 配置