编译依赖
sudo apt install make gcc build-essential
Nginx 依赖
wget http://www.zlib.net/zlib-1.2.11.tar.gz tar -xvf zlib-1.2.11.tar.gz wget wget https://ftp.pcre.org/pub/pcre/pcre-8.44.zip unzip pcre-8.44.zip
编译安装 1.18
wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -xvf nginx-1.18.0.tar.gz cd nginx-1.18.0 ./configure --with-pcre=/home/wyj/Downloads/pcre-8.44 --with-zlib=/home/wyj/Downloads/zlib-1.2.11 make sudo make install sudo /usr/local/nginx/sbin/nginx
查看进程 ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'
PID PPID USER %CPU VSZ WCHAN COMMAND 2313 1 root 0.0 4128 - nginx: master process /usr/local/nginx/sbin/nginx 2315 2313 nobody 0.0 4804 - nginx: worker process
编译 1.20
wget http://nginx.org/download/nginx-1.20.0.tar.gz tar -xvf nginx-1.20.0.tar.gz cd nginx-1.20 ./configure --with-pcre=/home/wyj/Downloads/pcre-8.44 --with-zlib=/home/wyj/Downloads/zlib-1.2.11 make
备份旧的 Nginx 可执行文件, 并复制新的可执行文件
sudo mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old sudo cp objs/nginx /usr/local/nginx/sbin/nginx
升级可执行文件
sudo kill -s USR2 2313
查看进程 ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'
PID PPID USER %CPU VSZ WCHAN COMMAND 2313 1 root 0.0 4128 - nginx: master process /usr/local/nginx/sbin/nginx 2315 2313 nobody 0.0 4804 - nginx: worker process 2965 2313 root 0.0 4144 - nginx: master process /usr/local/nginx/sbin/nginx 2968 2965 nobody 0.0 4828 - nginx: worker process
升级成功后续操作(确保真的升级成功):
sudo kill -s WINCH 2313 sudo kill -s QUIT 2313 sudo rm /usr/local/nginx/sbin/nginx.old
升级失败后的操作:
重新拉起旧的 nginx 服务
sudo kill -s HUP 2313
关闭新的 nginx 服务
sudo kill -s QUIT 2965
删除新的 Nginx 可执行文件, 并恢复旧的
sudo rm /usr/local/nginx/sbin/nginx sudo mv /usr/local/nginx/sbin/nginx.old /usr/local/nginx/sbin/nginx
master 进程支持以下信号:
TERM, INT
快速关闭服务QUIT
优雅关闭服务HUP
使用新配置启动新工作进程,正常关闭旧工作进程USR1
日志切割USR2
升级可执行文件WINCH
优雅关闭 worker 进程TERM, INT
QUIT
USR1
WINCH
参考文献:
Controlling nginx