$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
$ tar -zxf pcre-8.40.tar.gz
$ cd pcre-8.40
$ ./configure
$ make
$ sudo make install
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxf zlib-1.2.11.tar.gz$ cd zlib-1.2.11
$ ./configure
$ make
$ sudo make install
$ wget http://www.openssl.org/source/openssl-1.0.2f.tar.gz
$ tar -zxf openssl-1.0.2f.tar.gz
$ cd openssl-1.0.2f
$ ./config --prefix=/usr
$ make
$ sudo make install
二、下载安装Nginx
$ wget http://nginx.org/download/nginx-1.11.9.tar.gz
$ tar zxf nginx-1.11.9.tar.gz
三、增加其他模块
1.增加check模块
开始准备源代码,首先下载check模块。并为nginx源码包打补丁。执行如下指令:
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
unzip master
cd /root/nginx-1.11.9 (切换到nginx目录)
patch -p0 < ../nginx_upstream_check_module-master/check_1.11.5+.patch
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
unzip master
这里请注意:在nginx_upstream_check_module官网的安装说明中,有一个打补丁的注意事项:
If you use nginx-1.2.1 or nginx-1.3.0, the nginx upstream round robin
module changed greatly. You should use the patch named
'check_1.2.1.patch'.
If you use nginx-1.2.2+ or nginx-1.3.1+, It added the upstream
least_conn module. You should use the patch named 'check_1.2.2+.patch'.
If you use nginx-1.2.6+ or nginx-1.3.9+, It adjusted the round robin
module. You should use the patch named 'check_1.2.6+.patch'.
If you use nginx-1.5.12+, You should use the patch named
'check_1.5.12+.patch'.
If you use nginx-1.7.2+, You should use the patch named
'check_1.7.2+.patch'.
如果补丁安装成功,您将看到以下的提示信息:
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
patching file src/http/ngx_http_upstream_round_robin.h
这里我们的Nginx的版本是1.11.9,那么就应该打入check_1.11.5+.patch这个补丁
准备sticky模块。在nginx文件下执行如下指令:
mkdir modules
cd /root/nginx/nginx-1.2.4/modules
wget https://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.1.tar.gz
(这里下不了,在csdn上下了在上传modules 目录也一样)
tar -zxvf nginx-sticky-module-1.1.tar.gz
cd nginx-sticky-module-1.11.9
patch -p0 < ../nginx_upstream_check_module-master/nginx-sticky-module.patch
四、编译安装Nginx
./configure --sbin-path=/usr/local/nginx/nginx \
--with-debug --with-cc-opt='-O0 -g' \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=../pcre-8.40 \
--with-zlib=../zlib-1.2.11/ \
--add-module=../nginx_upstream_check_module-master --add-module=modules/nginx-sticky-module-1.1
--with-debug --with-cc-opt='-O0 -g' \ 这个测试用的 可以不用
这里开始会报错,sticky 模块会报错
解决方式就是修改在你下载解压缩之后的sticky模块文件夹中的ngx_http_sticky_misc.c文件
第一将这两个模块 <openssl/sha.h> and <openssl/md5.h>包含到文件ngx_http_sticky_misc.c
下面红色标注地方
#include <nginx.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_md5.h>
#include <ngx_sha1.h>
#include <openssl/sha.h>
#include <openssl/md5.h>
#include "ngx_http_sticky_misc.h"
第二个问题
/ngx_http_sticky_module.c:333: 警告:赋值时将整数赋给指针,未作类型转换
第340行左右修改(iphp->rrp.current = iphp->selected_peer;)为:
#if defined(nginx_version) && nginx_version >= 1009000
iphp->rrp.current = peer;
#else
iphp->rrp.current = iphp->selected_peer;
#endif
第三
把nginx-sticky-module-1.1/ngx_http_sticky_misc.c的281行修改为:digest->len = ngx_sock_ntop(in,sizeof(struct sockaddr_in), digest->data, len, 1);
五、配置和运行
这部分下次再发博客