nginx负载均衡fair方式分发

本文介绍如何在Nginx中配置Fair负载均衡模块,包括已安装和未安装Nginx的情况,并提供具体步骤及验证方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

fair采用的不是内建负载均衡使用的轮换的均衡算法,而是可以根据页面大小、加载时间长短智能的进行负载均衡。

这算是没有安装fair的情况

[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.4.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)

模块

模块下载地址:nginx-upstream-fair-master.zip

下面分为两种情况, 一种是之前已经安装好nginx的了, 另一种是还未安装nginx的。

未安装nginx

在nginx源码目录下

./configure --prefix=/usr/local/nginx  --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid  --add-module=/home/nginx-upstream-fair-master  
编译安装
make && make intstall

已安装nginx

在nginx源码目录下

./configure --prefix=/usr/local/nginx  --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid  --add-module=/home/nginx-upstream-fair-master
编译
make

这是只需要编译, 不需要安装, 如果再make install就会把原来的nginx覆盖了。

此时编译完成, 会在当前的源码目录下生成一个objs目录

[root@localhost nginx-1.4.2]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

objs目录下的文件如下

[root@localhost objs]# ll
总用量 3176
drwxr-xr-x 3 root root    4096 1月  10 16:16 addon
-rw-r--r-- 1 root root   14152 1月  10 16:16 autoconf.err
-rw-r--r-- 1 root root   36804 1月  10 16:16 Makefile
-rwxr-xr-x 1 root root 3129478 1月  10 16:17 nginx
-rw-r--r-- 1 root root    5243 1月  10 16:17 nginx.8
-rw-r--r-- 1 root root    5969 1月  10 16:16 ngx_auto_config.h
-rw-r--r-- 1 root root     657 1月  10 16:16 ngx_auto_headers.h
-rw-r--r-- 1 root root    3812 1月  10 16:16 ngx_modules.c
-rw-r--r-- 1 root root   29760 1月  10 16:17 ngx_modules.o
drwxr-xr-x 8 root root    4096 1月  10 16:16 src
复制nginx
cp objs/nginx /usr/local/nginx/sbin/nginx

覆盖它
配置fair
upstream backserver { 
fair; 
server 192.168.0.14; 
server 192.168.0.15; 
} 
重新启动nginx
service nginx restart
验证
cd /usr/local/nginx/sbin
./nginx -V
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.4.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --add-module=/usr/local/nginx-upstream-fair-master

 

转载于:https://www.cnblogs.com/chenglee/p/8260011.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值