nginx的信号量和平滑升级
一.nginx支持的信号
1.使用/usr/local/nginx/sbin/nginx -h
[root@server01 conf]# /usr/local/nginx/sbin/nginx -h nginx version: nginx/1.16.0 Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit # 查看nginx版本并且检查检查配置文件语法是否错误 -t : test configuration and exit # 检查配置文件是否正确 -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload # 可以发送信号给进程 -p prefix : set prefix path (default: /usr/local/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
cd /usr/local/nginx/sbin
./nginx -s stop # 快速的停止进程
./nginx -s quit # 优雅的停止进程
./nginx -s reopen # 打开新的日志文件,
./nginx -s reload # 重新加载配置文件,不停止进程
2.使用kill命令发送信号给进程
kill -信号 nginx的进程ID
nginx支持的信号:
TERM, INT # 快速的停止进程
HUP # 重新加载配置文件,不停止进程
QUIT # 优雅的退出程序
USR1 # 打开新的日志文件
USR2 # 平滑升级nginx
WINCH # 优雅的终止worker进程
二.nginx的平滑升级
原版本1.12,升级到1.16版本
1.配置,编译,安装新版本nginx(1.16)
配置参数可以与1.12版本一样
/usr/local/nginx/sbin/nginx -V可以查看配置参数
[root@VM_0_2_centos ~]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
tar -xf nginx-1.16.0.tar.gz
cd /root/soft/nginx-1.16.0
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
make && make install
2.查看sbin目录
[root@server01 conf]# ls ../sbin/ nginx nginx.old
nginx.old是原来版本(1.12)的,nginx是1.16版本的
3.启动新版本nginx
不能直接./nginx启动 会出现端口被占用
a.查看原进程id
ps -ef |grep nginx
b.会启动新版本nginx的master 和worker进程,此时新旧版本都可以提供服务
kill -USR2 原nginx的master进程pid
c.优雅退出旧版本的worker进程
kill -WINCH 原nginx的master进程pid
d.优雅退出旧版本的master进程
kill -QUIT 原nginx的master进程pid
此时就只有新版本的master和worker进程提供服务
或使用新版本的make upgrade平滑升级
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
make install && make upgrade