• nginx sticky模块安装是C语言和per脚本写的.因此需要安装gcc和g++编译器      
yum -y intall gcc g++
  •  安装sticky模块需要首先安装zlib库.

wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11
make && make install
./configure
 make && make install
  • 安装perl库. 
wget https://ftp.pcre.org/pub/pcre/pcre2-10.37.tar.gz
tar zxf pcre2-10.37.tar.gz
cd pcre2-10.37
./configure
make && make install
  • 安装openssl库    
wget https://www.openssl.org/source/old/3.0/openssl-3.0.0-alpha16.tar.gz
cd openssl-3.0.0-alpha16.tar.gz
tar zxf openssl-3.0.0-alpha16.tar.gz
cd openssl-3.0.0-alpha16
 ./Configure --prefix=/usr/local/ssl --openssldir=/usr/local/ssl     '-Wl,-rpath,$(LIBRPATH)'

这个会出现错误 

Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.

执行

 yum -y install perl-CPAN

继续执行

./Configure --prefix=/usr/local/ssl --openssldir=/usr/local/ssl    '-Wl,-rpath,$(LIBRPATH)'

出现


Can't locate IPC/Cmd.pm in @INC (@INC contains: /root/nginx/openssl-3.0.0-alpha16/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /root/nginx/openssl-3.0.0-alpha16/external/perl/Text-Template-1.56/lib) at /root/nginx/openssl-3.0.0-alpha16/util/perl/OpenSSL/config.pm line 18.
BEGIN failed--compilation aborted at /root/nginx/openssl-3.0.0-alpha16/util/perl/OpenSSL/config.pm line 18.
Compilation failed in require at ./Configure line 23.
BEGIN failed--compilation aborted at ./Configure line 23.

执行

 perl -MCPAN -e shell install Log::Log4perl install HTML::TokeParser::Simple

yum -y install perl-IPC-Cmd.noarch
 

全部按yes完成

继续执行

./Configure --prefix=/usr/local/ssl --openssldir=/usr/local/ssl    '-Wl,-rpath,$(LIBRPATH)'

生成makefile 成功

继续执行

make && make install

下载stick模块

 get https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz

 tar zxf master.tar.gz
 cd nginx-goodies-nginx-sticky-module-ng-08a395c66e42

下载nginx源代码1.16.1

wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar zxf nginx-1.16.1.tar.gz
cd nginx-1.16.1

编译

./configure --prefix=/opt/nginx --add-module=../nginx-goodies-nginx-sticky-module-ng-08a395c66e42 --with-http_stub_status_module --with-http_ssl_module

如果遇到定义错误

 vi ../nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_misc.c

在头文件修改


#include <openssl/sha.h> //增加
#include  <openssl/md5.h> //增加
#include <nginx.h>
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_md5.h>
#include <ngx_sha1.h>

继续编译

yum -y install openssl-devel

make &&make install

安装成功

测试,增加如下代码,重新启动nginx,注意,这个需要在/opt/nginx/sbin/nginx启动

    upstream backend {
    server 192.168.11.168;
    server 192.168.10.151;
    sticky   expires=1h domain=.example.com path=/;
  }


点赞(0)