欢迎光临
一直在努力

Nginx在线升级

  • nginx在线升级
通常由于应用的需求变更或者问题解决需要对之前安装过的nginx进行重新编译来支持新功能或者增加模块功能,而nginx是支持在线升级的既在不中断服务的前提下对nginx进行升级。下面以nginx重新编译增加echo-nginx-module模块为例。
一,查看目前的编译参数
[root@blweb-0-8 nginx]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.5.8
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
configure arguments: –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_realip_module
二 下载模块包进行打补丁
进入nginx的源文件夹,进行补丁修补
[root@blweb-0-8 nginx]# patch -p1 < /root/soft/nginx_upstream_check_module-0.3.0/check_1.5.12+.patch
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
Hunk #2 FAILED at 216.
1 out of 2 hunks FAILED — saving rejects to file src/http/modules/ngx_http_upstream_ip_hash_module.c.rej
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
三 进行编译安装
[root@blweb-0-8 nginx]# .configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_realip_module –add-module=/root/soft/echo-nginx-module-0.60
[root@blweb-0-8 nginx]# make
备份原来的二进制文件
[root@blweb-0-8 nginx]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old
[root@blweb-0-8 nginx]# cp objs/nginx /usr/local/nginx/sbin/
[root@blweb-0-8 ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
configure arguments: –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_realip_module –add-module=/root/soft/echo-nginx-module-0.60 –add-module=/root/soft/nginx_upstream_check_module-0.3.0
可以看到已经按照了该模块
四,进行不中断服务的相关操作
(关键是kill -USR2 nginx的pid 和 kill -QUIT kill -QUIT,可以通过ps aux|grep nginx查看nginx本身切换过程,启动新进程后,旧进程还是出来原来的请求处理完后慢慢退出,新进程处理新进来的请求,进而实现不中断服务升级)
[root@blweb-0-8 nginx-1.8.1]# kill -USR2 `cat /usr/local/nginx/var/nginx.pid`
[root@blweb-0-8 nginx-1.8.1]# ps aux |grep nginx
root 7297 0.0 0.3 49872 3240 ? S 10:13 0:00 nginx: master process /usr/local/nginx/sbin/nginx
www 7302 0.1 2.8 76496 28596 ? S 10:13 0:00 nginx: worker process
www 7303 0.2 2.8 76496 28596 ? S 10:13 0:00 nginx: worker process
www 7304 0.1 2.8 76496 28596 ? S 10:13 0:00 nginx: worker process
www 7305 0.9 2.8 76496 28580 ? S 10:13 0:00 nginx: worker process
root 7359 0.0 0.0 103248 872 pts/0 S+ 10:14 0:00 grep nginx
root 21559 0.0 0.0 49704 696 ? Ss Dec01 0:00 nginx: master process /usr/local/nginx/sbin/nginx
www 21561 0.0 0.0 75304 704 ? S Dec01 0:38 nginx: worker process
www 21562 0.0 0.0 75304 704 ? S Dec01 0:38 nginx: worker process
www 21563 0.0 0.0 75304 728 ? S Dec01 0:42 nginx: worker process
www 21564 0.0 0.1 75536 1272 ? S Dec01 0:00 nginx: worker process
[root@blweb-0-8 nginx-1.8.1]# kill -QUIT `cat /usr/local/nginx/var/nginx.pid`
[root@blweb-0-8 nginx-1.8.1]# ps aux |grep nginx
root 7472 0.0 0.0 103248 876 pts/0 S+ 10:14 0:00 grep nginx
root 21559 0.0 0.0 49704 704 ? Ss Dec01 0:00 nginx: master process /usr/local/nginx/sbin/nginx
www 21561 0.0 0.0 75304 704 ? S Dec01 0:38 nginx: worker process
www 21562 0.0 0.0 75304 704 ? S Dec01 0:38 nginx: worker process
www 21563 0.0 0.0 75304 728 ? S Dec01 0:42 nginx: worker process
www 21564 0.0 0.1 75536 1272 ? S Dec01 0:00 nginx: worker process
[root@blweb-0-8 nginx-1.8.1]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
configure arguments: –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_realip_module –add-module=/root/soft/echo-nginx-module-0.60 –add-module=/root/soft/nginx_upstream_check_module-0.3.0

未经允许不得转载:黑少博客 » Nginx在线升级

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

黑少博客

联系我们联系我们