3天精通nginx第三天-动态添加模块、平滑升级

在这里插入图片描述

Nginx动态添加模块

已经安装nginx但想要添加一个新模块,这就需要动态添加模块。现在以添加ngx_http_google_filter_module为例作为演示。

1.备份原文件

# 停止服务
/usr/local/nginx/sbin/nginx -s stop
# 将原nginx执行文件备份
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

在这里插入图片描述
2.下载ngx_http_google_filter_module模块

cd /usr/local/nginx/module
git clone https://github.com/openresty/echo-nginx-module.git

在这里插入图片描述
3.查看原nginx安装了那些模块

/usr/local/nginx/sbin/nginx -V

在这里插入图片描述

可以看出编译安装使用了 configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre

4.编译时添加新模块

/usr/local/nginx/nginx-1.14.0/configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --add-module=/usr/local/nginx/module/echo-nginx-module

在这里插入图片描述
5.编译

make

6.替换nginx二进制文件

# 将新生成的nginx复制到/usr/local/nginx/sbin/下
cp /usr/local/nginx/nginx-1.14.0/objs/nginx /usr/local/nginx/sbin/ 

在这里插入图片描述

平滑升级

1.下载想要升级的nginx包

wget http://nginx.org/download/nginx-1.21.6.tar.gz

2.解压nginx压缩包

tar -zxvf nginx-1.21.6.tar.gz

3.进入nginx-1.21.6文件夹下

cd nginx-1.21.6

4.查看原版本nginx 的配置

/usr/local/nginx/sbin/nginx -V

[root@localhost nginx-1.21.6]# /usr/local/nginx/sbin/nginx -V

#nginx的版本

nginx version: nginx/1.20.2
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

#nginx的配置信息

configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre

5.配置新版nginx

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre 

6.编译

make

7.移走原先的nginx二进制文件

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old

8.替换新编译的文件到原nginx的sbin目录下

cp objs/nginx /usr/local/nginx/sbin/

9.执行升级命令(在解压出的新版本的nginx源文件目录下执行)

make upgrade

[root@localhost nginx-1.21.6]# 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

10.查看是否升级成功

/usr/local/nginx/sbin/nginx -V

由原来的1.20.2已经升级到1.21.6

nginx version: nginx/1.21.6
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=/usr/local/nginx --with-http_ssl_module --with-pcre

如果感觉这篇文章对您有帮助,可以给博主点赞、评论、收藏,这样是对博主最大的鼓励,谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孑疋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值