第十二周-day52(上)-负载均衡的设备转换、动静分离与高可用介绍_负载均衡 切换 设备(2)

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前在阿里

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以点击这里获取!

[root@lb01 nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb01 nginx]# systemctl reload nginx



> 
> 记得将之前环境中的其他模块一起修改或暂时注释掉,不然语法会报错
> 
> 
> 



> 
> #### 2.curl一下查看结果
> 
> 
> curl -A 可以指定系统
> 
> 
> 



[root@lb01 nginx]# curl 10.0.0.5/lidao.html
this is PC website
[root@lb01 nginx]# curl -A ios 10.0.0.5/lidao.html
this is Mobile website
[root@lb01 nginx]# curl -A Android 10.0.0.5/lidao.html
this is Mobile website


#### 3.可以下载火狐浏览器查看



> 
> <http://www.firefox.com.cn/>  
>  安装插件流程:  
>  ![](https://upload-images.jianshu.io/upload_images/16952149-d81b88b9ab9d7f32.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](https://upload-images.jianshu.io/upload_images/16952149-2ee4ef62312bccfe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](https://upload-images.jianshu.io/upload_images/16952149-8e054751fabfc8ef.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](https://upload-images.jianshu.io/upload_images/16952149-d4cbe91a050b43e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](https://upload-images.jianshu.io/upload_images/16952149-03308cc520a05f21.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
> 
> 
> 


## 三、根据 URI 中的目录地址实现代理转发(动静分离)



> 
> 添加一台测试web03节点—10.0.0.9  
>  将web03的配置与web01和web02配置相同  
>  (/app站点目录与nginx.conf配置文件)
> 
> 
> 



> 
> ![](https://upload-images.jianshu.io/upload_images/16952149-dec84f2075176f21.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)  
>  ![](https://upload-images.jianshu.io/upload_images/16952149-9116b8885a477eeb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
> 
> 
> 


#### 1.准备环境



www.oldboy.com/upload/index.html
www.oldboy.com/static/index.html
www.oldboy.com/index.html

#web01:
mkdir -p /app/www/upload/index.html
echo this is upload >/app/www/index.html
[root@web01 ~]# cat /app/www/upload/index.html
this is upload

#web02:
mkdir -p /app/www/static/index.html
echo this is static >/app/www/index.html
[root@web02 ~]# cat /app/www/static/index.html
this is static

#web03:
mkdir -p /app/www/index.html #之前已经有首页文件,只需修改内容
echo this is default >/app/www/index.html
[root@web03 ~]# cat /app/www/index.html
this is default


#### 2.配置 upstream 与location



> 
> 定义upstream.
> 
> 
> 



 upstream  upload {
 server 10.0.0.7:80 weight=1 max_fails=3 fail_timeout=10s;
 }
 upstream static {
 server 10.0.0.8:80 weight=1 max_fails=3 fail_timeout=10s;
 }
 upstream default {
 server 10.0.0.9:80 weight=1 max_fails=3 fail_timeout=10s;
 }


> 
> 添加location
> 
> 
> 



 server {
 listen 80;
 server_name www.oldboy.com;
 location /upload {
     proxy_pass http://upload;
     proxy_set_header Host $host;
     proxy_set_header X-Forwarded-For $remote\_addr;
    }
 location /static {
     proxy_pass http://static;
     proxy_set_header Host $host;
     proxy_set_header X-Forwarded-For $remote\_addr;
    }
 location /default {
     proxy_pass http://default;
     proxy_set_header Host $host;
     proxy_set_header X-Forwarded-For $remote\_addr;
    }
 }


> 
> 完整配置  
>  ![](https://upload-images.jianshu.io/upload_images/16952149-8a0a72b903cc7e7c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
> 
> 
> 



[root@lb01 nginx]# vim nginx.conf

upstream upload {
server 10.0.0.7:80 weight=1 max_fails=3 fail_timeout=10s;
}
upstream static {
server 10.0.0.8:80 weight=1 max_fails=3 fail_timeout=10s;
}
upstream default {
server 10.0.0.9:80 weight=1 max_fails=3 fail_timeout=10s;
}

include /etc/nginx/conf.d/*.conf;

 server {
 listen 80;
 server_name www.oldboy.com;
 location /upload {
     proxy_pass http://upload;
     proxy_set_header Host $host;
     proxy_set_header X-Forwarded-For $remote\_addr;
    }
 location /static {
     proxy_pass http://static;
     proxy_set_header Host $host;
     proxy_set_header X-Forwarded-For $remote\_addr;
    }
 location / {
     proxy_pass http://default;
     proxy_set_header Host $host;
     proxy_set_header X-Forwarded-For $remote\_addr;
    }
 }

}
[root@lb01 nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb01 nginx]# systemctl reload nginx


#### 3.浏览器测试一下



> 
> 上传![](https://img-blog.csdnimg.cn/img_convert/f361b0f3f0335a0f143c4052f6f11446.webp?x-oss-process=image/format,png)静态![](https://img-blog.csdnimg.cn/img_convert/ba47b8f2c6a2ddb4bb5a8a6eee674acb.webp?x-oss-process=image/format,png)动态(默认)![](https://img-blog.csdnimg.cn/img_convert/9c331f5767ebecd784c3e7929f206411.webp?x-oss-process=image/format,png)
> 
> 
> 




---


## 四、轮询算法


![](https://img-blog.csdnimg.cn/img_convert/69cd9920128a5c59df690116a493dd2b.webp?x-oss-process=image/format,png)



> 
> ip\_hash  
>  只要客户端ip地址相同就会被转发到同一台机器上  
>  ![](https://img-blog.csdnimg.cn/img_convert/84afa87a04cf77285adefc352085e850.webp?x-oss-process=image/format,png)
> 
> 
> 


## 六、cookie与session会话区别



> 
> 会话保持  
>  cookie  
>  session
> 
> 
> 


#### 1.共同点



> 
> 存放用户信息  
>  key value类型 变量和变量内容


**先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前在阿里**

**深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**

**因此收集整理了一份《2024年最新Linux运维全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
![img](https://img-blog.csdnimg.cn/img_convert/05c6eb2d650d886f75f56506d6358da8.png)
![img](https://img-blog.csdnimg.cn/img_convert/b48fc4cebf3703a8625df7c34ed36d7c.png)
![img](https://img-blog.csdnimg.cn/img_convert/d09255490b96e3062617ba90565109d2.png)
![img](https://img-blog.csdnimg.cn/img_convert/3a046f4eae8308ec0223e8af31ec9cf9.png)
![img](https://img-blog.csdnimg.cn/img_convert/58ad9310375c82540da28aee92da64c7.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**

-1715529157723)]
[外链图片转存中...(img-iYP4XplT-1715529157723)]

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上运维知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值