- 1 背景
- 2 平滑升级
- 3 平滑升级命令
- 4 升级过程中遇到的问题及解决方案
- 4.1 错误1:error: the HTTP rewrite module requires the PCRE library
- 4.2 错误2:error: the HTTP gzip module requires the zlib library.
- 4.3 错误3:error: the HTTP XSLT module requires the libxml2/libxslt libraries.
- 4.4 错误4:error: the HTTP image filter module requires the GD library.
- 4.5 错误5:error: the GeoIP module requires the GeoIP library.
- 4.6 错误6:[emerg] module "/usr/lib/nginx/modules/ngx_http_passenger_module.so" version 1014000 instead of 1021004 in /etc/nginx/modules-enabled/50-mod-http-passenger.conf:1
- 4.6 错误6:报其他错误module.so的版本问题
- 4.6.1 ngx_http_xslt_filter_module.so
- 4.6.2 ngx_mail_module.so
- 4.6.3 ngx_stream_module.so
- 4.6.4 ngx_http_geoip_module.so
- 5 最后
系统为Ubuntu18.08,Nginx的旧版本为1.14.0,升级新版本为1.21.4;服务器上正在运行着服务,因此采用平滑升级的方式进行nginx升级。非root用户
2 平滑升级(1)在不停掉老进程的情况下,启动新进程。
(2)老进程负责处理仍然没有处理完的请求,但不再接受处理请求。
(3)新进程接受新请求。
(4)老进程处理完所有请求,关闭所有连接后,停止。
这样就很方便地实现了平滑升级。一般有两种情况下需要升级Nginx,一种是确实要升级Nginx的版本,另一种是要为Nginx添加新的模块。
3 平滑升级命令cd /mnt # 下载nginx升级包 sudo wget http://nginx.org/download/nginx-1.21.4.tar.gz # 解压升级包 sudo tar zxvf nginx-1.21.4.tar.gz cd nginx-1.21.4/ # 查看当前版本得到编译参数 sudo /usr/sbin/nginx -V # 参数:configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-H4cN7P/**nginx-1.14.0**=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module # 用上面编译参数,参数中的版本需要修改 sudo ./configure --prefix=/usr/local/nginx --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-H4cN7P/nginx-1.21.4=. -fstack-protector-strong....... # 编译make,千万别make install sudo make # make编译完后,在objs目录下就多了个nginx,这个就是新版本的程序了 # 备份原nginx文件 sudo mv /usr/sbin/nginx /usr/sbin/nginx-20211111 # 将新生成nginx执行文件复制到nginx/sbin下 cp objs/nginx /usr/sbin/nginx # 检测配置文件是否正确 sudo /usr/sbin/nginx -t # 执行升级(通过拷贝替换的方式可以不执行这一步了) make upgrade # 执行完后 sudo /usr/sbin/nginx -V # 到此就完成平滑升级。
参考文档:https://cloud.tencent.com/developer/article/1139955
4 升级过程中遇到的问题及解决方案 4.1 错误1:error: the HTTP rewrite module requires the PCRE library错误信息:
./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=option.
解决:
# 需要安装pcre包。 sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev # 你可能还需要安装 sudo apt-get install openssl libssl-dev
参考链接:
https://blog.csdn.net/pengshengli/article/details/86694967
错误信息:
./configure: error: the HTTP gzip module requires the zlib library. You can either disable the module by using --without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using --with-zlib=option.
解决:
# 找一个版本下载,解压、安装(安装前先configure) http://zlib.net/ # 使用的是1.2.11
参考链接:
https://blog.csdn.net/pengshengli/article/details/86694967
https://www.jb51.net/article/80468.htm
错误信息:
./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.
解决:
# 需要安装libxslt包。 sudo apt-get update sudo apt-get install libxslt-dev # 你可能还需要安装 sudo apt-get install libgd-dev # for the "error: the HTTP image filter module requires the GD library." error sudo apt-get install libgeoip-dev # for the GeoIP package
参考链接:
https://stackoverflow.com/questions/57415360/configure-error-the-http-xslt-module-requires-the-libxml2-libxslt-libraries
https://cloud.tencent.com/developer/article/1401078
错误信息:
./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.
解决:
# 需要安装libxslt包。 sudo apt-get update sudo apt-get install -y libgd-dev # 如果在安装libgd-dev时提示找不到 # 在 vim /etc/apt/sources.list 中添加一行ubuntu 的镜像源 deb http://security.ubuntu.com/ubuntu trusty-security main
参考链接:
https://blog.csdn.net/liuYinXinAll/article/details/88357669
https://stackoverflow.com/questions/57415360/configure-error-the-http-xslt-module-requires-the-libxml2-libxslt-libraries
https://cloud.tencent.com/developer/article/1401078
错误信息:
./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library.
解决:
# 需要安装libxslt包。 sudo apt-get update sudo apt-get install libgeoip-dev
参考链接:
https://blog.csdn.net/liuYinXinAll/article/details/88357669
https://stackoverflow.com/questions/57415360/configure-error-the-http-xslt-module-requires-the-libxml2-libxslt-libraries
https://cloud.tencent.com/developer/article/1401078
错误信息:执行 sudo /usr/sbin/nginx -t。因为服务器上使用passenger部署着rails的项目,因此遇到这个问题了。
nginx: [emerg] module "/usr/lib/nginx/modules/ngx_http_passenger_module.so" version 1014000 instead of 1021004 in /etc/nginx/modules-enabled/50-mod-http-passenger.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed
解决:
已安装了passenger相关模块(Installing Passenger + Nginx),需要重新添加ngx_http_passenger_module
passenger-config --nginx-addon-dir # 添加 --add-module=/your path/passenger/ngx_http_passenger_module sudo ./configure --prefix=/usr/local/nginx --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-H4cN7P/nginx-1.21.4=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --add-module=/usr/share/passenger/ngx_http_passenger_module # 重新编译 sudo make sudo cp objs/nginx /usr/sbin/nginx # 然后再次执行sudo /usr/sbin/nginx -t,可能会出现新的错误 # [emerg] module "ngx_http_passenger_module" is already loaded in /etc/nginx/modules-enabled/50-mod-http-passenger.conf:1 # 尝试修改50-mod-http-passenger.conf sudo vim /etc/nginx/modules-enabled/50-mod-http-passenger.conf # 注释掉 # load_module /usr/lib/nginx/modules/ngx_http_passenger_module.so;
参考链接:
https://stackoverflow.com/questions/10271332/can-i-add-passenger-support-to-a-existed-nginx-instead-of-rebuild-one
除了ngx_http_passenger_module.so外,其他模块可以从/mnt/nginx-1.21.4/objs/ 中拷贝指定的module 到/usr/share/nginx/modules/中
4.6.1 ngx_http_xslt_filter_module.so错误信息:
nginx: [emerg] module "/usr/share/nginx/modules/ngx_http_xslt_filter_module.so" version 1014000 instead of 1021004 in /etc/nginx/modules-enabled/50-mod-http-xslt-filter.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed
解决:
# 备份旧的module sudo mv /usr/share/nginx/modules/ngx_http_xslt_filter_module.so /usr/share/nginx/modules/ngx_http_xslt_filter_module.so.old # 拷贝新的module sudo cp objs/ngx_http_xslt_filter_module.so /usr/share/nginx/modules/ngx_http_xslt_filter_module.so4.6.2 ngx_mail_module.so
错误信息:
nginx: [emerg] dlopen() "/usr/share/nginx/modules/ngx_mail_module.so" failed (/usr/share/nginx/modules/ngx_mail_module.so: undefined symbol: SSL_CTX_set_options) in /etc/nginx/modules-enabled/50-mod-mail.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed
解决:
sudo mv /usr/share/nginx/modules/ngx_mail_module.so /usr/share/nginx/modules/ngx_mail_module.so.old sudo cp objs/ngx_mail_module.so /usr/share/nginx/modules/ngx_mail_module.so4.6.3 ngx_stream_module.so
错误信息:
nginx: [emerg] dlopen() "/usr/share/nginx/modules/ngx_stream_module.so" failed (/usr/share/nginx/modules/ngx_stream_module.so: undefined symbol: SSL_CTX_set_options) in /etc/nginx/modules-enabled/50-mod-stream.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed
解决:
sudo mv /usr/share/nginx/modules/ngx_stream_module.so /usr/share/nginx/modules/ngx_stream_module.so.old sudo cp objs/ngx_stream_module.so /usr/share/nginx/modules/ngx_stream_module.so4.6.4 ngx_http_geoip_module.so
错误信息:
nginx: [emerg] dlopen() "/usr/share/nginx/modules/ngx_http_geoip_module.so" failed (/usr/share/nginx/modules/ngx_http_geoip_module.so: undefined symbol: SSL_CTX_set_options) in /etc/nginx/modules-enabled/50-mod-stream.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed
解决:
sudo mv /usr/share/nginx/modules/ngx_http_geoip_module.so /usr/share/nginx/modules/ngx_http_geoip_module.so.old sudo cp objs/ngx_http_geoip_module.so /usr/share/nginx/modules/ngx_http_geoip_module.so5 最后
# 执行 sudo /usr/sbin/nginx -t # 输出 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful # 重新启动nginx sudo /etc/init.d/nginx restart



