nginx添加sticky cookie 分流模块

需要下载nginx源码和sticky,在nginx配置文件中添加sticky模块,然后重新编译nginx。

#准备安装基础环境:
yum install gcc openssl-devel pcre-devel zlib-devel

#下载nginx1.6.3
wget http://nginx.org/download/nginx-1.6.3.tar.gz

#解压缩nginx
tar xvf nginx-1.6.3.tar.gz

#安装依赖的库
yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel
yum -y install gd-devel
yum -y install perl-devel perl-ExtUtils-Embed
yum -y install GeoIP GeoIP-devel GeoIP-data
yum -y install gperftools-devel

#查看nginx的配置
nginx -V

#加入sticky模块
cd nginx-1.6.3

./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-google_perftools_module --with-debug --with-cc-opt=‘-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic‘ --with-ld-opt=‘-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E‘ --add-module=/root/nginx-sticky

#编译
make

#停止nginx
service nginx stop

#替换nginx
cp /usr/sbin/nginx /usr/sbin/nginx.bak.20161009
cp ./objs/nginx  /usr/sbin/nginx

#修改nginx配置:

upstream test_server {
        server 10.2.118.48:8002;
        server 10.2.118.49:8002;
        sticky;
}

#重启nginx

service nginx restart

参考资料:

https://my.oschina.net/766/blog/156693

http://www.xuebuyuan.com/2184929.html

http://blog.chinaunix.net/uid-24625974-id-2894092.html

时间: 2024-08-09 13:50:43

nginx添加sticky cookie 分流模块的相关文章

nginx添加sticky模块-cookie保持会话

cookie不同于session,一个存于客户端,一个存于服务端. 环境nginx 1.8.0 centos6.X sticky:1.2.5  wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz cookie负载均衡相比iphash来比其中一个特点比较明显:内网nat用户的均衡.而iphash无法做到. yum install openssl openssl-devel 先停止ngin

nginx根据cookie分流

nginx根据cookie分流众所周知,nginx可以根据url path进行分流,殊不知对于cookie分流也很强大,同时这也是我上篇提到的小流量实验的基础.二话不说,先看需求,两台服务器分别定义为apache001:192.168.1.1:8080apache002:192.168.1.2:8080默认服务器为:default:192.168.1.0:8080前端nginx服务器监听端口8080,需要根据cookie转发,查询的cookie的键(key)为abcdexpid,如果该cooki

安装成功的nginx,如何添加未编译安装模块(非覆盖安装http_image_filter_module)

背景:1.做了图片上传小项目.2.图片上传,需要多图管理.3.图片上传,需要存储到Fastdfs.4.Fastdfs上的图片,和Nginx结合.5.Nginx从Fastdfs获得的图片,需要使用缩略图.a.在不需要缩略图,小图的情况下,可以使用原图.b.需要缩略图的情况下,指定目标宽度和高度,获得指定宽度和高度的缩略图. 关键的几个参考资料1.安装成功的nginx如何添加未编译安装模块http://blog.csdn.net/gebitan505/article/details/17612845

nginx添加 nginx_heath模块

原因?为什么会使用nginx_heath 这个模块,主要是如nginx+tomcat部署的时,tomcat挂了之后nginx->upstream 轮询是可以踢掉挂掉的tomcat服务的,如果部署的机器挂了之后nginx轮询是不能踢掉的,如果服务再去请求,就会出现请求超时! 1.ngx_http_proxy_module 模块和ngx_http_upstream_module模块(自带) 官网地址:http://nginx.org/cn/docs/http/ngx_http_proxy_modul

nginx添加ssl模块

原已经安装好的nginx,现在需要添加一个未被编译安装的ssl模块: nginx -V 可以查看原来编译时都带了哪些参数 原来的参数:--prefix=/app/nginx 添加的参数: --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module 步骤如下: 1. 使用参数重新配置: ./configure --prefix=/app/nginx -user=nobody -group=nobod

nginx添加模块 (非覆盖安装)

nginx添加模块(非覆盖安装) 原已经安装好的nginx,现在需要添加一个未被编译安装的模块: 查看原来编译时都带了哪些参数# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.8.1built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) configure arguments: --prefix=/usr/local/nginx --with-http_realip_module --

Nginx 编译,添加未编译安装模块ngx_cache_purge

Nginx 编译,添加未编译安装模块ngx_cache_purge 官网下载nginx及第三方ngx_cache_purge 模块 http://wiki.nginx.org/Install http://labs.frickle.com/nginx_ngx_cache_purge/ 编译与安装 Blockquote ./configure \ –prefix=/usr/local/nginx-1.8.0 \ –sbin-path=/usr/sbin/nginx \ –conf-path=/et

安装好的nginx如何查看已经安装模块和添加一个未被编译安装的模块

今天想通过zabbix实现一个nginx监控,发现以来的模块–with-http_stub_status_module没有安装,需要进行编译一下.这里记录下模块单独安装步骤,就以–with-http_stub_status_module为例1,查看当前nginx编译参数 [[email protected] nginx-1.14.0]# /usr/local/nginx/sbin/nginx -Vnginx version: nginx/1.14.0built by gcc 4.8.5 2015

nginx 基于cookie分流

一.概述 为了保障公司业务不受单点机房故障影响;需要做机房双活;把流量分别导向不同的IDC机房,按比例分配;方法有多种,本文所讲的就是模拟按客户端不同cookie分流实现:nginx plug+自带cookie分配,就是商业版支持,对于 大多的创业公司用的是源生的开源nginx则可以通过应用层给不同的客户端分配cookie值来导向到不同的IDC机房;这么说容易理解点;本文就是通过模拟不同的客户端cookie导向到不同的IDC机房:架构如下: 图中的高可用负载既可以是单个机房的,也可以是多个机房的