首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >负载均衡企业实践应用

负载均衡企业实践应用

作者头像
萧晚歌
发布2020-08-19 11:06:41
1.4K0
发布2020-08-19 11:06:41
举报
文章被收录于专栏:linux技术分享linux技术分享

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

所在路径

IP地址

路径

集群

/upload

192.168.100.101

html/www/upload

upload服务器集群

/static

192.168.100.102

html/www/static

static服务器集群

/

192.168.100.103

html/www

default服务器集群

192.168.100.104

负载均衡服务器

web01上进行环境部署:

[root@webl ~]# mkdir /html/www/static

[root@web1 ~]# echo "static-web集群_192.168.100.101" >/html/www/static/index.html

web02上进行环境部署:

[root@web02 ~]# mkdir /html/www/upload

[root@web02 ~]# echo "upload-web集群_192.168.100.102" >/html/www/upload/index.html

web03上进行环境部署:

[root@web3 ~]# echo  "default-web集群_192.168.100.103" >/html/www/index.html    

第二个历程: 编写负载均衡配置文件

[root@lb01 conf.d]# cat lb.conf

    upstream static {

       server 192.168.100.101:80;

    }

    upstream upload {

       server 192.168.100.102:80;

    }

    upstream default {

       server 192.168.100.103:80;

    }

    server {

        listen       80;

        server_name  www.xxs.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;

        }

    }

[root@lb01 conf.d]# curl www.xxs.com

default-web集群_192.168.100.103

[root@lb01 conf.d]# curl www.xxs.com/upload

upload-web集群_192.168.100.102

[root@lb01 conf.d]# curl www.xxs.com/static

static-web集群_192.168.100.101

总结: 实现网站集群动静分离

    01. 提高网站服务安全性

    02. 管理操作工作简化

    03. 可以换分不同人员管理不同集群服务器

 根据用户的终端信息显示不同页面

web01:

echo "iphone_access 192.168.100.101" >/html/www/index.html

web02:

echo "google_access 192.168.100.102" >/html/www/index.html

web03:

echo "default_access 192.168.100.103" >/html/www/index.html

编写负载均衡配置文件

[root@lb01 conf.d]# cat lb.conf

    upstream app {

       server 192.168.100.101:80;

    }

    upstream web {

       server 192.168.100.102:80;

    }

    upstream default {

       server 192.168.100.103:80;

    }

    server {

        listen       80;

        server_name  www.oldboy.com;

        location / {

           if ($http_user_agent ~* iphone) {

              proxy_pass http://app;

           }

           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;

        }

    }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-06-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
负载均衡
负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档