①.对于软件的版本升级、添加官方模块、添加第三方模块,都需要用源码安装包重新生成(configure)、编译(make)、安装(make install),在企业生产中的源码安装包,一般需要存放在固定的位置,以便不时之需;

②.对于软件的版本回滚,只需要将软链接文件重新指向版本升级前的目录即可;

③.对于升级后(或添加了新模块)的版本,需要将旧版本中的 .pid 文件、.conf 配置文件以及我们修改(或创建)的其他重要文件和目录 拷贝到新版本目录的对应位置,再使用平滑重启,避免影响用户体验,也升级了版本,添加了新的功能 ;

④.对于添加某些第三方模块,需要使用 patch 命令,在源码安装包目录下指定补丁文件,再进行生成(configure)、编译(make)、安装(make install);

⑤.patch 命令,本质上是对源码文件作出修改(补丁),进行了升级:

参考信息

# 先参考使用官方YUM仓库 安装的 nginx-1.18.0 的配置参数,源码安装时,可以在此基础上稍作修改
[root@blog ~]# nginx -V
nginx version: nginx/1.18.0
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: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

源码安装 nginx-1.14.2

# 安装 nginx 依赖包,以及 patch 包
[root@lb02 ~]# yum install -y gcc glibc gcc-c++ pcre-devel openssl-devel patch # 下载 nginx-1.14.2 源码安装包,下载 nginx_upstream_check_module 模块补丁
[root@lb01 ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz
[root@lb01 ~]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip # 解压 nginx 源码包,以及第三方模块 nginx_upstream_check_module
[root@lb01 ~]# tar xf nginx-1.14.2.tar.gz
[root@lb01 ~]# unzip master.zip # 进入 nginx-1.14.2 目录,打补丁(-p1 表示源码安装包和补丁文件的绝对路径中,不同的目录的层数)
[root@lb01 ~]# cd nginx-1.14.2/
[root@lb01 nginx-1.14.2]# patch -p1 <../nginx_upstream_check_module-master/check_1.14.0+.patch # 生成,将第三方模块加入
[root@lb01 nginx-1.14.2]# ./configure --prefix=/app/nginx-1.14.2 --user=www --group=www --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/root/nginx_upstream_check_module-master --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' # 编译
[root@lb01 nginx-1.14.2]# make # 安装
[root@lb01 nginx-1.14.2]# make install # 给安装后的目录 创建一个软链接
[root@lb01 ~]# ln -s /app/nginx-1.14.2 /app/nginx # 添加环境变量
[root@lb01 ~]# echo 'export PATH="$PATH:/app/nginx/sbin/"' > /etc/profile.d/path.sh
[root@lb01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/app/nginx/sbin/:/root/bin # 修改 nginx.conf 主配置文件
[root@lb01 ~]# cat /app/nginx/conf/nginx.conf
user www;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include conf.d/*.conf;
} # 创建 conf.d 子配置文件目录
[root@lb01 ~]# mkdir /app/nginx/conf/conf.d # 编辑子配置文件
[root@lb01 conf.d]# vi default.conf <-------- # 方便在浏览器看 nginx 版本号
server {
listen 80;
server_name lb.com;
root html;
index index.html;
} [root@lb01 ~]# vi /app/nginx/conf/conf.d/all.conf
upstream all {
server 172.16.1.8;
server 172.16.1.7;
server 172.16.1.9;
check interval=3000 rise=2 fall=3 timeout=1000 type=tcp;
}
server {
listen 80;
server_name wecenter.wqh.com blog.wqh.com phpmyadmin.com;
location / {
proxy_pass http://all;
include proxy_params;
}
location /check {
check_status;
}
} # 编写 proxy_params 文件
[root@lb01 ~]# vi /app/nginx/conf/proxy_params
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
proxy_buffering on;
proxy_buffers 8 4k;
proxy_buffer_size 4k; # 启动 nginx 或者 重新加载 nginx 配置文件
[root@lb01 ~]# nginx
[root@lb01 ~]# nginx -s reload

版本升级 nginx-1.16.1

# 下载 nginx-1.14.2 源码安装包
[root@lb01 ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz # 解压源码包
[root@lb01 ~]# tar xf nginx-1.16.1.tar.gz # 进入 nginx-1.16.1 目录,打补丁
[root@lb01 nginx-1.16.1]# patch -p1 <../nginx_upstream_check_module-master/check_1.16.1+.patch # 生成,并将第三方模块加入
[root@lb01 nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --user=www --group=www --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/root/nginx_upstream_check_module-master --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' # 编译
[root@lb01 nginx-1.16.1]# make # 安装
[root@lb01 nginx-1.16.1]# make install # 将 pid 文件 拷贝到新的安装目录
[root@lb01 ~]# \cp /app/nginx/logs/nginx.pid /app/nginx-1.16.1/logs/ # 将 nginx.conf 主配置文件 拷贝到新的安装目录
[root@lb01 ~]# \cp /app/nginx/conf/nginx.conf /app/nginx-1.16.1/conf/ # 将 nginx.conf 子配置文件目录 拷贝到新的安装目录
[root@lb01 ~]# \cp -r /app/nginx/conf/conf.d /app/nginx-1.16.1/conf/ # 将 proxy_params 拷贝到新的安装目录
[root@lb01 ~]# \cp /app/nginx/conf/proxy_params /app/nginx-1.16.1/conf/ # 将 站点目录 拷贝到新的安装目录
[root@lb01 conf.d]# \cp -r /app/nginx/html /app/nginx-1.16.1/ # 重置软链接文件
[root@lb01 ~]# cd /app/
[root@lb01 app]# ll
total 0
lrwxrwxrwx 1 root root 12 May 28 17:50 nginx -> nginx-1.14.2
drwxr-xr-x 11 root root 151 May 28 18:29 nginx-1.14.2
drwxr-xr-x 6 root root 54 May 28 20:07 nginx-1.16.1
[root@lb01 app]# rm -rf nginx && ln -s nginx-1.16.1/ nginx
[root@lb01 app]# ll
total 0
lrwxrwxrwx 1 root root 13 May 28 20:25 nginx -> nginx-1.16.1/
drwxr-xr-x 11 root root 151 May 28 18:29 nginx-1.14.2
drwxr-xr-x 6 root root 54 May 28 20:07 nginx-1.16.1 # 快速重启 nginx
[root@lb01 ~]# nginx -s stop && nginx

版本回滚

# 重置软链接文件
[root@lb01 ~]# cd /app/
[root@lb01 app]# rm -rf nginx && ln -s nginx-1.14.2/ nginx # 快速重启 nginx
[root@lb01 ~]# nginx -s stop && nginx

Nginx 版本回滚的更多相关文章

  1. nginx之热部署,以及版本回滚

    热部署的概念:当从老版本替换为新版本的nginx的时候,如果不热部署的话,会需要取消nginx服务并重启服务才能替换成功,这样的话会使正在访问的用户在断开连接,所以为了不影响用户的体验,且需要版本升级 ...

  2. TortoiseSVN 版本回滚

    尝试用TortoiseSVN进行版本回滚,回滚到的版本和实际的内容有出入,可能是点了太多次给点乱了,囧~ 不过发现一个比较靠谱的方法,如下: 右键点击文件TortoiseSVN->showlog ...

  3. svn 日志版本回滚

    [root@v01 online]# svn diff -r 9:8 Index: index.html =============================================== ...

  4. git---远程仓库版本回滚

    开发中,发现有错误版本提交带远程分支master,怎么处理? 1 简介 最近在使用git时遇到了远程分支需要版本回滚的情况,于是做了一下研究,写下这篇博客. 2 问题 如果提交了一个错误的版本,怎么回 ...

  5. SVN系列之—-SVN版本回滚的办法

    例:SVN版本为:TortoiseSVN 1.9.7 一.SVN简介 subversion(简称svn)是一种跨平台的集中式版本控制工具,支持linux和windows. 版本控制解决了:*代码管理混 ...

  6. SVN版本回滚实战

    天在使用SVN发布的时候不小心修改了一些不正确的东西,新增和编辑了一些错误的文件,由于文件数量比较多,并且目录复杂,不可能单个进行处理,所以想到了SVN版本回滚. 回滚本地工作目录: 1.右键工作目录 ...

  7. 用Helm部署Kubernetes应用,支持多环境部署与版本回滚

    1 前言 Helm是优秀的基于Kubernetes的包管理器.利用Helm,可以快速安装常用的Kubernetes应用,可以针对同一个应用快速部署多套环境,还可以实现运维人员与开发人员的职责分离.现在 ...

  8. git版本回滚

    本地版本回滚 git reset --hard <版本号> (git log 可查看版本号,版本号不用写全) 远程仓库版本回滚 先在本地将版本回滚 ,然后git push -f 强制提交

  9. SVN版本回滚~

    如果你在svn上对文件进行编辑作了修改,想撤销,那么有两种方法可以还原:1) svn revert <yourfile>2) 手动删除该文件,重新执行svn up(rm <yourf ...

随机推荐

  1. 为什么[] == false 为true

    首先要讲一下js的数据类型分为: 1.基本数据类型(原始数据类型):String.Boolean.Number.null.undefined.Symbol 2.引用数据类型:Object.Array. ...

  2. MySQL下载与安装教程

    一,下载篇 1,首先访问MySQL官网下载页,https://dev.mysql.com/downloads/mysql/ 如果是MAC系统,操作系统请选择macOS,Windows则选择Window ...

  3. MAX232数据方向

    在调试一个新板子的时候,串口调试从来都是放在前面的,而由于是一个新板子,电路图也是新的,因此有时候不知道串口线结对了没有,这个时候可能会对照PCB和原理图去看一下,但有时候看的人会很迷糊,因为不同的人 ...

  4. 文件系统层次结构标准 Linux 系统目录结构

    https://zh.wikipedia.org/wiki/文件系统层次结构标准 多数Linux发行版遵从FHS标准并且声明其自身政策以维护FHS的要求. [3] [4] [5] [6] 但截至200 ...

  5. 匿名字段 内嵌结构体 interface作为struct field 匿名接口

    interface作为struct field,谈谈golang结构体中的匿名接口 - Go语言中文网 - Golang中文社区 https://studygolang.com/articles/19 ...

  6. 消息队列扫盲(RocketMQ 入门)

    消息队列扫盲 消息队列顾名思义就是存放消息的队列,队列我就不解释了,别告诉我你连队列都不知道似啥吧? 所以问题并不是消息队列是什么,而是 消息队列为什么会出现?消息队列能用来干什么?用它来干这些事会带 ...

  7. 20201104gryz模拟赛解题报告

    写在前面 \(Luckyblock\) 良心出题人, 题面好评 T1还是蛮简单的,用一个栈来维护就能过(某天听说 \(Luckyblock\) 出了套题,T1是个考栈的,看来就是这道了 注:栈的清空只 ...

  8. PowerQuery合并查询原理

    PowerQuery的合并查询比Excel中的VLOOKUP更加强大,下面对查询的类型做一个梳理, 1.左外部(第一个中的所有行,第二个中的匹配行):用左边表内的所有行去右边找它的匹配项 2.右外部( ...

  9. Web漏洞扫描-AWVS

    Web漏洞扫描-AWVS 一.AWVS概述 二.功能以及特点 三.AWVS界面 四.AWVS使用 相关优质博文: CSDN:帽子不够白:WEB渗透测试之三大漏扫神器 一.AWVS概述 Acunetix ...

  10. html播放音乐目前只支持ie

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...