posts - 52,comments - 0,views - 22059

 负载均衡企业实践应用

复制代码
1) 根据用户访问的uri信息进行负载均衡
第一个历程: 架构环境规划
/upload 集群-10.0.0.7:80 html/www/upload upload服务器集群
/static 集群-10.0.0.8:80 html/www/static static服务器集群
/ 集群-10.0.0.9:80 html/www default服务器集群

web01上进行环境部署:
[root@web01 html]# mkdir /html/www/upload
[root@web01 html]# echo upload-web集群_10.0.0.7 >/html/www/upload/index.html

web02上进行环境部署:
[root@web02 ~]# mkdir /html/www/static
[root@web02 ~]# echo "static-web集群_10.0.0.8" >/html/www/static/index.html

web03上进行环境部署:
echo "default-web集群_10.0.0.9" >/html/www/index.html

第二个历程: 编写负载均衡配置文件
[root@lb01 conf.d]# cat lb.conf
upstream upload {
  server 10.0.0.8:80;
}
upstream static {
  server 10.0.0.7:80;
}
upstream default {
  server 10.0.0.9:80;
}


server {
  listen 80;
  server_name www.oldboy.com;
  location / {
    proxy_pass http://default;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_next_upstream error timeout http_404 http_502 http_403;
  }
  location /upload {
    proxy_pass http://upload;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr; 
    proxy_next_upstream error timeout http_404 http_502 http_403;
  }
  location /static {
    proxy_pass http://static;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_next_upstream error timeout http_404 http_502 http_403;
  }
}
web01:
server {
  location / {
    root /html/www;
    index index.html index.htm;
  }
}

web02:
server {
  location / {
    root /html/www;
    index index.html index.htm;
  }
}

web03:
server {
  location / {
    root /html/www;
    index index.html index.htm;
  }
}
测试:浏览分别访问www.oldboy.com www.oldboy.com/upload www.oldboy.com/static查看显示页面
复制代码

 

复制代码
2) 根据用户访问的终端信息显示不同页面
    第一个历程: 准备架构环境
    iphone   www.oldboy.com  --- iphone_access 10.0.0.7:80  mobile移动端集群
    谷歌     www.oldboy.com  --- google_access 10.0.0.8:80  web端集群
    IE 360   www.oldboy.com  --- default_access 10.0.0.9:80 default端集群
    
    web01:
    echo "iphone_access 10.0.0.7" >/html/www/oldboy.html
    web02:
    echo "google_access 10.0.0.8" >/html/www/oldboy.html
    web03:
    echo "default_access 10.0.0.9" >/html/www/oldboy.html

    第二个历程: 编写负载均衡配置文件
    [root@lb01 conf.d]# cat lb.conf
    upstream web {
       server 10.0.0.8:80;
    }
    upstream mobile {
       server 10.0.0.7:80;
    }
    upstream default {
       server 10.0.0.9:80;
    }
    
    server {
        listen       80;
        server_name  www.oldboy.com;
        location / {
           if ($http_user_agent ~* iphone) {
              proxy_pass http://mobile;
           }
           if ($http_user_agent ~* Chrome) {
             proxy_pass  http://web;
           }
           proxy_pass http://default;
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $remote_addr;
           proxy_next_upstream error timeout http_404 http_502 http_403;
        }
    }
复制代码

 

posted on   宇小白  阅读(51)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示