制作的windows鏡像至少10G以上,通過命令行上傳(實際走的還是http通訊)服務(wù)器經(jīng)常返回502。

大size鏡像上傳失敗
經(jīng)驗證,通過本文介紹的方式可以輕松上傳大鏡像。
首先創(chuàng)建一個dummy文件(0 byte)
# touch dummy
# ll
total 17370224
drwxr-xr-x 2 root root 4096 Jan 5 11:43 ./
drwxr-xr-x 3 root root 4096 Dec 26 16:34 ../
-rw-r--r-- 1 root root 0 Jan 5 11:43 dummy
然后把dummy文件作為鏡像的raw data上傳(秒速)
glance image-create --architecture "x86_64" --protected true --os-version 2012 --os-distro windows --property os_type=windows --name "Windows Server 2012 Standard and Datacenter" --visibility public --disk-format qcow2 --container-format bare --file dummy
查詢image id
# glance image-list
+--------------------------------------+---------------------------------------------+
| ID | Name |
+--------------------------------------+---------------------------------------------+
| 0d30d276-2c3b-4c2e-9596-cdd42bef47dd | amphora-x64-haproxy |
| 72f136f3-ae80-4ec5-83d4-c70278b1a70e | CentOS7 |
| 6868a2f7-9c2d-4788-b06e-44aebcffe925 | cirros-0.4.0-x86_64-disk |
| 04239a5b-b4fe-4a83-9605-4b70c06595fb | Ubuntu 16.04 Server |
| a1a012c3-9a62-40b2-8c6a-cd3b69db068d | Windows Server 2012 Standard and Datacenter |
+--------------------------------------+---------------------------------------------+
找到glance存放image的地方
# vim /etc/glance/glance-api.conf
...
[glance_store]
filesystem_store_datadir = /opt/stack/data/glance/images/
...
# cd /opt/stack/data/glance/images
:/opt/stack/data/glance/images# ll
total 1833064
drwxr-xr-x 2 stack stack 4096 Jan 5 11:43 ./
drwxr-xr-x 5 stack stack 4096 Jan 3 19:26 ../
-rw-r--r-- 1 stack stack 289472512 Jan 4 14:03 04239a5b-b4fe-4a83-9605-4b70c06595fb
-rw-r--r-- 1 stack stack 698107392 Jan 3 19:37 0d30d276-2c3b-4c2e-9596-cdd42bef47dd
-rw-r--r-- 1 stack stack 12716032 Jan 3 19:26 6868a2f7-9c2d-4788-b06e-44aebcffe925
-rw-r--r-- 1 stack stack 876740608 Jan 5 11:33 72f136f3-ae80-4ec5-83d4-c70278b1a70e
-rw-r--r-- 1 stack stack 0 Jan 5 11:43 a1a012c3-9a62-40b2-8c6a-cd3b69db068d
然后把真正的鏡像文件copy覆蓋a1a012c3-9a62-40b2-8c6a-cd3b69db068d這個文件
/opt/stack/data/glance/images# cp ~/images/var/lib/libvirt/images/ws2k12stddc.qcow2 a1a012c3-9a62-40b2-8c6a-cd3b69db068d
/opt/stack/data/glance/images# ll
total 15466860
drwxr-xr-x 2 stack stack 4096 Jan 5 11:43 ./
drwxr-xr-x 5 stack stack 4096 Jan 3 19:26 ../
-rw-r--r-- 1 stack stack 289472512 Jan 4 14:03 04239a5b-b4fe-4a83-9605-4b70c06595fb
-rw-r--r-- 1 stack stack 698107392 Jan 3 19:37 0d30d276-2c3b-4c2e-9596-cdd42bef47dd
-rw-r--r-- 1 stack stack 12716032 Jan 3 19:26 6868a2f7-9c2d-4788-b06e-44aebcffe925
-rw-r--r-- 1 stack stack 876740608 Jan 5 11:33 72f136f3-ae80-4ec5-83d4-c70278b1a70e
-rw-r--r-- 1 stack stack 13961003008 Jan 5 13:03 a1a012c3-9a62-40b2-8c6a-cd3b69db068d
到這里應(yīng)該可以使用了。
接下來的問題目前應(yīng)該不影響使用鏡像。
由于上傳dummy時,glance計算了size和md5sum并保存數(shù)據(jù)庫了,很顯然不同于真正的鏡像的計算結(jié)果。
可以通過直接修改數(shù)據(jù)的方式改過來
# mysql -u root -p
Enter password:
mysql> use glance
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select id,name,size,status,checksum from images;
+--------------------------------------+---------------------------------------------+-------------+--------+----------------------------------+
| id | name | size | status | checksum |
+--------------------------------------+---------------------------------------------+-------------+--------+----------------------------------+
| 04239a5b-b4fe-4a83-9605-4b70c06595fb | Ubuntu 16.04 Server | 289472512 | active | f0f51c3a52efbcdb79571971d54395ae |
| 0d30d276-2c3b-4c2e-9596-cdd42bef47dd | amphora-x64-haproxy | 698107392 | active | 3f81a1c637592c99bff9c13537da54c4 |
| 6868a2f7-9c2d-4788-b06e-44aebcffe925 | cirros-0.4.0-x86_64-disk | 12716032 | active | 443b7623e27ecf03dc9e01ee93f67afe |
| 72f136f3-ae80-4ec5-83d4-c70278b1a70e | CentOS7 | 876740608 | active | 317ecf7d1128e0e53cb285b8704dc3d3 |
| a1a012c3-9a62-40b2-8c6a-cd3b69db068d | Windows Server 2012 Standard and Datacenter | 13961003008 | active | d4a5b24b50627b4e8bcac00a5cf6c30c |
+--------------------------------------+---------------------------------------------+-------------+--------+----------------------------------+
5 rows in set (0.00 sec)
#可以看出筆者已經(jīng)修改好了
mysql> update images set size=13961003008, checksum="d4a5b24b50627b4e8bcac00a5cf6c30c" where id="a1a012c3-9a62-40b2-8c6a-cd3b69db068d";