一、升级Nginx
1、查看旧版本nginx的编译参数
nginx -V
2、安装新版本
# wget https://nginx.org/download/nginx-1.24.0.tar.gz
# tar zxf nginx-1.24.0.tar.gz
# cd nginx-1.24.0/
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-compat --with-pcre-jit
# make -j `nproc`
编译新版本Nginx源码包,安装路径必须与旧版本一致,且不能执行make install
2、备份二进制文件用新版本代替
# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old #将旧版本的nginx改名并备份
# ls
auto CHANGES.ru configure html Makefile objs src
CHANGES conf contrib LICENSE man README
# ls objs/
autoconf.err nginx ngx_auto_config.h ngx_modules.c src
# cp objs/nginx /usr/local/nginx/sbin
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? yes
# ll /usr/local/nginx/sbin
total 3772
# ll /usr/local/nginx/sbin/
total 8044
-rwxr-xr-x 1 root root 3858728 Feb 6 15:42 nginx #新版本
-rwxr-xr-x 1 root root 4373160 Feb 6 15:44 nginx.old #旧版本
# nginx -t #启动nginx,让新的配置文件加载旧的配置文件看兼容不兼容
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
为了升级服务器可执行文件,应首先将新的可执行文件替换旧文件。之后应该将 USR2 信号发送到主进程。主进程首先将其带有进程 ID 的文件重命名为带有.oldbin
后缀的新文件,例如 /usr/local/nginx/logs/nginx.pid.oldbin
,然后启动一个新的可执行文件,该文件又启动新的工作进程:
# mv /usr/local/nginx/logs/nginx.pid /usr/local/nginx/logs/nginx.pid.oldbin
3、进行信号处理(发送USR2信号)
向主进程(master)发送USR2信号。Nginx会启动一个新版本的master进程和对应的工作进程
和旧版本一起处理请求
# ps -aux | grep nginx
root 19604 0.0 0.1 20560 1232 ? Ss 15:45 0:00 nginx: master process nginx # 旧进程
nginx 19607 0.0 0.5 24812 5124 ? S 15:45 0:00 nginx: worker process # 旧进程
root 19609 0.0 0.0 112708 988 pts/0 R+ 15:45 0:00 grep --color=auto nginx
root 71140 0.0 0.0 112724 992 pts/1 S+ 20:00 0:00 grep --color=auto nginx
# kill -USR2 68104 # 杀掉旧进程主程序
kill -WINCH 68104
nginx -s reload 68104 # 版本回退
# nginx -V
nginx version: nginx/1.16.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
二、处理因openssl升级引起的错误
1、错误一
在编译nginx-1.22.0时,出现以下错误
$ make
make -f objs/Makefile
make[1]: Entering directory `/data/soft/nginx-1.22.0'
cd /usr/local/ssl \
&& if [ -f Makefile ]; then make clean; fi \
&& ./config --prefix=/usr/local/ssl/.openssl no-shared no-threads \
&& make \
&& make install_sw LIBDIR=lib
/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/ssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/data/soft/nginx-1.22.0'
make: *** [build] Error 2
在nginx-1.22.0/auto/lib/openssl/目录下,文件conf中记录了相关的配置,因此只需要修改conf文件中的以下内容
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
CORE_LIBS="$CORE_LIBS $NGX_LIBPTHREAD"
中$OPENSSL/后的.openssl删除即可,修改之后的如下所示:
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
CORE_LIBS="$CORE_LIBS $NGX_LIBPTHREAD"
然后重新make即可
或者重新./configure,然后make即可解决该问题。
2、错误二
cc: error: /usr/local/openssl-3.0/lib/libssl.a: No such file or directory
cc: error: /usr/local/openssl-3.0/lib/libcrypto.a: No such file or directory
make[1]: *** [objs/nginx] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory `/usr/src/nginx-1.24.0'
make: *** [build] Error 2
原因是libssl.a和libcrypto.a并不在lib目录下,而是在lib64目录下,做个软链接即可
ln -s lib64 lib
或者直接在上一步更改conf文件
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib64/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib64/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
CORE_LIBS="$CORE_LIBS $NGX_LIBPTHREAD"
评论区