平滑升级(适用于所有的编译安装软件)

平滑升级步骤:

  1. 获取之前的编译参数

  2. 下载新模块

  3. 重新编译软件,加上--add-module=新模块的解压路径

  4. 停止服务并备份原程序

  5. 把原程序用新程序覆盖

  6. 启动新程序

演示如下(本次以nginx为例):

nginx的安装详情请见:Nginx的安装和配置

获取之前的安装nginx的编译参数

[root@nginx ~]# nginx -V
nginx version: nginx/1.20.0
built by gcc 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC) 
built with OpenSSL 1.1.1g FIPS  21 Apr 2020
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

下载新模块

模块的地址:https://github.com/openresty/echo-nginx-module

下载到本地,使用xftp传到本机

image

[root@nginx ~]# ls
anaconda-ks.cfg  echo-nginx-module-master.zip  nginx-1.20.0  nginx-1.20.0.tar.gz

重新编译软件

注意事项:

  1. 模块文件要和nginx解压目录平级
  2. 添加完新模块make编译成功后,不要马上make install安装

开始操作

//安装unzip工具
[root@nginx ~]# yum -y install unzip

//解压新的模块包
[root@nginx ~]# unzip echo-nginx-module-master.zip 
[root@nginx ~]# ls
anaconda-ks.cfg           echo-nginx-module-master.zip  nginx-1.20.0.tar.gz
echo-nginx-module-master  nginx-1.20.0

//删除之前解压的编译目录,再次解压
[root@nginx ~]# rm -rf nginx-1.20.0
[root@nginx ~]# tar xf nginx-1.20.0.tar.gz 
[root@nginx ~]# cd nginx-1.20.0
[root@nginx nginx-1.20.0]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README

//添加新的模块进行编译安装
#生成makefile文件
[root@nginx 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 
--add-module=../echo-nginx-module-master           //使用--add-module=新模块的解压路径
[root@nginx nginx-1.20.0]# ls
auto     CHANGES.ru  configure  html     Makefile  objs    src
CHANGES  conf        contrib    LICENSE  man       README

#objs目录下没有nginx程序
[root@nginx nginx-1.20.0]# ls objs/
addon         Makefile           ngx_auto_headers.h  src
autoconf.err  ngx_auto_config.h  ngx_modules.c

#编译
[root@nginx nginx-1.20.0]# make

#objs目录下有nginx程序,说明成功
[root@nginx nginx-1.20.0]# ls objs/
addon         Makefile  nginx.8            ngx_auto_headers.h  ngx_modules.o
autoconf.err  nginx     ngx_auto_config.h  ngx_modules.c       src

备份原程序并停止、覆盖、启动服务

注意事项:

  1. 备份以前的程序,以防本次升级的版本程序有问题
  2. 停止程序 覆盖程序 启动程序 应该一气呵成,尽可能减少服务停止时间

开始操作

//查看nginx升级前后的区别
#原有的nginx
[root@nginx nginx-1.20.0]# nginx -V
nginx version: nginx/1.20.0
built by gcc 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC) 
built with OpenSSL 1.1.1g FIPS  21 Apr 2020
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

#添加新功能的nginx
[root@nginx nginx-1.20.0]# objs/nginx -V
nginx version: nginx/1.20.0
built by gcc 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC) 
built with OpenSSL 1.1.1g FIPS  21 Apr 2020
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=../echo-nginx-module-master

//停止、备份、覆盖、启动程序
[root@nginx nginx-1.20.0]# nginx -s stop && cp /usr/local/nginx/sbin/nginx /opt && cp objs/nginx /usr/local/nginx/sbin/ && /usr/local/nginx/sbin/nginx
cp: overwrite '/usr/local/nginx/sbin/nginx'? y

//查看nginx信息
[root@nginx nginx-1.20.0]# nginx -V
nginx version: nginx/1.20.0
built by gcc 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC) 
built with OpenSSL 1.1.1g FIPS  21 Apr 2020
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=../echo-nginx-module-master

//查看端口
[root@nginx nginx-1.20.0]# ss -antl
State     Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0          128                  0.0.0.0:80                0.0.0.0:*       
LISTEN    0          128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0          128                     [::]:22                   [::]:*

测试

引用echo模块

//修改配置文件
[root@nginx ~]# cd /usr/local/nginx/conf/
[root@nginx conf]# vim nginx.conf
#修改以下内容
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            echo "hehe";    //修改此行
        }

#检查配置文件内容
[root@nginx conf]# 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@nginx conf]# nginx -s reload

网页访问

image

CMD命令提示符访问

image

原文地址:https://www.cnblogs.com/leixixi/p/14829274.html