软件平滑升级

问题

平滑升级是什么?
是一种在热升级手段,在不中断服务的情况下升级软件。
为什么平滑升级呢?
因为现在软件版本功能已经无法满足上产需求,所以需要升级新的版本,来提供更好的服务。
平滑升级是则么做到的?
用新的进程,把旧的进程替换掉。
具体是咋么做到的呢?请看 案例1
出现为题是否能回滚呢?
可以,回滚流程请看 案例2

案例一:平滑升级nginx服务

实验环境

selinux:关闭状态
firewalld:关闭状态
nginx两个版本:
例如:版本为nginx-1.20.1和nginx-1.21.3
在这里插入图片描述

实验过程

先安装nginx1.20.1版本
步骤如下:

把软件解压到当前目录
[root@localhost media]# tar -xf nginx-1.20.1.tar.gz
安装编译工具
[root@localhost media]# yum -y install gcc pcre-devel zlib-devel
进入目录编译安装nginx
[root@localhost media]# cd nginx-1.20.1/
创建个用户没有家目录,并且登入环境为nologin,用来管理nginx软件
[root@localhost nginx-1.20.1]# useradd -s /usr/sbin/nologin -M nginx
[root@localhost nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --user=nginx
创建软连接,添加环境变量
[root@localhost nginx-1.20.1]# ln -s /usr/local/nginx/sbin/nginx  /usr/sbin/
启动nginx服务
[root@localhost nginx-1.20.1]# nginx
查看进程
[root@localhost media]# ps -aux| grep nginx
root      25803  0.0  0.0  20520   620 ?        Ss   18:44   0:00 nginx: master process nginx
nginx     25804  0.0  0.0  23048  1380 ?        S    18:44   0:00 nginx: worker process
root      26121  0.0  0.0 112668   968 pts/3    S+   19:15   0:00 grep --color=auto nginx

开始升级

# 把软件解压到当前目录
[root@localhost media]# tar -xf nginx-1.21.3.tar.gz
# 把软件解压到当前目录
[root@localhost media]# tar -xf nginx-1.21.3.tar.gz
# 进入目录编译安装nginx
[root@localhost media]# cd nginx-1.21.3/
# 编译安装中需要注意下,编译安装的名字不能和源文件的名称一样要不然会出现,把源文件给直接替换掉
[root@localhost nginx-1.21.3]# ./configure --prefix=/usr/local/nginx01 --user=nginx
[root@localhost nginx-1.21.3]# cd /usr/sbin
# 把原来的nginx文件名字改一下,方便升级失败回滚
[root@localhost sbin]# mv nginx nginx01
# 创建软连接,添加环境变量
[root@localhost nginx-1.21.3]# ln -s /usr/local/nginx01/sbin/nginx  /usr/sbin/
# 查看进程,查找到nginx进程编号
[root@localhost media]# ps -aux| grep nginx
root      25803  0.0  0.0  20520   620 ?        Ss   18:44   0:00 nginx: master process nginx
nginx     25804  0.0  0.0  23048  1380 ?        S    18:44   0:00 nginx: worker process
root      26121  0.0  0.0 112668   968 pts/3    S+   19:15   0:00 grep --color=auto nginx
用此命令来平滑升级
[root@localhost sbin]# kill -usr2 25803
# 现在在查看进程,多出了一个新的父进程和子进程
[root@localhost media]# ps -aux| grep nginx
root      25803  0.0  0.0  20520   804 ?        Ss   18:44   0:00 nginx: master process nginx
nginx     25804  0.0  0.0  23048  1380 ?        S    18:44   0:00 nginx: worker process
root      26202  0.0  0.0  20520  1604 ?        S    19:24   0:00 nginx: master process nginx
nginx     26203  0.0  0.0  23048  1376 ?        S    19:24   0:00 nginx: worker process
root      26205  0.0  0.0 112668   972 pts/3    S+   19:24   0:00 grep --color=auto nginx
# 从容的关掉旧的进程
[root@localhost sbin]# kill -winch 25803
[root@localhost media]# ps -aux| grep nginx
root      25803  0.0  0.0  20520   804 ?        Ss   18:44   0:00 nginx: master process nginx
root      26202  0.0  0.0  20520  1604 ?        S    19:24   0:00 nginx: master process nginx
nginx     26203  0.0  0.0  23048  1376 ?        S    19:24   0:00 nginx: worker process
root      26224  0.0  0.0 112668   972 pts/3    S+   19:27   0:00 grep --color=auto nginx
# 现在已经升级成功

注:到此位置已升级完成,没问题可以把旧的进程直接kill掉。如果出现问题在这可知执行回滚操作

回滚流程

# 开始实现回滚操作
[root@localhost sbin]# kill -hup 25803
# 旧进程再次启动
[root@localhost sbin]# ps -aux | grep nginx
root      25803  0.0  0.0  20520   804 ?        Ss   18:44   0:00 nginx: master process nginx
root      26202  0.0  0.0  20520  1604 ?        S    19:24   0:00 nginx: master process nginx
nginx     26203  0.0  0.0  23048  1376 ?        S    19:24   0:00 nginx: worker process
nginx     26330  0.0  0.0  23048  1376 ?        S    19:39   0:00 nginx: worker process
root      26332  0.0  0.0 112668   972 pts/3    S+   19:39   0:00 grep --color=auto nginx
[root@localhost media]# kill -winch 26202
[root@localhost media]# kill -9 26202
[root@localhost sbin]# ps -aux | grep nginx
root      25803  0.0  0.0  20520   804 ?        Ss   18:44   0:00 nginx: master process nginx
nginx     26203  0.0  0.0  23048  1376 ?        S    19:24   0:00 nginx: worker process 
# 回滚完成

用来平滑升级和回滚的命令

命令解释系统支持的信号编号
kill -usr2用来平滑升级12
kill -winch从容关进程28
kill -hup激活进程1

在这里插入图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值