- 爲 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.
|
|