负载均衡企业实践应用

一、动静分离网站集群架构

实验环境准备:

 /upload    集群-10.0.0.8:80  html/www/upload    upload服务器集群
 /static      集群-10.0.0.7:80  html/www/static       static服务器集群
 /              集群-10.0.0.9:80  html/www                 default服务器集群

根据用户访问的uri信息进行负载均衡 

   第一个历程: 架构环境规划
    /upload   集群-10.0.0.8:80  html/www/upload    upload服务器集群
    /static   集群-10.0.0.7:80  html/www/static    static服务器集群
    /         集群-10.0.0.9:80  html/www           default服务器集群
    
    web02上进行环境部署:
    [root@web02 ~]# mkdir /html/www/upload
    [root@web02 ~]# echo  "upload-web集群_10.0.0.8" >/html/www/upload/index.html
    web01上进行环境部署:
    [root@oldboy01 html]# mkdir /html/www/static
    [root@oldboy01 html]# echo static-web集群_10.0.0.7 >/html/www/static/index.html
    web03上进行环境部署:
    echo  "default-web集群_10.0.0.9" >/html/www/index.html    

    第二个历程: 编写负载均衡配置文件
    [root@lb01 /etc/nginx/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.test.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;
        }
    } 
       第三个历程: 打开浏览器测试
     www.test.com/static/
     static-web集群_10.0.0.7

     www.test.com/upload/
     upload-web集群_10.0.0.8

     www.test.com
     default-web集群_10.0.0.9






  总结: 实现网站集群动静分离
    01. 提高网站服务安全性
    02. 管理操作工作简化
    03. 可以换分不同人员管理不同集群服务器

 

二、根据用户访问的终端信息显示不同页面

    根据用户的user_agent显示不同页面
    第一个历程: 准备架构环境
    iphone   www.test.com  --- iphone_access   10.0.0.7:80  mobile移动端集群
    谷歌     www.test.com  --- google_access   10.0.0.8:80  web端集群
    IE 360   www.test.com  --- default_access  10.0.0.9:80 default端集群
    
    web01:
    echo "iphone_access 10.0.0.7" >/html/www/test.html
    web02:
    echo "google_access 10.0.0.8" >/html/www/test.html
    web03:
    echo "default_access 10.0.0.9" >/html/www/test.html

    第二个历程: 编写负载均衡配置文件
    [root@lb01 /etc/nginx/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.test.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;
          }
  }
    第三个历程: 打开浏览器进行测试
    www.test.com/test.html
    如果是iPhone显示:iphone_access 10.0.0.7
    如果是谷歌浏览器显示:google_access 10.0.0.8
    IE和360显示:default_access 10.0.0.9

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值