centos 7 Nginx升级(源码版)

20 篇文章 0 订阅

升级一般是添加新的模块,或者升级版本,所以要参考以前编译的模块,如果不添加,那么以前的模块就不能使用了
直接开始

升级方法一:make upgrade

此方法过程不可控
将旧版升级至1.16.1

[root@localhost ~]# /usr/local/nginx/sbin/nginx -V   查看旧版本预编译模块信息
nginx version: JWS
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-

http_ssl_module --with-http_mp4_module --with-http_realip_module --with-pcre --with-http_gunzip_module --with-

http_gzip_static_module

解压新源码包

[root@localhost src]# tar -xf nginx-1.16.1.tar.gz 
[root@localhost src]# cd nginx-1.16.1

预编译新源码包

[root@localhost nginx-1.16.1]# ./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_mp4_module \
--with-http_realip_module \
--with-pcre \
--with-http_gunzip_module \
--with-http_gzip_static_module 

编译安装

[root@localhost nginx-1.16.1]# make
[root@localhost nginx-1.16.1]# make install

升级 make upgrade

[root@localhost nginx-1.16.1]# 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`	#生成新版本1.16.1的master进程
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin #测试
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin` #退出旧版本master进程

查看新版本

[root@localhost nginx-1.16.1]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.16.1

升级方法二:

不影响现有使用,过程完全掌握(将旧版本升级至1.18.0)
1、下载新版本源码安装包

[root@localhost src]# wget http://nginx.org/download/nginx-1.18.0.tar.gz

2、查看旧版本安装信息

[root@localhost src]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_mp4_module --with-http_realip_module --with-pcre --with-http_gunzip_module --with-http_gzip_static_module

3、解压

[root@localhost src]# tar -xf nginx-1.18.0.tar.gz 
[root@localhost src]# cd nginx-1.18.0

4、编译安装

[root@localhost nginx-1.18.0]# ./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_mp4_module \
--with-http_realip_module \
--with-pcre \
--with-http_gunzip_module \
--with-http_gzip_static_module
[root@localhost nginx-1.18.0]# make
[root@localhost nginx-1.18.0]# make install
[root@localhost nginx-1.18.0]# ll /usr/local/nginx/sbin/   会自动替换nginx二进制文件,且将1.61版本的文件备份
total 12160
-rwxr-xr-x 1 root root 6239912 May 21 15:45 nginx
-rwxr-xr-x 1 root root 6209536 May 21 15:43 nginx.old

注:此时使用的还是旧版本,尚未切换
5、查看1.61旧进程

[root@localhost nginx-1.16.1]# ps -ef|grep nginx
root     10357     1  0 15:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www      10358 10357  0 15:43 ?        00:00:00 nginx: worker process
root     10360  1993  0 15:43 pts/0    00:00:00 grep --color=auto nginx

6、查看新版本配置文件是否正确

[root@localhost nginx-1.18.0]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.18.0

7、生成新的1.80版本master进程

[root@localhost nginx-1.18.0]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
[root@localhost nginx-1.18.0]# ps -ef|grep nginx
root     10357     1  0 15:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www      13068 10357  0 15:51 ?        00:00:00 nginx: worker process
root     13072 10357  0 15:53 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www      13073 13072  0 15:53 ?        00:00:00 nginx: worker process
root     13075  1993  0 15:53 pts/0    00:00:00 grep --color=auto nginx

8、优雅退出老版的worker工作进程

[root@localhost nginx-1.18.0]# kill -WINCH 10357
[root@localhost nginx-1.18.0]# ps -ef|grep  nginx
root     10357     1  0 15:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
root     13072 10357  0 15:53 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www      13073 13072  0 15:53 ?        00:00:00 nginx: worker process
root     13084  1993  0 15:57 pts/0    00:00:00 grep --color=auto nginx

9、测试运行,发现没有问题,就可以退出旧的master进程了,kill -QUIT 10357

[root@localhost nginx-1.18.0]# kill -QUIT 10357
[root@localhost nginx-1.18.0]# ps -ef|grep  nginx
root     13072 10357  0 15:53 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www      13073 13072  0 15:53 ?        00:00:00 nginx: worker process
root     13084  1993  0 15:57 pts/0    00:00:00 grep --color=auto nginx

10、测试运行,如发现问题,立马回滚
回滚
拉起老进程

[root@localhost nginx-1.18.0]# kill -HUP 10357
[root@localhost nginx-1.18.0]# ps -ef|grep  nginx
root     10357     1  0 15:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
root     13072 10357  0 15:53 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www      13073 13072  0 15:53 ?        00:00:00 nginx: worker process
www      13101 10357  0 16:01 ?        00:00:00 nginx: worker process
root     13103  1993  0 16:01 pts/0    00:00:00 grep --color=auto nginx

退出新的master进程

[root@localhost nginx-1.18.0]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`
[root@localhost nginx-1.18.0]# ps -ef|grep nginx
root     10357     1  0 15:43 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www      13101 10357  0 16:01 ?        00:00:00 nginx: worker process
root     13108  1993  0 16:03 pts/0    00:00:00 grep --color=auto nginx

换回nginx二进制文件,删除新nginx,恢复旧的nginx

[root@localhost nginx-1.18.0]# rm -rf /usr/local/nginx/sbin/nginx
[root@localhost nginx-1.18.0]# mv /usr/local/nginx/sbin/nginx.old /usr/local/nginx/sbin/nginx

----------end

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值