Nginx扩展

nginx的平滑升级——添加新模块

nginx在编译安装完成之后,出于以下两种考虑都需要进行升级:

  • 版本更新
  • 添加未编译安装的模块

而nginx所采用的平滑升级可以保证在不停止服务的情况下解决以上问题。我们以动态增加–with-http_stub_status_module模块为例,步骤如下:

1. 查看nginx版本号及已安装模块

[root@zabbix ~]# nginx -V
nginx version: nginx/1.12.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

2.下载对应版本的源码包

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

3.解压并重新编译

[root@zabbix nginx]# tar -zxf nginx-1.12.0.tar.gz -C /usr/local/app/nginx/
[root@foundation7 nginx]# cd /usr/local/app/nginx/nginx-1.12.0/
[root@zabbix nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --with-http_stub_status_module
[root@foundation7 nginx-1.12.0]# make

源码安装三部曲:./configure && make &&make install

  • ./configure:用来检查当前的linux环境是否满足即将安装软件所需的依赖关系。
  • make:编译命令,可自动完成编译过程,且只对上次编译修改过的部分进行编译。从Makefile中读取指令执行
[root@zabbix nginx-1.12.0]# make
make -f objs/Makefile
make[1]: 进入目录“/usr/local/app/nginx/nginx-1.12.0”
make[1]: “objs/nginx”是最新的。
make[1]: 离开目录“/usr/local/app/nginx/nginx-1.12.0”
make -f objs/Makefile manpage
make[1]: 进入目录“/usr/local/app/nginx/nginx-1.12.0”
make[1]: 对“manpage”无需做任何事。
make[1]: 离开目录“/usr/local/app/nginx/nginx-1.12.0

可以看出当没有修改时,是不进行重新编译的。

4.替换nginx二进制文件
通过编译之后,源码包里的objs目录里便有了新的nginx文件,替换原来的nginx二进制文件,重新加载配置文件即可完成平滑升级。

[root@zabbix nginx-1.12.0]# cp /usr/local/app/nginx/sbin/nginx /usr/local/app/nginx/sbin/nginx.bak 
[root@zabbix nginx-1.12.0]# cp objs/nginx /usr/local/app/nginx/sbin/nginx
[root@zabbix nginx-1.12.0]# ll /usr/local/sbin/nginx 
lrwxrwxrwx. 1 root root 31 615 10:54 /usr/local/sbin/nginx -> /usr/local/app/nginx/sbin/nginx
[root@zabbix nginx-1.12.0]# nginx -t
nginx: the configuration file /usr/local/app/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/app/nginx/conf/nginx.conf test is successful
[root@zabbix nginx-1.12.0]# nginx -s reload
[root@zabbix ~]# nginx -V
nginx version: nginx/1.12.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_ --with-http_stub_status_module

可以看到,我们已经动态加载了–with-http_stub_status_module模块。

nginx的平滑升级——升级

1、查看当前版本

[root@zabbix ~]# nginx -V
nginx version: nginx/1.12.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

2、升级到新的版本

下载新版安装包到/tmp目录下
[root@Admin tmp]# ls
nginx-1.12.0.tar.gz   nginx-1.9.0.tar.gz

解压到当前目录
[root@Admin tmp]# tar -zxvf nginx-1.9.0.tar.gz 

进入解压目录进行以下操作
[root@Admin tmp]# cd nginx-1.9.0
[root@Admin nginx-1.9.0]# ./configure 
[root@Admin nginx-1.9.0]# make

进入已安装的nginx目录下,备份当前使用的nginx
[root@Admin nginx-1.9.0]# cd /opt/nginx/sbin/
[root@Admin sbin]# cp nginx nginx.old
[root@Admin sbin]# ls
nginx  nginx.old

将新版本的编译文件复制到安装目录
[root@Admin sbin]# cd /tmp/nginx-1.9.0
[root@Admin nginx-1.9.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@Admin nginx-1.9.0]# cp -rfp objs/nginx /opt/nginx/sbin/
cp:是否覆盖"/opt/nginx/sbin/nginx"? y

查看是否升级成功
[root@zabbix ~]# nginx -V
nginx version: nginx/1.9.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值