Nginx 添加新模块以及平滑升级

nginx安装成功后,发现有一些其他模块没有编译进去,或者想额外添加一些模块,这时候就要重新编译nginx

下面以 --with-http_stub_status_module为例:

使用./nginx -V 查看没有该模块,使用下面方法添加:

进入nginx源码包(configure)此方法不适用于yum安装的nginx!

1

[root@lmode nginx]# cd /usr/local/src/nginx-1.4.7

将要编译的参数重新添加到后面(之前的模块也要加上)

1

[root@lmode nginx-1.4.7]# ./configure --prefix=/usr/local/nginx   --with-http_stub_status_module

注意:这里只能make 千万别make install,否则就覆盖安装了

1

[root@lmode nginx-1.4.7]# make

make完成后,在源码目录下会有一个objs目录,objs目录下就多了个nginx,这个就是新版本的程序了。

1

2

3

[root@lmode nginx-1.4.7]# ls

auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

然后将objs目录下的nginx替换之前已经安装过的nginx。

先备份旧的nginx程序

1

[root@lmode nginx-1.4.7]#cp /usr/local/nginx/nginx  /usr/local/nginx/nginx.bak

把新的nginx程序覆盖旧的

1

[root@lmode nginx-1.4.7]#cp ./objs/nginx /usr/local/nginx/sbin/nginx

如果提示“cp:cannot create regular file `/usr/local/nginx/sbin/nginx': Text file busy”

建议使用如下语句cp

1

#cp -rfp objs/nginx /usr/local/nginx/sbin/nginx

测试新的nginx程序是否正确

1

2

3

[root@lmode nginx-1.4.7]# /usr/local/nginx/nginx -t

nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/nginx.conf test is successful

最后重启nginx

1

[root@lmode nginx-1.4.7]# /usr/local/nginx/nginx -s reload

然后在nginx配置文件中server添加一个localtion

location /nginx-status {
          stub_status on;
          access_log off;
                       }

发现虽然nginx -t  不报错了但是还是无法使用该模块功能。报错可看ngixn日志就知道了。

解决办法:进行平滑更新一下nginx,避免重启带来业务影响。

1)查看nginx进程

[root@web01 conf.d]# ps -ef|grep nginx
root      10864      1  0 Jul01 ?        00:00:00 nginx: master process /app/nginx/sbin/nginx
nginx     18057  10864  0 12:25 ?        00:00:00 nginx: worker process
root      18246  15116  0 13:37 pts/1    00:00:00 grep --color=auto nginx



2)发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程。

[root@web01 conf.d]# kill -USR2 10864
[root@web01 conf.d]# ps aux|grep nginx
root      10864  0.0  0.1  21256  1508 ?        Ss   Jul01   0:00 nginx: master process /app/nginx/sbin/nginx
nginx     18057  0.0  0.1  21256  1732 ?        S    12:25   0:00 nginx: worker process
root      18259  0.1  0.3  45956  3240 ?        S    13:38   0:00 nginx: master process /app/nginx/sbin/nginx
nginx     18260  0.0  0.1  46336  1904 ?        S    13:38   0:00 nginx: worker process
root      18265  0.0  0.0 112704   960 pts/1    R+   13:39   0:00 grep --color=auto nginx


3)向旧的Nginx主进程(master)发送WINCH信号,它会逐步关闭自己的工作进程。

[root@web01 conf.d]# kill -WINCH 10864
[root@web01 conf.d]# ps aux|grep nginx
root      10864  0.0  0.1  21256  1508 ?        Ss   Jul01   0:00 nginx: master process /app/nginx/sbin/nginx
root      18259  0.0  0.3  45956  3240 ?        S    13:38   0:00 nginx: master process /app/nginx/sbin/nginx
nginx     18260  0.0  0.1  46336  1904 ?        S    13:38   0:00 nginx: worker process
root      18271  0.0  0.0 112704   960 pts/1    R+   13:41   0:00 grep --color=auto nginx



4)发送QUIT信息,优雅的退出旧进程。

[root@web01 conf.d]# kill -QUIT 10864
[root@web01 conf.d]# ps aux|grep nginx
root      18259  0.0  0.3  45956  3240 ?        S    13:38   0:00 nginx: master process /app/nginx/sbin/nginx
nginx     18260  0.0  0.1  46336  1904 ?        S    13:38   0:00 nginx: worker process
root      18273  0.0  0.0 112704   960 pts/1    S+   13:41   0:00 grep --color=auto nginx

然后更新nginx配置文件

nginx  -s   reload

再测试stub_status  模块

curl  http://127.0.0.1:80/nginx-status 
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值