Nginx升级记录

检查服务器版本,操作系统位数

[root@JT-T-KEYAN-001 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@JT-T-KEYAN-001 ~]#
[root@JT-T-KEYAN-001 ~]# uname -r
2.6.32-358.el6.x86_64
[root@JT-T-KEYAN-001 ~]#

下载要升级的nginx版本安装包,上传到服务器软件目录下

查找nginx执行文件路径:

[root@JT-T-KEYAN-001 src]# ps -ef|grep nginx|grep master|awk -F" " '{print $11}'
/usr/sbin/nginx
[root@JT-T-KEYAN-001 src]#
[root@JT-T-KEYAN-001 src]#

查看nginx之前的版本及编译参数:

[root@JT-T-KEYAN-001 src]# nginx -V
nginx version: nginx/1.11.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.1.0c  10 Nov 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-openssl=/usr/local/src/openssl-1.1.0c --with-file-aio --with-http_v2_module --with-ipv6
[root@JT-T-KEYAN-001 src]#

解压要升级的nginx版本,使用原来的编译参数进行编译(不安装)

[root@JT-T-KEYAN-001 src]# tar -zxf nginx-1.18.0.tar.gz
[root@JT-T-KEYAN-001 src]#
[root@JT-T-KEYAN-001 src]# cd nginx-1.18.0
[root@JT-T-KEYAN-001 nginx-1.18.0]#
[root@JT-T-KEYAN-001 nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-openssl=/usr/local/src/openssl-1.1.0c --with-file-aio --with-http_v2_module --with-ipv6

[root@JT-T-KEYAN-001 nginx-1.18.0]# echo $?
0
[root@JT-T-KEYAN-001 nginx-1.18.0]#
[root@JT-T-KEYAN-001 nginx-1.18.0]# make
[root@JT-T-KEYAN-001 nginx-1.18.0]# echo $?
0
[root@JT-T-KEYAN-001 nginx-1.18.0]#

备份原nginx执行程序:

[root@JT-T-KEYAN-001 nginx-1.18.0]# mv /usr/sbin/nginx /usr/sbin/nginx11
[root@JT-T-KEYAN-001 nginx-1.18.0]#

替换新的nginx执行程序:

[root@JT-T-KEYAN-001 nginx-1.18.0]# cp objs/nginx /usr/sbin/nginx
[root@JT-T-KEYAN-001 nginx-1.18.0]#
[root@JT-T-KEYAN-001 nginx-1.18.0]# ll /usr/sbin/nginx*
-rwxr-xr-x  1 root root 8128528 10月 16 13:59 /usr/sbin/nginx
-rwxr-xr-x. 1 root root 7824521 10月 27 2017 /usr/sbin/nginx11
[root@JT-T-KEYAN-001 nginx-1.18.0]#

发送USR2信息给旧版本主进程号,使nginx的旧版本停止接收请求,用nginx的新版本接替,且老进程处理完成所有请求,关闭所有连接后,停止

[root@JT-T-KEYAN-001 nginx-1.18.0]# kill -USR2 `cat /var/run/nginx.pid`
[root@JT-T-KEYAN-001 nginx-1.18.0]#

查看 nginx pid 所在目录,多了 nginx.pid.oldbin 文件,存放了旧版本nginx的pid号

[root@JT-T-KEYAN-001 nginx-1.18.0]# ll /var/run/nginx*
-rw-r--r-- 1 root root 6 10月 16 14:02 /var/run/nginx.pid
-rw-r--r-- 1 root root 5 8月   3 15:17 /var/run/nginx.pid.oldbin
[root@JT-T-KEYAN-001 nginx-1.18.0]#

关闭旧的nginx进程

[root@JT-T-KEYAN-001 nginx-1.18.0]# kill -QUIT `cat /var/run/nginx.pid.oldbin`
[root@JT-T-KEYAN-001 nginx-1.18.0]#

查看升级后的版本

[root@JT-T-KEYAN-001 nginx-1.18.0]# nginx -v
nginx version: nginx/1.18.0
[root@JT-T-KEYAN-001 nginx-1.18.0]#

发表评论

您的电子邮箱地址不会被公开。