nginx平滑升级

本文详细介绍了如何平滑升级nginx,包括下载新版本或功能包,获取并保留当前编译参数,重新编译并添加新模块,以及备份和替换原有程序。同时提到了二进制安装的步骤,如创建系统用户,安装依赖,配置日志目录,下载并编译nginx,以及如何添加和测试新功能。

平滑升级

平滑升级
1.下载新功能包或新版本程序
2.获取当前版本编译参数
3.重新编译加上新功能模块 --add-module=PATH
4.不要执行make install 只能执行make
5.备份原程序
6.替换原程序
pkill nginx ; \cp objs/nginx /usr/local/nginx/sbin ; nginx

二进制安装nginx

创建nginx系统用户

[root@czh  ~]# useradd -r -M -s /sbin/nologin nginx

安装依赖环境

[root@czh ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ wget make
[root@czh ~]# yum -y groups mark install 'Development Tools'

创建日志存放目录

[root@czh ~]# mkdir -p /var/log/nginx
[root@czh ~]# chown -R nginx.nginx /var/log/nginx

下载nginx

wget https://nginx.org/download/nginx-1.20.1.tar.gz

解压 然后编译安装

[root@czh nginx]# tar xf nginx-1.20.1.tar.gz 
[root@czh nginx-1.20.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
[root@czh nginx-1.20.1]# make && make install

设置环境变量

[root@czh nginx-1.20.1]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@czh nginx-1.20.1]# . /etc/profile.d/nginx.sh

添加echo功能
查看nginx编译的时候安装了哪些

[root@czh ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
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

下载echo功能的包和nginx的包

[root@czh ~]# yum -y install git
[root@czh ~]# git clone https://github.com/openresty/echo-nginx-module.git
[root@czh ~]# wget https://nginx.org/download/nginx-1.20.1.tar.gz
[root@czh ~]# ls
anaconda-ks.cfg  echo-nginx-module  nginx-1.20.1  nginx-1.20.1.tar.gz

进行升级

[root@czh ~]# cp /usr/local/nginx/sbin/nginx{,-bak}
[root@czh ~]#cd nginx-1.20.1/
[root@czh nginx-1.20.1]# ./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 --add-module=/root/echo-nginx-module
[root@czh nginx-1.20.1]# make     //这里make就行了 不用makeinstall
root@czh nginx-1.20.1]# pkill nginx;\cp objs/nginx /usr/local/nginx/sbin/;nginx    //这里就不要一个个手动输了
 
查看安装后的
[root@czh nginx-1.20.1]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
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 --add-module=/root/echo-nginx-module

测试

[root@czh nginx-1.20.1]# vim /usr/local/nginx/conf/nginx.conf

        location /text {
            echo "text";
        }


[root@czh nginx-1.20.1]# 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
[root@czh nginx-1.20.1]# nginx -s reload
[root@czh nginx-1.20.1]# curl 192.168.31.140/text
text

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值