- 为 instance 准备资源
- nova-compute 首先会根据指定的 flavor 依次为 instance 分配内存、磁盘空间和 vCPU。
- 网络资源也会提前分配。
| | Jun 16 13:12:52 compute nova-compute[5666]:
DEBUG nova.compute.manager
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093] Starting instance...
{{(pid=5666) _do_build_and_run_instance /opt/stack/nova/nova/compute/manager.py:1835
|
| Jun 16 13:12:52 compute nova-compute[5666]:
DEBUG oslo_concurrency.lockutils
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
Lock "compute_resources" acquired
by "nova.compute.resource_tracker.instance_claim" :: waited 0.000s
{{(pid=5666) inner
/usr/local/lib/python2.7/dist-packages/oslo_concurrency/lockutils.py:273
|
| Jun 16 13:12:52 compute nova-compute[5666]:
DEBUG nova.compute.resource_tracker
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
Memory overhead for 512 MB instance; 0 MB
{{(pid=5666) instance_claim /opt/stack/nova/nova/compute/resource_tracker.py:202
| (ADJ) 在头顶上的;在上面的;高架的→You use overhead to indicate that something is above you or above the place that you are talking about.n. 经常费用; 经常开支; 这里指开销 | Jun 16 13:12:52 compute nova-compute[5666]:
DEBUG nova.compute.resource_tracker
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
Disk overhead for 1 GB instance; 0 GB
{{(pid=5666) instance_claim /opt/stack/nova/nova/compute/resource_tracker.py:205
|
| Jun 16 13:12:52 compute nova-compute[5666]:
DEBUG nova.compute.resource_tracker
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
CPU overhead for 1 vCPUs instance; 0 vCPU(s)
{{(pid=5666) instance_claim /opt/stack/nova/nova/compute/resource_tracker.py:208
|
| Jun 16 13:12:52 compute nova-compute[5666]:
INFO nova.compute.claims
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
Attempting claim on node compute: memory 512 MB, disk 1 GB, vcpus 1 CPU
| 创建虚拟机时选择的flavor是 | Jun 16 13:12:52 compute nova-compute[5666]:
INFO nova.compute.claims
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
Total memory: 7983 MB, used: 512.00 MB
|
| Jun 16 13:12:52 compute nova-compute[5666]:
INFO nova.compute.claims
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
memory limit not specified, defaulting to unlimited
|
| Jun 16 13:12:52 compute nova-compute[5666]:
INFO nova.compute.claims
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093] Total disk: 47 GB, used: 0.00 GB
|
| Jun 16 13:12:52 compute nova-compute[5666]:
INFO nova.compute.claims
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
disk limit not specified, defaulting to unlimited
|
| Jun 16 13:12:52 compute nova-compute[5666]:
INFO nova.compute.claims
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093] Total vcpu: 4 VCPU, used: 0.00 VCPU
| 4VCPU是因为该日志是在公司开发环境搭建的2节点devstack上产生的,每台机器VCPU数量为4 | Jun 16 13:12:52 compute nova-compute[5666]:
INFO nova.compute.claims
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
vcpu limit not specified, defaulting to unlimited
|
| Jun 16 13:12:52 compute nova-compute[5666]:
DEBUG nova.virt.hardware
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
Require both a host and instance NUMA topology to fit instance on host.
{{(pid=5666) numa_fit_instance_to_host /opt/stack/nova/nova/virt/hardware.py:1465
|
| Jun 16 13:12:52 compute nova-compute[5666]:
INFO nova.compute.claims
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093] Claim successful on node compute | 网络资源也会提前分配。
| Jun 16 13:12:53 compute nova-compute[5666]:
DEBUG nova.compute.manager
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
Allocating IP information in the background.
{{(pid=5666) _allocate_network_async /opt/stack/nova/nova/compute/manager.py:1423 |
|
- 创建 instance 的镜像文件
首先将该 image 下载到计算节点,然后将其作为 backing file 创建 instance 的镜像文件。
- 从 Glance 下载 image
- 资源准备好之后,nova-compute 会为 instance 创建镜像文件。OpenStack 启动一个 instance 时,会选择一个 image,这个 image 由 Glance 管理。
| |
- nova-compute 首先会检查 image 是否已经下载(比如之前已经创建过基于相同 image 的 instance)。如果没有,就从 Glance 下载 image 到本地。由此可知,如果计算节点上要运行多个相同 image 的 instance,只会在启动第一个 instance 的时候从 Glance 下载 image,后面的 instance 启动速度就大大加快了。
| |
- 日志分析:
- image(ID为 f0bdf0e7-ebb5-459d-a7a5-a0f0ed13d6d7)是 qcow2 格式,nova-compute 将其下载。Nova 默认会通过 qemu-img 转换成 raw 格式,以提高 IO 性能。
- 下载的image 的存放目录是 /opt/stack/data/nova/instances/_base,这是由/etc/nova/nova.conf 的两个配置选项决定的
| [DEFAULT]
...
instances_path = /opt/stack/data/nova/instances
base_dir_name = _base
... |
- 下载的 image 文件被命名为 6eb03a619bcf59de5a27bf520cf83606bf8327a7,这是 image id 的 SHA1 哈希值Secure Hash Algorithm
| | Jun 16 13:12:55 compute nova-compute[5666]:
DEBUG nova.virt.images
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
f0bdf0e7-ebb5-459d-a7a5-a0f0ed13d6d7 was qcow2, converting to raw
{{(pid=5666) fetch_to_raw /opt/stack/nova/nova/virt/images.py:179 |
| Jun 16 13:12:55 compute nova-compute[5666]:
DEBUG nova.utils
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
Path '/opt/stack/data/nova/instances' supports direct I/O
{{(pid=5666) supports_direct_io /opt/stack/nova/nova/utils.py:1394 |
| Jun 16 13:12:55 compute nova-compute[5666]:
DEBUG oslo_concurrency.processutils
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
Running cmd (subprocess): qemu-img convert -t none -O raw -f qcow2
/opt/stack/data/nova/instances/_base/6eb03a619bcf59de5a27bf520cf83606bf8327a7.part
/opt/stack/data/nova/instances/_base/6eb03a619bcf59de5a27bf520cf83606bf8327a7.converted
{{(pid=5666) execute /usr/local/lib/python2.7/dist-packages/oslo_concurrency/processutils.py:372 | -O:output format;-f:format;-t:cache
backing file的id不一样是因为这条是我后来添加的笔记(又一个实例) |
- 为 instance 创建镜像文件
- 有了 下载的image 之后,instance 的镜像文件直接通过 qemu-img 命令创建,backing file 就是下载的 image。
- 这里 instance 的镜像文件是 /opt/stack/data/nova/instances/86f71e87-4ae2-48fb-9bcd-c72e3c28e093/disk,格式为 qcow2,其中 86f71e87-4ae2-48fb-9bcd-c72e3c28e093就是 instance的 id。可以通过 qume-info 查看 disk 文件的属性
| | Jun 16 13:12:57 compute nova-compute[5666]:
DEBUG oslo_concurrency.processutils
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
Running cmd (subprocess): qemu-img create -f qcow2 -o
backing_file=/opt/stack/data/nova/instances/_base/6eb03a619bcf59de5a27bf520cf83606bf8327a7
/opt/stack/data/nova/instances/86f71e87-4ae2-48fb-9bcd-c72e3c28e093/disk
{{(pid=5666) execute /usr/local/lib/python2.7/dist-packages/oslo_concurrency/processutils.py:372 | -o:options
1
2
3
4
5
6
7
8
9
10
11
12 | root@compute:~# qemu-img info /opt/stack/data/nova/instances/86f71e87-4ae2-48fb-9bcd-c72e3c28e093/disk
image: /opt/stack/data/nova/instances/86f71e87-4ae2-48fb-9bcd-c72e3c28e093/disk
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 1.9M
cluster_size: 65536
backing file: /opt/stack/data/nova/instances/_base/6eb03a619bcf59de5a27bf520cf83606bf8327a7
Format specific information:
compat: 1.1
lazy refcounts: false
refcount bits: 16
corrupt: false |
|
- 说明:
- image,指的是 Glance 上保存的镜像,作为 instance 运行的模板。 计算节点将下载的 image 存放在 /opt/stack/data/nova/instances/_base 目录下。
- 镜像文件,指的是 instance 启动盘所对应的文件
- 二者的关系是:image 是镜像文件 的 backing file。image 不会变,而镜像文件会发生变化。比如安装新的软件后,镜像文件会变大。
- 英文中两者都叫 “image”,为避免混淆,我们用 “image” 和 “镜像文件” 作区分。
| |
- 创建 instance 的 XML 定义文件
- cloudman:创建的 XML 文件会保存到该 instance 目录 /opt/stack/data/nova/instances/f1e22596-6844-4d7a-84a3-e41e6d7618ef,命名为 libvirt.xml
- 我:在/opt/stack/data/nova/instances/86f71e87-4ae2-48fb-9bcd-c72e3c28e093/没有找到.xml这个文件
- 但是在计算节点的/etc/libvirt/qemu/发现xml文件,该文件记录了虚机的各种参数
| cloudman:
我的: 日志中关于xml的有:
| DEBUG nova.virt.libvirt.driver
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
Start _get_guest_xml network_info=[...
|
| DEBUG nova.virt.libvirt.driver
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
End _get_guest_xml ... | 这个过程应该是获取xml文件吧,然后正式启动创建过程
| root@compute:~# ll /opt/stack/data/nova/instances/86f71e87-4ae2-48fb-9bcd-c72e3c28e093/
total 2052
drwxr-xr-x 2 stack libvirt 4096 Jun 16 13:12 ./
drwxr-xr-x 5 stack root 4096 Jun 16 13:12 ../
-rw------- 1 root root 48807 Jun 16 15:23 console.log
-rw-r--r-- 1 root root 2097152 Jun 16 15:23 disk
-rw-r--r-- 1 stack libvirt 86 Jun 16 13:12 disk.info |
|
- 创建虚拟网络并启动 instance
- 创建虚拟网络:用的是 linux-bridge 实现的虚拟网络
- cloudman:为 instance 创建虚拟网络设备
- 我:没有找到Ensuring bridge
| cloudman:
vif是virtual interface(虚拟网卡)的缩写 我:
| Jun 16 13:12:57 compute nova-compute[5666]:
DEBUG nova.network.base_api
[None req-d9a23179-e16d-4016-9586-e68c3dfdf6a9 admin admin]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
Updating instance_info_cache with network_info:
[{"profile": {}, ... "network": {"bridge": "brq4f28b3ec-cc",
"subnets": [{"ips": [{"meta": {}, "version": 4, ... "address": "172.12.12.7"}],
"version": 4, "meta": {"dhcp_server": "172.12.12.2"}, ... "cidr": "172.12.12.0/24", ...
{{(pid=5666) update_instance_cache_with_nw_info /opt/stack/nova/nova/network/base_api.py:48 | 虽然没有Ensuring bridge,但是有nova.virt.libvirt.vif参考见07.计算Nova→3.通过场景学习nova→4.Start Instance。总之,上述过程表示网络相关 |
- 接下来可以启动 instance了,最后Instance spawned successfully表示实例成功孵化。
- OpenStack 图形界面和 KVM CLI 都可以查看到 instance 的运行状态。
1.virsh list用于显示当前节点创建的实例,而不是像nova list似的显示所有节点创建的实例 2.由于是第一次创建实例,故Name是...1
| | Jun 16 13:13:01 compute nova-compute[5666]:
INFO nova.compute.manager [-]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093] VM Started (Lifecycle Event)
|
| Jun 16 13:13:01 compute nova-compute[5666]:
INFO nova.compute.manager
[None req-9b9e116b-fa49-46b3-8c41-9bade624c334 None None]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093] VM Paused (Lifecycle Event)
|
| Jun 16 13:13:01 compute nova-compute[5666]:
INFO nova.compute.manager
[None req-9b9e116b-fa49-46b3-8c41-9bade624c334 None None]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093]
During sync_power_state the instance has a pending task (spawning). Skip.
| 同步电源状态
| Jun 16 13:13:01 compute nova-compute[5666]:
INFO nova.compute.manager
[None req-9b9e116b-fa49-46b3-8c41-9bade624c334 None None]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093] VM Resumed (Lifecycle Event)
|
resume [rɪ'zjum](V-ERG) (使)重新开始;(使)继续进行
| Jun 16 13:13:01 compute nova-compute[5666]:
INFO nova.virt.libvirt.driver [-]
[instance: 86f71e87-4ae2-48fb-9bcd-c72e3c28e093] Instance spawned successfully.
|
|