openstack由于镜像过大上传失败解决办法

制作的windows镜像至少7G以上,通过命令行上传(实际走的还是http通讯)服务器经常返回502。
502 Bad Gateway: Bad Gateway: The proxy server received an invalid: response from an upstream server.: Apache/2.4.18 (Ubuntu) Server at 192.168.18.61 Port 80 (HTTP 502)

经验证,通过以下方式可以轻松上传大镜像

1.首先创建一个dummy文件(0 byte)

cd /opt/image/
touch dummy

2.后把dummy文件作为镜像上传(秒速)

glance image-create --name win7 --file /opt/image/dummy --disk-format qcow2 --container-format bare --visibility public --progress

3.查询image id

+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | d41d8cd98f00b204e9800998ecf8427e     |
| container_format | bare                                 |
| created_at       | 2018-05-17T01:23:36Z                 |
| disk_format      | qcow2                                |
| id               | f7fbe797-184a-4c5d-ad67-67cb254539a2 |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | win7                                 |
| owner            | 3bc17302ef9f465ba390fa036a35a34e     |
| protected        | False                                |
| size             | 0                                    |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2018-05-17T01:23:37Z                 |
| virtual_size     | None                                 |
| visibility       | public                               |
+------------------+--------------------------------------+

4.找到glance存放image的地方

vi /etc/glance/glance-api.conf
[glance_store]
filesystem_store_datadir = /opt/stack/data/glance/images/

5.然后把真正的镜像文件copy覆盖f7fbe797-184a-4c5d-ad67-67cb254539a2 这个文件

cp /opt/image/win7.qcow2 f7fbe797-184a-4c5d-ad67-67cb254539a2 

6.修改size

由于上传dummy时,glance计算了size和md5sum并保存数据库了,很显然不同于真正的镜像的计算结果。
可以通过直接修改数据的方式改过来

-rw-r--r-- 1 stack stack 7836008448 May 17 09:26 f7fbe797-184a-4c5d-ad67-67cb254539a2   

把7836008448 修改到数据库

猜你喜欢

转载自my.oschina.net/xhx6616/blog/1817973