在看nginx_upstream那些基础

2023年 7月 15日 20.7k 0

nginx负载均衡依赖upstream模块,支持的代理方式有proxy_pass,fastcgi_pass,memcached_pass1,upstream模块是放在nginx配置文件中的http{}标签中2,upstream默认算法是wrr,权重轮训3,upstream模块内部部分参数如下(参数和haproxy几乎一样):server 10.0.0.54:80 这里的端口可换做域名,通过DNS做负载均衡weitht 权重,默认1,越大接收请求越多max_fails=2 fail_timeout=20s, 最大的尝试失败次数,默认为1,0表示禁止尝试,一般2-3次,可根据业务进行配置;fail_timeout=20s,失败超时时间,默认10s,通常2-3秒backup ,也可以成为热备。rs节点的高可用,当存活节点当即,则启动down ,维护模式,可配置ip_hash使用max_conns=NUMBER,限制连接数调度算法:rr轮询,weight权重,ip_hash黏贴-会话保持,fair第三方算法-根据节点的响应时间来分配请求(响应时间短的优先分配),url——hash根据地址hash-将每一个url定义到后端服务器-后端服务器为缓存服务器效果比较显著

wget http://nginx.org/download/nginx-1.6.3.tar.gz 
tar xf nginx-1.6.3.tar.gz 
cd nginx-1.6.3 
yum -y install pcre pcre-devel openssl-devel
useradd nginx -s /usr/nologin -M
./configure 
--user=nginx 
--group=nginx 
--prefix=/usr/local/nginx 
--with-http_stub_status_module 
--with-http_ssl_module
[root@nginx-proxy conf]# make && make install
[root@nginx-proxy conf]# egrep -v "#|^$" nginx.conf.default  > nginx.conf
[root@nginx-proxy2 conf]# cat nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
upstream backend {
    server 10.0.0.54:80 weight=5;
    server 10.0.0.53:80 weight=5;
#    server 10.0.0.55:80 weight=5 backup;
    } 
  
   server {
        listen       80;
        server_name  www.linuea123.com;
        location / {
            root   html;
            index  index.html index.htm;
    proxy_pass http://backend;
    }
    }
}

请输入图片描述

相关文章

LeaferJS 1.0 重磅发布:强悍的前端 Canvas 渲染引擎
10分钟搞定支持通配符的永久有效免费HTTPS证书
300 多个 Microsoft Excel 快捷方式
一步步配置基于kubeadmin的kubevip高可用
istio全链路传递cookie和header灰度
REST Web 服务版本控制

发布评论