Nginx 版本快速升级切换

前言:
本文章适合有Linux基础者阅读,需掌握源码方式安装nginx(文中作者直接省略了nginx的源码安装过程)

1.当前系统环境

系统 主机名 IP地址
Centos 7.4 xmh 10.0.0.200

2.nginx版本
当前版本:nginx-1.12.2
新版本:nginx-1.14.2
本文章使用源码包方式安装nginx

  • nginx存放:/application
  • nginx命名:以nginx版本命名

需求:需要将正在运行的nginx-1.12.2版本快速切换到nginx-1.14.2

3.版本切换思路

1.删除原有的软链接(rm -rf nginx)
2.为新版本目录创建新的软链接(nginx-1.14.2 --> nginx)
3.停止旧版本的服务进程(./nginx-1.12.2/sbin/nginx -s stop)
4.启动新版本的服务进程(./nginx/sbin/nginx)
注意:以上四个步骤需要通过 && 结合一起执行

4.nginx版本切换

#1.先将新版本的源码包编译到对应的目录
[root@xmh ~]# cd /application/
[root@xmh application]# ll
lrwxrwxrwx  1 root root  14 Jan 29 11:29 nginx -> ./nginx-1.12.2
drwxr-xr-x 11 root root 151 Jan 29 11:22 nginx-1.12.2
drwxr-xr-x  6 root root  54 Jan 29 11:30 nginx-1.14.2  #新版本nginx

#2.为不同版本nginx中的index.html文件追加内容(区分)
[root@xmh application]# echo "This is nginx 1.12.2 old" >nginx-1.12.2/html/index.html
[root@xmh application]# echo "This is nginx 1.14.2 new" >nginx-1.14.2/html/index.html

#3.将nginx原先的1.12.2版本切换到1.14.2(软链接方式)
[root@xmh application]# rm -rf ./nginx && ln -s ./nginx-1.14.2 ./nginx && ./nginx-1.12.2/sbin/nginx -s stop && ./nginx/sbin/nginx

[root@xmh application]# ll
lrwxrwxrwx  1 root root  14 Jan 29 11:35 nginx -> ./nginx-1.14.2 #版本切换成功
drwxr-xr-x 11 root root 151 Jan 29 11:22 nginx-1.12.2
drwxr-xr-x 11 root root 151 Jan 29 11:35 nginx-1.14.2

旧版本的nginx:
Nginx 版本快速升级切换

新版本的nginx:
Nginx 版本快速升级切换

猜你喜欢

转载自blog.51cto.com/12643266/2347525