[每日三问][OpenStack] Nova 虚机状态机,boot过程, suspend/pause的区别
1.OpenStack中虚机的状态机.状态转变:
指令 | VM的状态要求 | task状态的要求 | 目标状态 |
---|---|---|---|
pause | Active,shutoff,rescured | resize verify, unset | paused |
unpause | paused | N/A | Active |
suspend | Active, Shutoff | N/A | Suspended |
resume | Suspended | N/A | Active |
rescue | Active, Shutoff | Resize Verify, unset | Rescued |
unrescue | Rescued | N/A | Active |
set admin password | Active | N/A | Active |
rebuild | Active, Shutoff | Resize Verify, unset | Active, Shutoff |
force delete | Soft Deleted | N/A | Deleted |
restore | Soft Deleted | N/A | Active |
soft delete | Active, Shutoff, Error | N/A | Soft Deleted |
delete | Active, Shutoff, Building, Rescued, Error | N/A | Deleted |
backup | Active, Shutoff | N/A | Active, Shutoff |
snapshot | Active, Shutoff | N/A | Active, Shutoff |
start | Shutoff, Stopped | N/A | Active |
stop | Active, Shutoff, Rescued | Resize Verify, unset | Stopped |
reboot | Active, Shutoff, Rescued | Resize Verify, unset | Active |
resize | Active, Shutoff | Resize Verify, unset | Resized |
revert resize | Active, Shutoff | Resize Verify, unset | Active |
confirm resize | Active, Shutoff | Resize Verify, unset | Active |
- VM boot时候经历的状态:
Sequence of VM states, task states, and power states when a new VM instance is created.
创建instance- 为 instance 准备资源
nova-compute 首先会根据指定的 flavor 依次为 instance 分配内存、磁盘空间和 vCPU。 - 创建 instance 的镜像文件
nova-compute会: 1. 首先将该 image 下载到计算节点 2. 然后将其作为 backing file 创建 instance 的镜像文件。 存储在计算节点的/var/lib/nova/instances - 创建 instance 的 XML 定义文件
- 创建虚拟网络并启动虚拟机
- 为 instance 准备资源
-
VM boot时候组件之间的协同: 创建虚机的内部过程
- 客户(可以是 OpenStack 最终用户,也可以是其他程序)向 API(nova-api)发送请求:“帮我创建一个虚机”
- API 对请求做一些必要处理后,向 Messaging(RabbitMQ)发送了一条消息:“让 Scheduler 创建一个虚机”
- Scheduler 向 Messaging 发送了一条消息:“在计算节点 A 上创建这个虚机” nova-scheduler 会按照 flavor 去选择合适的计算节点
5.计算节点 A 的 Compute(nova-compute)从 Messaging 中获取到 Scheduler 发给它的消息,然后在本节点的 Hypervisor 上启动虚机。 - 在虚机创建的过程中,Compute 如果需要查询或更新数据库信息,会通过 Messaging 向 Conductor(nova-conductor)发送消息,Conductor 负责数据库访问。
-
Suspend/Pause的比较:
相同点:- 两者都是暂停 instance 的运行,并保存当前状态,之后可以通过 Resume 操作恢复。
不同点
- Suspend 将 instance 的状态保存在磁盘;Pause 是保存在内存中,所以 Resume 被 Pause 的 instance 要比 Suspend 快。
- instance 被 Suspend 后,状态为 Shut Down;而被 Pause 的 instance 状态是 Paused。
- 虽然都是通过 Resume 操作恢复,Pause 对应的 Resume 在 OpenStack 内部被叫作 “Unpause”;Suspend 对应的 Resume 才是真正的 “Resume”。这个在日志中能体现出来。