正在生产线上跑着web前端是nginx+tomcat,现在有这样一个需求,需要对网站的单品页面和列表页设置缓存,不同的页面设置不同的缓存,但是由于开始没有安装ngx_cache_purge这个模块,现在没法直接往配置文件里边写,这时候,就需要在线安装ngx_cache_purge此模块,下边就说下怎么在线编译安装新模块。
安装步骤:
1.首先看下内核和系统的版本号。
1
2
3
4
5
6
7
8
|
[root@vmware1 ~]
# uname -a
Linux vmware1 2.6.18-308.el5
#1 SMP Tue Feb 21 20:06:06 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@vmware1 ~]
# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.8 (Final)
Release: 5.8
Codename: Final
|
2.看下编译安装nginx的时候,都编译安装的哪些模块。
1
2
3
4
5
|
[root@vmware1 ~]
# /usr/local/nginx/sbin/nginx -V
nginx version: nginx
/1
.3.1
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
TLS SNI support disabled
configure arguments: --user=nginx --group=nginx --prefix=
/usr/local/nginx-1
.3.1 --with-http_stub_status_module --with-http_ssl_module --with-pcre=
/taokey/tools/pcre-8
.33
|
3.下载proxy_cache所需的压缩包ngx_cache_purge-2.1.tar.gz。
1
2
3
4
5
6
7
8
9
|
[root@vmware1 tools]
# wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
--2013-09-29 11:02:19进到-- http:
//labs
.frickle.com
/files/ngx_cache_purge-2
.1.
tar
.gz
Resolving labs.frickle.com... 5.9.135.91
Connecting to labs.frickle.com|5.9.135.91|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10535 (10K) [application
/octet-stream
]
Saving to: `ngx_cache_purge-2.1.
tar
.gz'
100%[==========================================================================================>] 10,535 --.-K
/s
in
0s
2013-09-29 11:02:21 (64.8 MB
/s
) - `ngx_cache_purge-2.1.
tar
.gz' saved [10535
/10535
]
|
4.解压下载好的ngx_cache_purge-2.1.tar.gz这个压缩包
1
|
[root@vmware1 tools]
# tar -xf ngx_cache_purge-2.1.tar.gz
|
5.进到之前安装nginx这个软件包的目录
1
|
[root@vmware1 nginx-1.3.1]
# cd /taokey/tools/nginx-1.3.1
|
6.重新./configure,make编译,不用make install。千万要注意:到这里就可以了,千万不要make install,不然文件就会被覆盖了。
1
2
|
[root@vmware1 nginx-1.3.1]
# ./configure --user=nginx --group=nginx --add-module=../ngx_cache_purge-2.1 --prefix=/usr/local/nginx-1.3.1 --with-http_stub_status_module --with-http_ssl_module --with-pcre=/taokey/tools/pcre-8.33
[root@vmware1 nginx-1.3.1]
# make
|
7.需要替换nginx二进制文件,先备份一下原来的启动脚本。
1
|
[root@vmware1 nginx-1.3.1]
# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
|
8.需要把nginx进程杀掉,不然复制会报错
1
2
3
4
5
|
[root@vmware1 nginx-1.3.1]
# killall nginx
[root@vmware1 nginx-1.3.1]
# killall nginx
nginx: no process killed
[root@vmware1 nginx-1.3.1]
# cp ./objs/nginx /usr/local/nginx/sbin/
cp
: overwrite `
/usr/local/nginx/sbin/nginx
'?
yes
|
9.此时,查看下nginx的所有的模块,是否把cache_purge这个模块成功编译进去。
1
2
3
4
5
|
[root@vmware1 nginx-1.3.1]
# /usr/local/nginx/sbin/nginx -V
nginx version: nginx
/1
.3.1
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
TLS SNI support disabled
configure arguments: --user=nginx --group=nginx --add-module=..
/ngx_cache_purge-2
.1 --prefix=
/usr/local/nginx-1
.3.1 --with-http_stub_status_module --with-http_ssl_module --with-pcre=
/taokey/tools/pcre-8
.33
|
10.开启nginx.
1
2
3
|
[root@vmware1 nginx-1.3.1]
# /usr/local/nginx/sbin/nginx
[root@vmware1 nginx-1.3.1]
# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6205
/nginx
|
到此为止,实验结束。