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 ...
随机推荐
- bootstrap-3-fileinput上传案例
效果 导入的js和css <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/ ...
- 什么?又是404!趣图助你理解HTTP状态码~
HTTP状态码(一): 注释: 301—永久移动.被请求的资源已被永久移动位置: 302—请求的资源现在临时从不同的 URI 响应请求: 305—使用代理.被请求的资源必须通过指定的代理才能被访问 ...
- pip install whl
$ pip install --download /tmp/offline_packages -r requirements.txt $ pip install --no-index --find-l ...
- shouldComponentUpdate 是做什么的,(react 性能优化是哪个周期函数?)
shouldComponentUpdate询问组件是否需要更新的一个钩子函数,判断数据是否需要重新渲染,返回一个布尔值.默认的返回值是true,需要重新render().若如果返回值是false则不触 ...
- 关于 Docker Hub 上不能注册 Docker ID 的问题
1. 引言 我们中国大陆访问dockerhub的时候,想要注册一个dockerID,发现sign up按钮是灰色的,不能点击进行注册.这个时候通过点击右键"查看网页源代码"和&qu ...
- [转]调试利器-SSH隧道
在开发微信公众号或小程序的时候,由于微信平台规则的限制,部分接口需要通过线上域名才能正常访问.但我们一般都会在本地开发,因为这能快速的看到源码修改后的运行结果.但当涉及到需要调用微信接口时,由于不和你 ...
- Mac上安装mysqlclient的报错
[背景] 今天我把算把自己的python基础平台从python-3.6.2升级到python-3.7.2,在我安装完python-3.7.2之后,打算在此基础之上安装 mysqlclient的时候报错 ...
- 【原创 深度学习与TensorFlow 动手实践系列 - 4】第四课:卷积神经网络 - 高级篇
[原创 深度学习与TensorFlow 动手实践系列 - 4]第四课:卷积神经网络 - 高级篇 提纲: 1. AlexNet:现代神经网络起源 2. VGG:AlexNet增强版 3. GoogleN ...
- Spring 事务 readOnly 到底是怎么回事?
Spring的事务经常会有这样的配置: 1 <tx:method name="search*" read-only="true" /> 或者这样的注 ...
- 10款基于jquery的web前端动画特效
1.jQuery横向手风琴图片切换动画 之前我们为大家分享过很多款基于jQuery和CSS3的手风琴菜单和手风琴焦点图插件,比如CSS3响应式垂直手风琴菜单和jQuery横向手风琴图片展示插件.今天要 ...