Glance 架构
glance架构.png如上图所示,Glance架构相对比较简单
Glance-api
- glance-api 对外提供RSET Api接口,响应image查询、获取和存储的调用。
- glance-api将metadata请求交给glance-register处理,将image请求交给store backend处理
Glance-registry
glance-register服务进程负责处理和存储image的元数据(metadata)信息,比如image的大小和类型等。
glance-registry.pngglance支持多种image格式,之前我们已经详细介绍,这里不再赘述。
image的metadata储存在数据库里,我们来查看一下:
[root@openstack-controller tools]# mysql -uglance -p$GLANCE_DBPASS -s glance
MariaDB [glance]> show tables;
Tables_in_glance
artifact_blob_locations
artifact_blobs
artifact_dependencies
artifact_properties
artifact_tags
artifacts
image_locations
image_members
image_properties
image_tags
images
metadef_namespace_resource_types
metadef_namespaces
metadef_objects
metadef_properties
metadef_resource_types
metadef_tags
migrate_version
task_info
tasks
MariaDB [glance]> select * from images limit 1\G
*************************** 1. row ***************************
id: 4d890feb-3c24-4425-8311-61c41a582a56
name: cirros
size: 13287936
status: active
is_public: 1
created_at: 2017-06-22 07:21:46
updated_at: 2017-06-22 07:21:48
deleted_at: NULL
deleted: 0
disk_format: qcow2
container_format: bare
checksum: ee1eca47dc88f4879d8a229cc70a07c6
owner: 471592a4281e4223b2ad578b5c9b8442
min_disk: 0
min_ram: 0
protected: 0
virtual_size: NULL
MariaDB [glance]> select * from metadef_resource_types;
id name protected created_at updated_at
1 OS::Glance::Image 1 2017-06-22 07:21:42 2017-06-22 07:21:42
2 OS::Cinder::Volume 1 2017-06-22 07:21:42 2017-06-22 07:21:42
3 OS::Nova::Flavor 1 2017-06-22 07:21:42 2017-06-22 07:21:42
4 OS::Nova::Aggregate 1 2017-06-22 07:21:42 2017-06-22 07:21:42
5 OS::Nova::Instance 1 2017-06-22 07:21:42 2017-06-22 07:21:42
Store backend
glance自身并不支持存储服务,它通过backend来调用其他存储服务来存储image,常见的backend有:
- A directory on a local file system(这是默认配置)
- GridFS
- Ceph RBD
- Amazon S3
- Sheepdog
- OpenStack Block Storage (Cinder)
- OpenStack Object Storage (Swift)
- VMware ESX
具体使用哪种 backend,是在 /etc/glance/glance-api.conf 中配置的,其他 backend 的配置可参考backend配置参考:
image.png这样我们就可以很轻易的找到image的存储位置:
# 列出image的id信息
[root@openstack-controller tools]# glance image-list
+--------------------------------------+--------+
| ID | Name |
+--------------------------------------+--------+
| 4d890feb-3c24-4425-8311-61c41a582a56 | cirros |
+--------------------------------------+--------+
# 找到image存储的位置
[root@openstack-controller tools]# ls /var/lib/glance/images/4d890feb-3c24-4425-8311-61c41a582a56
/var/lib/glance/images/4d890feb-3c24-4425-8311-61c41a582a56
[root@openstack-controller tools]# du -sh /var/lib/glance/images/4d890feb-3c24-4425-8311-61c41a582a56
13M /var/lib/glance/images/4d890feb-3c24-4425-8311-61c41a582a56
# 检查一下image的文件类型
[root@openstack-controller tools]# file /var/lib/glance/images/4d890feb-3c24-4425-8311-61c41a582a56
/var/lib/glance/images/4d890feb-3c24-4425-8311-61c41a582a56: QEMU QCOW Image (v2), 41126400 bytes
glance镜像操作实例
1. 命令行创建image
通过Dashboard创建image的流程十分简单,但是当要创建的image体积过大时,页面操作会卡住很长的一段时间,所以我们一般建议通过命令行来创建image。
# 加--progress参数显示上传进度
[root@openstack-controller tools]# glance image-create --name ubuntu-16.04 --file ubuntu-16.04-server-cloudimg-amd64-disk1.img \
--disk-format qcow2 --container-format bare --progress
[=============================>] 100%
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | b27130a877734d9ec938a63ca63c4ee7 |
| container_format | bare |
| created_at | 2017-06-30T03:03:58Z |
| disk_format | qcow2 |
| id | cafc3188-54a0-4f51-8286-0fb2b44d81f5 |
| min_disk | 0 |
| min_ram | 0 |
| name | ubuntu-16.04 |
| owner | 471592a4281e4223b2ad578b5c9b8442 |
| protected | False |
| size | 303235072 |
| status | active |
| tags | [] |
| updated_at | 2017-06-30T03:04:03Z |
| virtual_size | None |
| visibility | private |
+------------------+--------------------------------------+
# 通过上面的id找到image的上传路径
[root@openstack-controller tools]# ls /var/lib/glance/images/cafc3188-54a0-4f51-8286-0fb2b44d81f5
/var/lib/glance/images/cafc3188-54a0-4f51-8286-0fb2b44d81f5
2. 使用guestfish定制修改镜像文件
# 安装guestfish命令工具
[root@openstack-controller tools]# yum install -y libguestfs-tools
[root@openstack-compute tmp]# guestfish --rw -a ubuntu-16.04-server-cloudimg-amd64-disk1.img
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
# 必须先输入run去启动虚拟机,may take a while
><fs> run
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
# 列出image的文件系统
><fs> list-filesystems
/dev/sda1: ext4
# 无法直接操作问价系统,需要将文件系统挂载后才能操作
><fs> cat /etc/hosts
libguestfs: error: download: download_stub: you must call 'mount' first to mount the root filesystem
><fs> mount /dev/sda1 /
# 现在可以像平常一样修改文件了^_^
><fs> cat /etc/hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
# 输入exit退出完成修改
><fs> exit
3. 使用guestmount挂载并修改镜像
guestmount工具同样是libguestfs-tools提供,可以将镜像挂载到本地后进行文件修改
[root@openstack-compute tmp]# guestmount -a ubuntu-16.04-server-cloudimg-amd64-disk1.img -i --rw /mnt
[root@openstack-compute tmp]# cd /mnt/
[root@openstack-compute mnt]# ls
bin boot dev etc home initrd.img lib lib64 lost+found media mnt opt proc root run sbin snap srv sys tmp usr var vmlinuz
[root@openstack-compute mnt]# cat etc/hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
[root@openstack-compute mnt]# cd /
[root@openstack-compute /]# umount /mnt/
[root@openstack-compute /]#
网友评论