OpenStack:Glance原理介绍

来自CloudWiki
跳转至: 导航搜索

OpenStack 由 Glance 提供 Image 服务。

理解 Image

要理解 Image Service 先得搞清楚什么是 Image 以及为什么要用 Image?

在传统 IT 环境下,安装一个系统是要么从安装 CD 从头安装,要么用 Ghost 等克隆工具恢复。这两种方式有如下几个问题:

  • 如果要安装的系统多了效率就很低
  • 时间长,工作量大
  • 安装完还要进行手工配置,比如安装其他的软件,设置 IP 等
  • 备份和恢复系统不灵活

Openstack7-12.jpg

云环境下需要更高效的解决方案,这就是 Image。

Image 是一个模板,里面包含了基本的操作系统和其他的软件。

举例来说,有家公司需要为每位员工配置一套办公用的系统,一般需要一个 Win7 系统再加 MS office 软件。

OpenStack 是这么玩的:

  • 先手工安装好这么一个虚机
  • 然后对虚机执行 snapshot,这样就得到了一个 image
  • 当有新员工入职需要办公环境时,立马启动一个或多个该 image 的 instance(虚机)就可以了

在这个过程中,第 1 步跟传统方式类似,需要手工操作和一定时间。

但第 2、3 步非常快,全自动化,一般都是秒级别。

而且 2、3 步可以循环做。

比如公司新上了一套 OA 系统,每个员工的 PC 上都得有客户端软件。

那么可以在某个员工的虚机中手工安装好 OA 客户端,然后执行 snapshot ,得到新的 image,以后就直接使用新 image 创建虚机就可以了。

另外,snapshot 还有备份的作用,能够非常方便的恢复系统。

理解 Image Service

Image Service 的功能是管理 Image,让用户能够发现、获取和保存 Image。

在 OpenStack 中,提供 Image Service 的是 Glance,其具体功能如下:

  • 查询镜像:提供 REST API 让用户能够查询和获取 image 的元数据和 image 本身
  • 存储镜像:支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3 等
  • 创建镜像:对 Instance 执行 Snapshot 创建新的 image

Glance架构

Openstack7-10.png

glance-api

glance-api 是系统后台运行的服务进程。

对外提供 REST API,响应 image 查询、获取和存储的调用。

glance-api 不会真正处理请求。

如果是与 image metadata(元数据)相关的操作,glance-api 会把请求转发给 glance-registry;

如果是与 image 自身存取相关的操作,glance-api 会把请求转发给该 image 的 store backend。

在控制节点上可以查看 glance-api 进程

[root@controller ~]# ps -e|grep glance-api

1932 ?        00:00:03 glance-api
2112 ?        00:00:02 glance-api

glance-registry

glance-registry 是系统后台运行的服务进程。

负责处理和存取 image 的 metadata,例如 image 的大小和类型。

在控制节点上可以查看 glance-registry 进程

[root@controller ~]# ps -e|grep glance-registry

2125 ?        00:00:01 glance-registry
2229 ?        00:00:03 glance-registry

Glance 支持多种格式的 image,包括

Openstack7-11.png

Database

Image 的 metadata 会保持到 database 中,默认是 MySQL。

在控制节点上可以查看 glance 的 database 信息

[root@controller ~]# sudo mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.1.71 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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> show tables;
+------------------+
| Tables_in_glance |
+------------------+
| image_locations  |
| image_members    |
| image_properties |
| image_tags       |
| images           |
| migrate_version  |
| task_info        |
| tasks            |
+------------------+
8 rows in set (0.00 sec)

mysql>

Store backend

Glance 自己并不存储 image。

真正的 image 是存放在 backend 中的。

Glance 支持多种 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 的配置可参考http://docs.openstack.org/liberty/config-reference/content/configuring-image-service-backends.html

查看目前已经存在的 image

[root@controller ~]# source admin-openrc.sh
[root@controller ~]# glance image-list
+--------------------------------------+--------------+-------------+------------------+-----------+--------+
| ID                                   | Name         | Disk Format | Container Format | Size      | Status |
+--------------------------------------+--------------+-------------+------------------+-----------+--------+
| 9d3ec99c-5360-4838-bf47-fe40b0b72436 | centos6.5    | qcow2       | bare             | 305397760 | active |
| 498ef44c-0d77-4c8f-ad1e-508c8ca858b1 | cirros       | qcow2       | bare             | 13147648  | active |
| f80d36b8-78b5-4a96-aab4-f775ca13d173 | maxin        | qcow2       | bare             | 9761280   | active |
| d9619bc6-5b6a-427d-9b87-9bca97eb4d70 | maxin_cirros | qcow2       | bare             | 9761280   | active |
+--------------------------------------+--------------+-------------+------------------+-----------+--------+

查看保存目录

 [root@controller ~]# ls -l /var/lib/glance/images
total 330152
-rw-r----- 1 glance glance  13147648 Jun 17  2015 498ef44c-0d77-4c8f-ad1e-508c8ca858b1
-rw-r----- 1 glance glance 305397760 Jun 17  2015 9d3ec99c-5360-4838-bf47-fe40b0b72436
-rw-r----- 1 glance glance   9761280 Oct 15 14:18 d9619bc6-5b6a-427d-9b87-9bca97eb4d70
-rw-r----- 1 glance glance   9761280 Oct 15 14:49 f80d36b8-78b5-4a96-aab4-f775ca13d173

每个 image 在目录下都对应有一个文件,文件以 image 的 ID 命名。

下节我们来实际操作 Glance。

参考文档:https://www.cnblogs.com/CloudMan6/p/5384923.html