glance image-create 由于镜像过大上传失败解决办法

制作的windows镜像至少10G以上,通过命令行上传(实际走的还是http通讯)服务器经常返回502。


glance image-create 由于镜像过大上传失败解决办法_第1张图片
大size镜像上传失败

经验证,通过本文介绍的方式可以轻松上传大镜像。
首先创建一个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

到这里应该可以使用了。
接下来的问题目前应该不影响使用镜像。
由于上传dummy时,glance计算了size和md5sum并保存数据库了,很显然不同于真正的镜像的计算结果。
可以通过直接修改数据的方式改过来

# 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)
#可以看出笔者已经修改好了
mysql> update images set size=13961003008, checksum="d4a5b24b50627b4e8bcac00a5cf6c30c" where id="a1a012c3-9a62-40b2-8c6a-cd3b69db068d";

你可能感兴趣的:(glance image-create 由于镜像过大上传失败解决办法)