Nginx 升级
-
需要查看原来安装的nginx的版本以及编译的参数(安装了那些模块)
nginx -V
[root@cctc-contract-web-01 ~]# nginx -V nginx version: nginx/1.18.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/ --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-stream --with-stream_ssl_module --with-http_slice_module --with-file-aio --with-http_v2_module
-
下载需要升级的nginx版本,解压
tar -zxvf nginx-1.22.0.tar.gz
-
解压进入目录开始运行上面所查询到的编译参数
cd nginx-1.22.0 ./configure --prefix=/ --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-stream --with-stream_ssl_module --with-http_slice_module --with-file-aio --with-http_v2_module
-
然后make,但不要make install
make
-
备份旧的nginx二进制文件
mv /usr/sbin/nginx /usr/sbin/nginx.old_20220803
-
替换新的nginx
mv /root/nginx-1.22.0/objs/nginx /usr/sbin/nginx
-
查看当前nginx版本
nginx -v
-
查看当前nginx进程情况
ps -ef | grep nginx
[root@cctc-contract-web-01 ~]# ps -ef | grep nginx root 64354 1 0 6月24 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 64355 64354 0 6月24 ? 00:00:03 nginx: worker process nginx 64356 64354 0 6月24 ? 00:00:14 nginx: worker process nginx 64357 64354 0 6月24 ? 00:01:42 nginx: worker process nginx 64358 64354 0 6月24 ? 00:01:11 nginx: worker process
-
向旧nginx主线程发送升级信号
kill -USR2 64354
-
此时再次查看nginx进程 有新旧2个nginx进程
[root@cctc-contract-web-01 ~]# ps -ef | grep nginx root 64354 1 0 6月24 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 64355 64354 0 6月24 ? 00:00:03 nginx: worker process nginx 64356 64354 0 6月24 ? 00:00:14 nginx: worker process nginx 64357 64354 0 6月24 ? 00:01:42 nginx: worker process nginx 64358 64354 0 6月24 ? 00:01:11 nginx: worker process root 130058 64354 0 23:43 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 130059 130058 0 23:43 ? 00:00:00 nginx: worker process nginx 130060 130058 0 23:43 ? 00:00:00 nginx: worker process nginx 130061 130058 0 23:43 ? 00:00:00 nginx: worker process nginx 130062 130058 0 23:43 ? 00:00:00 nginx: worker process
-
优雅关闭旧nginx线程(会保留旧的主线程,若服务没问题则可以kill掉该线程)
kill -WINCH 64354
[root@cctc-contract-web-01 sbin]# ps -ef | grep nginx root 64354 1 0 6月24 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf root 130058 64354 0 23:43 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 130059 130058 0 23:43 ? 00:00:00 nginx: worker process nginx 130060 130058 0 23:43 ? 00:00:00 nginx: worker process nginx 130061 130058 0 23:43 ? 00:00:00 nginx: worker process nginx 130062 130058 0 23:43 ? 00:00:00 nginx: worker process
-
回滚
kill -HUP 64354
-
关闭旧的nginx进程
kill -QUIT 64354
-
异常问题解决
-
Q:
checking for C compiler ... not found ./configure: error: C compiler cc is not found
A:
yum -y install gcc-c++
-
Q:
checking for gcc -pipe switch ... found checking for --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E" ... not found ./configure: error: the invalid value in --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E"
A:
yum install redhat-rpm-config
-
Q:
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
A:
yum install pcre-devel openssl-devel
-
Q:
./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.
A:
yum install libxslt-devel
-
Q:
./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.
A:
yum install gd-devel
-
Q:
./configure: error: perl module ExtUtils::Embed is required
A:
yum install perl-ExtUtils-Embed
-
Q:
./configure: error: the Google perftools module requires the Google perftools library. You can either do not enable the module or install the library.
A:
yum install gperftools-devel
-