upstream模块调度算法
反向代理调度算法,轮询算法--——领导如何挑选小弟。迎宾小姐如何挑选服务员。
调度一般分为两类,第一类为静态调度算法,即负载均衡器根据自身设定的规划进行分配,不需要考虑节点的情况,例如,rr、wrr、ip_hash等都属于静态调度算法。
第二类动态算法,即负载均衡会根据后端节点的当前状态来决定是否分发请求,例如:连接数少的优秀获得请求,响应时间短的优先获得请求。例如:least_conn、fair等都属于动态调度算法。
1.rr轮询(round robin默认调度算法,静态调度算法)
按客户请求顺序吧客户端强求足已分配到不同的后端节点服务器,这相当于LVS中的rr算法,如果后端服务器宕机(默认情况下Nginx只检测80端口),宕机的服务器会被自动从节点服务池中国剔除,以使用客户端的用户访问不受影响。新的请求会分配给正常的服务器。
2.wrr(weight加权轮询,静态调度算法)
在rr轮询算法的基础加上权重,即为权重轮询算法,当使用该算法时,权重和用户访问成正比,权重值越大,被转发的请求也就越多。可以根据服务器的配置和性能指定加权值的大小,有效解决新旧服务器性能不均衡的请求分配问题。
举个例子帮助大家加深理解。
3.ip_hash(静态调度算法)
每个请求按客户端的hash结果分配,当新的请求到达时,先将客户端IP通过哈希算法出一个值,在随后的客户端请求中,客户IP的哈希值只要相同,就会分配至同一个值,在随后的客户端请求中,客户IP的哈希孩子只要相同,就会被分配至同一台服务器,该调度算法可以解决动态网页的session共享问题,但有时会导致请求请求分配不均,既无法保证1:1的负载均衡,因为在国内大多数公司都是NAT上网模式,多个客户端会对应一个外部IP,所以,这些客户端都会被分配到同一个服务器,从而导致请求分配不均。LVS负载均衡的-p参数、keepalived_timeout50参数都类似这个Nginx里的ip_hash参数,其功能均为解决动态网页的session共享问题

