一、Glance介绍:
1.1 glance主要是由三部分组成:
glance-api:接收云系统镜像的创建,删除,读取请求,类似nova-api,通过其他模块(glance-registry及image store)来完成诸如镜像的查找、获取、上传、删除等操作,api监听端口9292。
glance-registry:云系统的镜像注册服务,用于与mysql数据库交互,存储或获取镜像的元数据(metadata);提供镜像元数据相关的REST接口,通过glance-registry,可以向数据库中写入或获取镜像各种数据,glance-registry监听端口9191,glance数据库中有两张表,一张是image表,另一张是image property表。image表保存了镜像格式、大小等信息;image property表则主要保存镜像的定制化信息。
imagestore:是一个存储的接口层,通过这个接口,glance可以获取镜像,image store支持的存储有Amazon的S3、Openstack本身的Swift还有注入ceph,sheepdog,GFS等分布式存储。image store是镜像保存与获取的接口,它仅仅是一个接口层,具体的实现需要外部的存储支持
二、Glance配置
2.1 项目以及端点配置
2.1.1 创建glance镜像服务
1
2
3
4
5
6
7
8
9
10
|
[root@linux-node1 ~]
# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
|
id
| be8d1f87ce294817acb351f03f5ef4e3 |
| name | glance |
|
type
| image |
+-------------+----------------------------------+
|
2.1.2 创建镜像服务API端点,一般需要创建三个(public,internal,admin)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
[root@linux-node1 ~]
# openstack endpoint create --region RegionOne image public http://192.168.56.11:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
|
id
| f060541cb88741b79bbd4f3e3e44aa0d |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | be8d1f87ce294817acb351f03f5ef4e3 |
| service_name | glance |
| service_type | image |
| url | http:
//192
.168.56.11:9292 |
+--------------+----------------------------------+
[root@linux-node1 ~]
# openstack endpoint create --region RegionOne image internal http://192.168.56.11:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
|
id
| dcd57aa6f23e4cc085540a47d399c6cb |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | be8d1f87ce294817acb351f03f5ef4e3 |
| service_name | glance |
| service_type | image |
| url | http:
//192
.168.56.11:9292 |
+--------------+----------------------------------+
[root@linux-node1 ~]
# openstack endpoint create --region RegionOne image admin http://192.168.56.11:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
|
id
| cfb42dc406cc4a7ba19105c6886b2aa6 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | be8d1f87ce294817acb351f03f5ef4e3 |
| service_name | glance |
| service_type | image |
| url | http:
//192
.168.56.11:9292 |
+--------------+----------------------------------+
|
2.1.3 服务列表的查看
2.2 连接数据配置
1
2
3
4
|
[root@linux-node1 ~]
# vim /etc/glance/glance-api.conf #glance-api配置->
1748 connection =mysql+pymysql:
//glance
:glance@192.168.56.11
/glance
[root@linux-node1 ~]
# vim/etc/glance/glance-registry.conf #registry配置
1038 connection = mysql+pymysql:
//glance
:glance@192.168.56.11
/glance
|
2.2.1 初始化同步到数据库
1
2
3
4
5
6
7
|
警告可以忽略
[root@linux-node1 ~]
# su -s /bin/sh -c "glance-manage db_sync" glance
Option
"verbose"
from group
"DEFAULT"
is deprecated
for
removal. Its value may be silently ignored
in
the future.
/usr/lib/python2
.7
/site-packages/oslo_db/sqlalchemy/enginefacade
.py:1171: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade
expire_on_commit=expire_on_commit, _conf=conf)
/usr/lib/python2
.7
/site-packages/pymysql/cursors
.py:166: Warning: (1831, u
"Duplicate index 'ix_image_properties_image_id_name' defined on the table 'glance.image_properties'. This is deprecated and will be disallowed in a future release."
)
result = self._query(query)
|
2.2.2 数据库检查验证
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
[root@linux-node1 ~]
# mysql -uglance -pglance -h192.168.56.11 -e "use 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 |
+-----------
|
2.3 连接keystone配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@linux-node1 ~]
# vim /etc/glance/glance-api.conf
3178 [keystone_authtoken] 下面添加
#连接keystone配置
3179 auth_uri = http:
//192
.168.56.11:5000
#url地址
3180 auth_url = http:
//192
.168.56.11:35357
3181 memcached_servers = 192.168.56.11:11211
#memcached地址
3182 auth_type = password
3183 project_domain_name = default
3184 user_domain_name = default
3185 project_name = service
3186 username = glance
3187 password = glance
打开3990 flavor = keystone的注释
#配置认证服务访问
打开1864 stores =
file
,http的注释
# 配置本地文件系统和镜像存储位置
打开1896 default_store =
file
的注释
#默认存储文件类型
打开2196 filesystem_store_datadir =
/var/lib/glance/images
的注释
#默认镜像存储位置
|
编辑glance-registry配置文件
1
2
3
4
5
6
7
8
9
10
11
12
|
vim
/etc/glance/glance-registry
.conf
1127 [keystone_authtoken] 下面添加
1128 auth_uri = http:
//192
.168.56.11:5000
1129 auth_url = http:
//192
.168.56.11:35357
1130 memcached_servers = 192.168.56.11:11211
1131 auth_type = password
1132 project_domain_name = default
1133 user_domain_name = default
1134 project_name = service
1135 username = glance
1136 password = glance
打开 1910 flavor = keystone 注释
|
2.4 启动服务
1
2
3
4
5
|
[root@linux-node1 ~]# systemctl enableopenstack-glance-api.service \
openstack-glance-registry.service
[root@linux-node1 ~]# systemctl startopenstack-glance-api.service \
openstack-glance-registry.service
2.4.1 端口查看
|
2.5 上传镜像
注: 把镜像放到任意目录下,执行以下命令,进入那个目录,否则要加绝对路径
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@linux-node1 ~]
# openstack image create "cirros" --file cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --public
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | ee1eca47dc88f4879d8a229cc70a07c6 |
| container_format | bare |
| created_at | 2016-12-27T17:55:14Z |
| disk_format | qcow2 |
|
file
|
/v2/images/63d8947e-5224-40b6-92e5-8c939e75d45e/file
|
|
id
| 63d8947e-5224-40b6-92e5-8c939e75d45e |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 7ae0fb7deb5342d885a07c2c890a1ff4 |
| protected | False |
| schema |
/v2/schemas/image
|
| size | 13287936 |
| status | active |
| tags | |
| updated_at | 2016-12-27T17:55:15Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
|
检查上传结果
1
2
3
4
5
6
|
[root@linux-node1 ~]
# openstack image list #老版本的使用命令glance image-list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 63d8947e-5224-40b6-92e5-8c939e75d45e | cirros | active |
+--------------------------------------+--------+--------+
|
本文转自 kesungang 51CTO博客,原文链接:http://blog.51cto.com/sgk2011/1887253,如需转载请自行联系原作者