nginx负载均衡fair方式分发
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
- 上一篇 »Nginx负载均衡配置实例详解
- 下一篇 »linux 下 nginx的负载均衡