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 ...
随机推荐
- iOS:基于RTMP的视频推流
iOS基于RTMP的视频推流 一.基本介绍 iOS直播一出世,立马火热的不行,各种直播平台如雨后春笋,正因为如此,也同样带动了直播的技术快速发展,在IT界精通直播技术的猴子可是很值钱的.直播技术涉及的 ...
- jvm实战-jvm调优
jvm调优 jvm调优主要是内存管理方面的调优,包括各个代的大小,GC策略等. 代大小调优 JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系统的可用虚拟内 ...
- 10分钟上手图数据库Neo4j
随着互联网不断的发展,传统的关系型数据库如oracle,mysql已经难以支撑现下大数据量,高并发的场景了.于是,NoSQL横空出世,有像cassandra这样的column-based,像Mongo ...
- DES加密解密算法C语言代码实现
代码: #include<stdio.h> #include<string.h> #include<stdlib.h> /*-------------------- ...
- JDBC告警系列(一)The server time zone value 'ÖÐ' is unrecognized or represents more than one time zone.
一.现象 java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents ...
- 【转载】Linux下查看CPU、内存占用率
不错的文章(linux系统性能监控--CPU利用率):https://blog.csdn.net/ctthuangcheng/article/details/52795477 在linux的系统维护中 ...
- 常用xpath选择器和css选择器总结
xpath选择器 表达式 说明 article 选取所有article元素的所有子节点 /article 选取根元素article article/a 选取所有属于article的子元素的a元素 // ...
- java 查看SOAP请求报文
log.info("ESB 请求URL = " + cachedEndpoint.toString());//打印SOAP请求报文 add by LinJC on 20170120 ...
- [mvc] 简单的forms认证
1.在web.config的system.web节点增加authentication节点,定义如下: <system.web> <compilation debug="tr ...
- c++ 格式字符串说明
C++的格式化字符串经常用作格式化数字的输出.字符串合并和转换等等很多场合. 1. 格式化规定符 ━━━━━━━━━━━━━━━━━━━━━━━━━━ 符号 作用 ─ ...