Nginx 版本回滚
①.对于软件的版本升级、添加官方模块、添加第三方模块,都需要用源码安装包重新生成(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 版本回滚的更多相关文章
- nginx之热部署,以及版本回滚
热部署的概念:当从老版本替换为新版本的nginx的时候,如果不热部署的话,会需要取消nginx服务并重启服务才能替换成功,这样的话会使正在访问的用户在断开连接,所以为了不影响用户的体验,且需要版本升级 ...
- TortoiseSVN 版本回滚
尝试用TortoiseSVN进行版本回滚,回滚到的版本和实际的内容有出入,可能是点了太多次给点乱了,囧~ 不过发现一个比较靠谱的方法,如下: 右键点击文件TortoiseSVN->showlog ...
- svn 日志版本回滚
[root@v01 online]# svn diff -r 9:8 Index: index.html =============================================== ...
- git---远程仓库版本回滚
开发中,发现有错误版本提交带远程分支master,怎么处理? 1 简介 最近在使用git时遇到了远程分支需要版本回滚的情况,于是做了一下研究,写下这篇博客. 2 问题 如果提交了一个错误的版本,怎么回 ...
- SVN系列之—-SVN版本回滚的办法
例:SVN版本为:TortoiseSVN 1.9.7 一.SVN简介 subversion(简称svn)是一种跨平台的集中式版本控制工具,支持linux和windows. 版本控制解决了:*代码管理混 ...
- SVN版本回滚实战
天在使用SVN发布的时候不小心修改了一些不正确的东西,新增和编辑了一些错误的文件,由于文件数量比较多,并且目录复杂,不可能单个进行处理,所以想到了SVN版本回滚. 回滚本地工作目录: 1.右键工作目录 ...
- 用Helm部署Kubernetes应用,支持多环境部署与版本回滚
1 前言 Helm是优秀的基于Kubernetes的包管理器.利用Helm,可以快速安装常用的Kubernetes应用,可以针对同一个应用快速部署多套环境,还可以实现运维人员与开发人员的职责分离.现在 ...
- git版本回滚
本地版本回滚 git reset --hard <版本号> (git log 可查看版本号,版本号不用写全) 远程仓库版本回滚 先在本地将版本回滚 ,然后git push -f 强制提交
- SVN版本回滚~
如果你在svn上对文件进行编辑作了修改,想撤销,那么有两种方法可以还原:1) svn revert <yourfile>2) 手动删除该文件,重新执行svn up(rm <yourf ...
随机推荐
- Spring入门及IoC的概念
Spring入门 Spring是一个轻量级的Java开发框架,最早由Robd Johnson创建,目的为了解决企业级应用开发的业务逻辑层和其他各层的耦合问题,它是一个分层的JavaSE/EE轻量级开源 ...
- Android iText向pdf模板插入数据和图片
一.需求 这些日志在写App程序,有这么一个需求,就是需要生成格式统一的一个pdf文件,并向固定表格中填充数据,并且再在pdf中追加两页图片. 二.方案 手工设计一个pdf模板,这个具体步骤就不再赘述 ...
- java虚拟机入门(三)- 你了解对象吗
对象对于java程序员来说,那是想要多少就有多少,所以那些嘲笑程序员的单身狗,哼,只有无知使你们快乐,想我大java开发,何曾缺少过对象.我们不仅仅知道创建对象,还知道创建对象的过程是啥样的,不信?往 ...
- Linux防火墙和iptables
1. CentOS 查看防火墙状态: systemctl status firewalld firewall-cmd --state 启停防火墙: # 开启 systemctl start firew ...
- wordpress迁移报错
背景: 因为一些原因迁移wordpress的博客.备份好数据库和网站源码到另一台生产环境上线的时候报错: Warning: require(/www/wwwroot/pazzn/wp-includes ...
- jQuery 点击当前展开其他隐藏
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- loj10004智力大冲浪
题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者 m 元.先不要太高兴!因为这些钱还不一定都是你的?!接下来主持人宣布了比赛规则 ...
- 【Python爬虫】:使用高性能异步多进程爬虫获取豆瓣电影Top250
在本篇博文当中,将会教会大家如何使用高性能爬虫,快速爬取并解析页面当中的信息.一般情况下,如果我们请求网页的次数太多,每次都要发出一次请求,进行串行执行的话,那么请求将会占用我们大量的时间,这样得不偿 ...
- MySQL集群之MyCat
MySQL集群之MyCat 一.MyCat简介及分析 1.1 MyCat是什么? 1.2 关键特性及应用场景 1.2.1 关键特性 1.2.2 应用场景 1.2.3 MyCat不适合的应用场景 1.3 ...
- Prometheus+Grafana+kafka_exporter监控kafka
Prometheus+Grafana+kafka_exporter搭建监控系统监控kafka 一.Prometheus+Grafana+kafka_exporter搭建监控系统监控kafka 1.1K ...
