第一章、负载均衡深入
1.1、调度算法
两个模块:
upstream 服务器池,里面放服务器
upstream backend{
server 10.0.0.7:80 weight=1;
server 10.0.0.7:80 weight=1;
server 10.0.0.9:80 weight=1;
}
这种分配方式叫做负载均衡算法
1.11第一类为静态调度算法
和节点无关的调度算法:rr轮询(默认调度算法,静态调度算法)
wrr(权重轮询,静态调度算法)
ip_hash(静态调度算法,缺点负载不均衡,优点解决会话保持)
会话保持技术:nginx ip_hash 、搭建缓存服务器redis、cookies技术(大公司使用)
解决会话保持 https://blog.51cto.com/oldboy/1331316
1.12第二类动态调度算法
fail (动态调度算法)
least_conn最小调度连接算法
url_hast算法,同一个URL地址,调度给同一台节点
hash(url)===oldgril 调度给某一台机器
http://nginx.org/en/docs/http/ngx_http_upstream_module.html 调度给A服务器
web缓存服务器的负载均衡
一致性HASH算法
1.2、proxy模块
将匹配URI为name的请求抛给http://127.0.0.1/remote/。
server {
listen 80;
server_name blog.etiantian.org;
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name www.etiantian.org;
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}

1.21、根据路径转发
location /name/ {
proxy_pass http://127.0.0.1/remote/;
}
根据url中的目录地址实现代理转发说明
location /name/ {
proxy_pass http://127.0.0.1/remote/;
}
第二章、根据URL中的目录实现动静分离

2.1、案列背景:通过Nginx实现动静分离,即通过Nginx反向代理配置规则实现让动态资源和静态资源及其他业务分别有不同的服务器解析,以解决网站性能、安全、用户体验等重要问题
upstream static_pools {
server 10.0.0.7:80 weight=1;
}
upstream upload_pools {
server 10.0.0.8:80 weight=1;
}
upstream default_pools {
server 10.0.0.9:80 weight=1;
}
location /static/ {
proxy_pass http://static_pools;
}
location /upload/ {
proxy_pass http://upload_pools;
}
location / {
proxy_pass http://default_pools;
}
负载均衡服务器配置配置文件


web01(静态服务器)、web02(上传服务器)、web03(动态服务器)创建目录,增加首页内容













网友评论