nginx平滑升级

来源:互联网 发布:淘宝看不到卖家所在地 编辑:程序博客网 时间:2024/05/02 01:13
刚装了个新版本的NGINX1.4.0,nginx又爆出漏洞出来了。
cp -a /usr/local/nginx /usr/local/nginx.bk  //备份一下
nginx -V //查看旧版本的编译参数
nginx version: nginx/1.4.0
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-52)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/root/software/openssl-1.0.1e
这里需要注意一下,查看nginx的PID文件在哪里,后面升级会用到。

find /usr/local/nginx/ -name nginx.pid

wget http://nginx.org/download/nginx-1.4.1.tar.gz
tar zxvf nginx-1.4.1.tar.gz
cd nginx-1.4.1
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/root/software/openssl-1.0.1e
make
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old && cp objs/nginx /usr/local/nginx/sbin/nginx    //替换nginx的一个二进制文件
nginx -t
make upgrade  //执行命令进行平滑升级
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
cat: /usr/local/nginx/logs/nginx.pid: 没有那个文件或目录
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
make: *** [upgrade] 错误 1
我在这里出错,原因很明显。
查看Makefile文件,你会发现make upgrade其实就是都执行了这几个命令,那好,自己手动执行。。
less Makefile
upgrade:
        /usr/local/nginx/sbin/nginx -t


        kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
        sleep 1
        test -f /usr/local/nginx/logs/nginx.pid.oldbin


        kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
kill -USR2 `cat /usr/local/nginx/nginx.pid`  //我的PID文件位置,并把旧的PID文件重命名为nginx.pid.oldbin(旧的)
kill -QUIT `cat /usr/local/nginx/nginx.pid.oldbin`  //从容关闭旧的nginx
lsof nginx.old //看一下有没有进程在用
附上Nginx支持的几种控制信号:
*  TERM,INT  快速关闭  
*  QUIT   从容关闭  
*  HUP    平滑重启,重新加载配置文件  
*  USR1   重新打开日志文件,在切割日志时用途较大  
*  USR2   平滑升级可执行程序  
*  WINCH 从容关闭工作进程
OK,查看新版本
nginx -V
nginx version: nginx/1.4.1
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-52)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/root/software/openssl-1.0.1e
升级成功。
总结,NGINX升级其实跟添加新的模块是一样的。


参考资料:http://minitoo.blog.51cto.com/4201040/872215
                    http://nginx.org/en/docs/control.html
原创粉丝点击