nginx平滑升级

文章详细描述了如何在CentOS7系统中将Nginx从1.12.2版本平滑升级到1.21.5版本,包括查看当前版本、下载新版本、配置编译、处理依赖问题以及执行升级操作等步骤。在升级过程中,需要注意保留原有的配置和模块,并避免直接使用`makeinstall`以防止覆盖原有安装,确保服务器的不间断运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nginx下载:Index of /download/

CentOS 7 Nginx1.12.2平滑升级到新版本nginx-1.21.5

查看当前Nginx版本信息

[root@web ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-pcre --with-openssl=/tmp/openssl-1.1.0e --with-http_ssl_module --with-http_v2_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-http_image_filter_module --with-mail --with-threads --with-mail_ssl_module --with-stream_ssl_module

下载nginx-1.21.5版本到/usr/local/下,解压并进入解压后的目录

[root@nginx ~]# cd /usr/local/
[root@nginx ~]# wget http://nginx.org/download/nginx-1.21.5.tar.gz
[root@nginx ~]# tar xf nginx-1.21.5.tar.gz
[root@nginx ~]# cd nginx-1.21.5

配置nginx

查看nginx版本的时候,configure后面有一大串模块,这也是你第一次安装nginx时所指定的模块,升级的时候也要同时指定,也可以添加其他模块

[root@nginx nginx-1.21.5]# ./configure \
  --prefix=/usr/local/nginx \
  --user=nginx \
  --group=nginx \
  --with-pcre \
  --with-openssl=/tmp/openssl-1.1.0e \
  --with-http_ssl_module \
  --with-http_v2_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-http_image_filter_module \
  --with-mail \
  --with-threads \
  --with-mail_ssl_module \
  --with-stream_ssl_module \
 && make

make完以后,不需要执行make install,否则会覆盖安装,nginx服务会出现各种问题

不中断nginx web服务器的正常运行称之为平滑升级,先重命名之前的nginx二进制文件

[root@nginx nginx-1.21.5]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

拷贝刚编译新生产的Nginx二进制文件到/usr/local/nginx/sbin/目录

[root@nginx nginx-1.21.5]# cp /usr/local/nginx-1.21.5/objs/nginx /usr/local/nginx/sbin/

开始执行升级命令

[root@web nginx-1.21.5]# make upgrade
/usr/local/nginx/sbin/nginx -t
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
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

查看nginx版本信息

[root@web nginx-1.13.3]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.21.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
built with OpenSSL 1.1.0e  16 Feb 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-pcre --with-openssl=/tmp/openssl-1.1.0e --with-http_ssl_module --with-http_v2_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-http_image_filter_module --with-mail --with-threads --with-mail_ssl_module --with-stream_ssl_module

注意:

报错:nginx unknown directive "stream"

nginx默认安装的时候没有加载stream模块

需要重新对源文件进行编译、安装,通过添加--with-stream参数指定安装stream模块

./configure --with-stream

make & make install

再次检查nginx.conf配置文件,确认配置无语法错误后,再次尝试启动服务。

nginx -t 检查配置文件是否正确

nginx -c 指定启动的配置文件

报错1:
./configure: error: the HTTP XSLT module requires the libxml2/libxslt
libraries. You can either do not enable the module or install the libraries.
原因:缺少依赖
解决:
[root@vm-3 nginx-1.21.5]# yum -y install libxml2 libxslt-devel

再次配置
报错2:
./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.
解决:安装依赖
yum -y install gd-devel

再次配置
报错3:
./configure: error: perl module ExtUtils::Embed is required
解决:
yum -y install perl-devel perl-ExtUtils-Embed
再次配置
报错4:
./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library.
解决:
yum -y install GeoIP GeoIP-devel GeoIP-data
再次配置
报错5:
./configure: error: the Google perftools module requires the Google perftools
library. You can either do not enable the module or install the library.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值