cookie客户端浏览器
变量名字和变量的内容
开发人员制定
相同网站,访问相同的cookie
钥匙(字符串 文本)
请求头和响应头里面的
session服务器
用户密码 登录信息(登录) ……打包 加密……锁头
eash_conn
lesh_conn算法会根据后端节点连接数来决定分配情况,哪个集群连接数少就分发。
5.url_hash算法
和ip_hash算法类似,这里是根据访问的hash结果请求的,让每个URL定向到同一个后端服务器,后端服务器为缓冲服务器效果显著。
在upstream中加入hash语句,server语句中不能写入weight等其他参数,hash_method使用的是hash算法
cd /application/nginx/conf/
pwd
#/application/nginx/conf
hostname
lb01
cp nginx.conf{,.bak.before.upsteam}
cat nginx.conf
准备
#测试weight次数 权重
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; upstream server_pools {
server 10.0.0.7:80 weight=2;
server 10.0.0.8:80 weight=1;
server 10.0.0.9:80 weight=1;
} server {
listen 80;
server_name www.etiantian.org;
location / {
proxy_pass http://server_pools;
}
}
} /application/nginx/sbin/nginx -t lsof -i:80
/application/nginx/sbin/nginx curl 10.0.0.5/bingbing.html #测试weight=4 max_fails=3 fail_timeout=30s; #测试命令
for n in {1..1000};do curl -s 10.0.0.5/bingbing.html|grep "[78]$";sleep 1;date +%T;done worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; upstream server_pools {
server 10.0.0.7:80 weight=4 max_fails=3 fail_timeout=30s;
server 10.0.0.8:80 weight=4 max_fails=3 fail_timeout=30s;
# server 10.0.0.9:80 weight=1;
} server {
listen 80;
server_name www.etiantian.org;
location / {
proxy_pass http://server_pools;
}
}
}
#测试weight次数 权重
#测试backup热备功能
#把7/8/服务器Nginx功能关掉看看是否9出来
#当7或8启动,9就关闭 #7/8执行
killall nginx
/application/nginx/sbin/nginx #了解
#sed -i 'N;s#\n10.0.0.255# #g' /application/nginx/html/{www,bbs}/bingbing.html #在lb01测试
for n in {1..1000};do curl -s 10.0.0.5/bingbing.html;sleep 1;date +%T;done worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; upstream server_pools {
server 10.0.0.7:80 weight=4 max_fails=3 fail_timeout=30s;
server 10.0.0.8:80 weight=4 max_fails=3 fail_timeout=30s;
server 10.0.0.9:80 weight=4 max_fails=3 fail_timeout=30s backup;
} server {
listen 80;
server_name www.etiantian.org;
location / {
proxy_pass http://server_pools;
}
}
}
#测试backup热备功能
#ip_hash测试
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; upstream server_pools {
ip_hash;
server 10.0.0.7:80 weight=4 max_fails=3 fail_timeout=30s;
server 10.0.0.8:80 weight=4 max_fails=3 fail_timeout=30s;
server 10.0.0.9:80 weight=4 max_fails=3 fail_timeout=30s;
} server {
listen 80;
server_name www.etiantian.org;
location / {
proxy_pass http://server_pools;
}
}
}
######nginx.conf multi vhosts #解决方法
#proxy_set_header #看抓包工具
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; upstream server_pools {
server 10.0.0.7:80 weight=4 max_fails=3 fail_timeout=30s;
server 10.0.0.8:80 weight=4 max_fails=3 fail_timeout=30s;
server 10.0.0.9:80 weight=4 max_fails=3 fail_timeout=30s;
} server {
listen 80;
server_name www.etiantian.org;
location / {
proxy_pass http://server_pools;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name bbs.etiantian.org;
location / {
proxy_pass http://server_pools;
proxy_set_header Host $host;
}
}
}
#ip_hash测试
upstream模块调度算法的更多相关文章
- 基于LNMP(fastcgi协议)环境部署、原理介绍以及fastcgi_cache配置以及upstream模块负载均衡讲解
ngx_http_proxy_module只能反向代理后端使用HTTP协议的主机.而ngx_http_fastcgi_module只能反向代理后端使用FPM或者使用FastCGI协议的客户端. 一.部 ...
- nginx upstream模块--负载均衡
Module ngx_http_upstream_module英文文档 upstream模块相关说明1.upstream模块应放于nginx.conf配置的http{}标签内2.upstream模块默 ...
- [转帖]nginx upstream模块--负载均衡
nginx upstream模块--负载均衡 https://www.cnblogs.com/linjiqin/p/5494783.html Module ngx_http_upstream_modu ...
- Nginx - upstream 模块及参数测试
目录 - 1. 前言- 2. 配置示例及指令说明 - 2.1 配置示例 - 2.2 指令 - 2.3 upstream相关变量- 3. 参数配置及测试 - 3.1 max_fa ...
- nginx之proxy、cache、upstream模块学习
nginx之proxy反向代理模块: location ^~ /proxy_path/ { root "/www/html"; 这里没必要配置 index index.html; ...
- nginx的stream模块和upstream模块
nginx7层调度方式 使用upstream模块定义集群名称和节点地址 定义在server字段之外httpd字段之内 upstream staticweb { server 172.17.0.2; # ...
- nginx upstream模块
upstream模块 upstream模块 (100%) nginx模块一般被分成三大类:handler.filter和upstream.前面的章节中,读者已经了解了handler.filter. 利 ...
- Nginx Upstream模块源码分析(上)
Upstream模块是一个很重要的模块,很多其他模块都会使用它来完成对后端服务器的访问, 达到反向代理和负载均衡的效果.例如Fastcgi.Memcached.SessionSticky等. 如果自己 ...
- nginx系列10:通过upstream模块选择上游服务器和负载均衡策略round-robin
upstream模块的使用方法 1,使用upstream和server指令来选择上游服务器 这两个指令的语法如下图: 示例: 2,对上游服务使用keepalive长连接 负载均衡策略round-rob ...
随机推荐
- 浅谈MFC类CrackMe中消息处理函数查找方法
最近一个学姐发给我了一份CrackMe希望我解一下,其中涉及到了MFC的消息函数查找的问题,就顺便以此为例谈一下自己使用的消息函数查找的方法.本人萌新,如果有任何错漏与解释不清的地方,欢迎各路大佬指正 ...
- --defaults-file 不能用?
今天在测试mysql多实例时发现mysqld_safe --user --defaults-file 怎么都无法启动,后来发现是必须按顺序,先写--defaults-file才可以. mysqld_s ...
- H+ 添加(新增)Tab选项卡
//注:在contabs.js文件中 $(function () { }); 方法外 加入//注: data-name="' + menuName + '" 这句是加入的自定义属性 ...
- canvas 水滴图、液体进度条、仿加速球、圆球水波图
传送门:https://github.com/guoyoujin/WaterMoire <!DOCTYPE html> <html lang="en"> & ...
- python itertools 模块讲解
1.介绍itertools 是python的迭代器模块,itertools提供的工具相当高效且节省内存. 使用这些工具,你将能够创建自己定制的迭代器用于高效率的循环. - 无限迭代器 itertool ...
- atitit r9 doc on home ntpc .docx
卷 p2soft 的文件夹 PATH 列表 卷序列号为 9AD0-D3C8 D:. │ Aittit pato 面对拒绝 的回应.docx │ Atitit 中国明星数量统计 attilax. ...
- SQL Server 2016新特性:列存储索引新特性
SQL Server 2016新特性:列存储索引新特性 行存储表可以有一个可更新的列存储索引,之前非聚集的列存储索引是只读的. 非聚集的列存储索引支持筛选条件. 在内存优化表中可以有一个列存储索引,可 ...
- ionic入门教程-ionic路由详解(state、route、resolve)(转)
http://blog.csdn.net/onil_chen/article/details/51758696?appinstall=0 今天好好的跟大家讲讲ionic的路由配置. 问到的朋友有点多, ...
- 简单探讨spring整合mybatis时sqlSession不需要释放关闭的问题
https://blog.csdn.net/RicardoDing/article/details/79899686 近期,在使用spring和mybatis框架编写代码时,sqlSession不需要 ...
- java通过jdbc访问mysql,update数据返回值的思考
java通过jdbc访问mysql,update数据返回值的思考 先不说那么多,把Java代码贴出来吧. public static void main(String[] args) throws I ...