preface
在上节中我们了解了keystone服务,下面就看看glance管理镜像的服务吧。
glance组成
glance有两部分组成:
- glance-api 接受云系统镜像的创建,删除,读取请求
- glance-Registry 云系统的镜像注册服务
glance-api 是接受 rest api请求的。完成诸如镜像的查找,获取,上传,删除等操作,默认是监听9292端口
glance-registry 是用于Mysql的数据交互,用户存储或获取镜像的元数据(metadata);提供镜像元数据相关的REST接口,通过glance-Registry,可以向数据库中写入或获取镜像的各种数据。glance-Registry监听的端口是9191.Glance数据库中有两种表,一张是image表,主要存储了镜像格式,大小等信息;另一张是image property表,主要存了镜像定制化信息。
image-store是一个存储的接口层,通过这个接口,glance可以获取镜像,image store支持的存储有Amazon的S3,Openstack本身的swift,还有诸如ceph,sheepdog,GluasterFS等分布式存储,image store是镜像保存与获取的接口,它仅仅是一个接口层,具体的实现需要外部的存储支持。
三种存储方式
我们从用户的使用角度来说
- 对象存储
调用restful api来存储文件的属于对象存储。 - 块存储
就像一块硬盘/磁盘/分区一样来存放东西。 - 文件存储
通过文件夹的方式来存放文件。
通过三种不同的存储方式来区别是对象、块还是文件存储
那么就动手配置它吧
我们先把基础工作做好:
- 控制节点创建数据库(前面已经完成了)
- 创建用户并赋予admin权限(前面已经完成了)
- 创建服务实体
[root@linux-node1 ~]# source admin_openrc # 用admin,不然会报错403错误
[root@linux-node1 ~]# openstack service create --name glance \
> --description "OpenStack Image" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 75791c905b92412ca4390b3970726f75 |
| name | glance |
| type | image |
+-------------+----------------------------------+
- 创建镜像服务的api端点:
[root@linux-node1 ~]# openstack endpoint create --region RegionOne image public http://192.168.56.11:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | af87e8f5eb69433884165450d75ed3c0 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 75791c905b92412ca4390b3970726f75 |
| 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 | 1f10e8ab94db40ed997e170a38b9cb2b |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 75791c905b92412ca4390b3970726f75 |
| 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 | 8dfebc8930bf4e65b8fc763b9411bf0c |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 75791c905b92412ca4390b3970726f75 |
| service_name | glance |
| service_type | image |
| url | http://192.168.56.11:9292 |
+--------------+----------------------------------+
# 检测下:
[root@linux-node1 ~]# openstack service list
+----------------------------------+----------+----------+
| ID | Name | Type |
+----------------------------------+----------+----------+
| 75791c905b92412ca4390b3970726f75 | glance | image |
| d24e9eacb30a4c9fa6d1109c856f6b11 | keystone | identity |
+----------------------------------+----------+----------+
[root@linux-node1 ~]# openstack endpoint list
| 1f10e8ab94db40ed997e170a38b9cb2b | RegionOne | glance | image | True | internal | http://192.168.56.11:9292 |
| 8dfebc8930bf4e65b8fc763b9411bf0c | RegionOne | glance | image | True | admin | http://192.168.56.11:9292 |
| af87e8f5eb69433884165450d75ed3c0 | RegionOne | glance | image | True | public | http://192.168.56.11:9292 |
5.安装glance服务
[root@linux-node1 ~]# yum install openstack-glance
6.修改数据库配置并且同步数据库
# glance-api配置文件
[root@linux-node1 openrc]# vim /etc/glance/glance-api.conf
[database]
connection = mysql+pymysql://glance:[email protected]/glance
# glance-Registry配置文件
[database]
connection = mysql+pymysql://glance:[email protected]/glance
[root@linux-node1 glance]# su -s /bin/sh -c "glance-manage db_sync" glance # 警告信息可以忽略
[root@linux-node1 glance]# mysql -uglance -h 192.168.56.11 -pglance -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 |
+----------------------------------+
7.配置keystoner认证与镜像存储地方
# api 配置文件
[root@linux-node1 glance]# vim /etc/glance/glance-api.conf
[keystone_authtoken] 添加keystone认证信息
auth_uri = http://192.168.56.11:5000
auth_url = http://192.168.56.11:35357
memcached_servers = 192.168.56.11:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
[paste_deploy] 认证方式为keyston
flavor = keystone
[glance_store] 配置本地文件系统存储和镜像文件位置:
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
# Registry配置文件
[root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
[keystone_authtoken]
auth_uri = http://192.168.56.11:5000
auth_url = http://192.168.56.11:35357
memcached_servers = 192.168.56.11:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
[paste_deploy]
flavor = keystone
8.确保无误,启动服务:
[root@linux-node1 glance]# systemctl enable openstack-glance-api.service \
> openstack-glance-registry.service
[root@linux-node1 glance]# systemctl start openstack-glance-api.service \
> openstack-glance-registry.service
9.下载镜像并检测glance服务是否正常
下载镜像
[root@linux-node1 images]# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img # 下载镜像
导入镜像到glance
[root@linux-node1 images]# source /root/admin_openrc
[root@linux-node1 images]# 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 | 2017-01-03T06:46:27Z |
| disk_format | qcow2 |
| file | /v2/images/5c242396-3c7b-4bc6-bec1-3df8eb57d53d/file |
| id | 5c242396-3c7b-4bc6-bec1-3df8eb57d53d |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 6197e636277d41ce8b0a835fbca4f87a |
| protected | False |
| schema | /v2/schemas/image |
| size | 13287936 |
| status | active |
| tags | |
| updated_at | 2017-01-03T06:46:28Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+
[root@linux-node1 images]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 5c242396-3c7b-4bc6-bec1-3df8eb57d53d | cirros | active |
+--------------------------------------+--------+--------+
10.如果能够通过openstack image list查看到刚才导入的镜像,那么就说明glance正常工作的了。