功能
归档
291
2017 年 01 月 15 日
openstack搭建之镜像服务Glance(三)

一、实验平台:CentOS Linux release 7.3.1611 (Core)

二、openstack版本:Mitake

三、本机所有IP:内网:192.168.1.2 192.168.1.3

外网:192.168.2.4 192.168.2.5

四、openstack1:192.168.1.2 #控制节点 1 处理器, 4 GB 内存, 及20 GB 存储

五、openstack2:192.168.1.3 #计算节点 1 处理器, 2 GB 内存, 及20 GB 存储



一、镜像服务概览

OpenStack镜像服务是IaaS的核心服务。它接受磁盘镜像或服务器镜像API请求,和来自终端用户或OpenStack计算组件的元数据定义。它也支持包括OpenStack对象存储在内的多种类型仓库上的磁盘镜像或服务器镜像存储。

大量周期性进程运行于OpenStack镜像服务上以支持缓存。同步复制(Replication)服务保证集群中的一致性和可用性。其它周期性进程包括auditors,updaters,和reapers

OpenStack镜像服务包括以下组件: glance-api: 接收镜像API的调用,诸如镜像发现、恢复、存储。 glance-registry 存储、处理和恢复镜像的元数据,元数据包括项诸如大小和类型。 glance-registry是私有内部服务,用于服务OpenStack Image服务。不要向用户暴露该服务

数据库 存放镜像元数据,用户是可以依据个人喜好选择数据库的,多数的部署使用MySQLSQLite

镜像文件的存储仓库 支持多种类型的仓库,它们有普通文件系统对象存储RADOS块设备HTTP、以及亚马逊S3。记住,其中一些仓库仅支持只读方式使用。

元数据定义服务 通用的API,是用于为厂商管理员服务,以及用户自定义元数据。这种元数据可用于不同的资源,例如镜像,工件,卷,配额以及集合。一个定义包括了新属性的键,描述,约束以及可以与之关联的资源的类型。


二、安装配置

安装和配置镜像服务之前,你必须创建创建一个数据库、服务凭证和API端点。

创建glance数据库: mysql -u root -p CREATE DATABASE glance; GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance'; GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance'; 获得admin凭证来获取只有管理员能执行的命令的访问权限: . admin-openstack.sh 要创建服务证书:完成以下步骤:

创建glance用户:

openstack user create --domain default --password-prompt glance
User Password:              #设置密码,我这里设置为glance
Repeat User Password:
+-----------+----------------------------------+
| Field     | Value                            |
+-----------+----------------------------------+
| domain_id | 563963f57f154b628814c4e1bc9d2169 |
| enabled   | True                             |
| id        | 20bb22b2a5354c09bae0ae62c9e91eed |
| name      | glance                           |
+-----------+----------------------------------+

添加admin角色到glance用户和service项目上。 openstack role add --project service --user glance admin 创建glance服务实体:

openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | f78b8a02c3bd4bf48e382a44b1aadccb |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

创建镜像服务的API端点:

openstack endpoint create --region RegionOne image public http://192.168.1.2:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 8f118e658b3f4b6a87fd23c00ef71943 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f78b8a02c3bd4bf48e382a44b1aadccb |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.1.2:9292          |
+--------------+----------------------------------+

openstack endpoint create --region RegionOne image internal http://192.168.1.2:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | e90965d9bb10454c82b9767919fac746 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f78b8a02c3bd4bf48e382a44b1aadccb |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.1.2:9292          |
+--------------+----------------------------------+

openstack endpoint create --region RegionOne image admin http://192.168.1.2:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | c36c34d52a354940ad2459a726057a22 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f78b8a02c3bd4bf48e382a44b1aadccb |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.1.2:9292          |
+--------------+----------------------------------+

安装软件包:

yum -y install openstack-glance

编辑文件/etc/glance/glance-api.conf

vim /etc/glance/glance-api.conf

[database]
connection = mysql+pymysql://glance:glance@192.168.1.2/glance       #配置数据库访问

[keystone_authtoken]                                                #配置认证服务访问
auth_uri = http://192.168.1.2:5000
auth_url = http://192.168.1.2:35357
memcached_servers = 192.168.1.2:11211
auth_type = password                    #验证类型为密码
project_domain_name = default           #默认域
user_domain_name = default              #用户默认域
project_name = service                  #项目名称
username = glance                       #用户
password = glance                       #密码

[paste_deploy]
flavor = keystone

[glance_store]              #配置本地文件系统存储和镜像文件位置
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

编辑文件/etc/glance/glance-registry.conf 设置registry,和api的设置基本一样

vim /etc/glance/glance-registry.conf

[database]
connection = mysql+pymysql://glance:glance@192.168.1.2/glance       #配置数据库访问

[keystone_authtoken]                                                #配置认证服务访问
auth_uri = http://192.168.1.2:5000
auth_url = http://192.168.1.2:35357
memcached_servers = 192.168.1.2:11211
auth_type = password                    #验证类型为密码
project_domain_name = default           #默认域
user_domain_name = default              #用户默认域
project_name = service                  #项目名称
username = glance                       #用户
password = glance                       #密码

[paste_deploy]
flavor = keystone

写入镜像服务数据库:

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:1056: 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`. This is deprecated and will be disallowed in a future release.')
  result = self._query(query)
#替我们去创建表结构,openstack有警告没有关系,只要不是error就可以

同步完数据库之后我们进行检查

mysql -h 192.168.1.2 -u glance -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                            |
+----------------------------------+

启动镜像服务、配置他们随机启动:

systemctl enable openstack-glance-api.service openstack-glance-registry.service
systemctl start openstack-glance-api.service openstack-glance-registry.service
#glance-api的端口是9292,glance-registry的端口是9191

三、验证

获得admin凭证来获取只有管理员能执行的命令的访问权限:

. admin-openstack.sh

下载源镜像:

wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
#如果您的发行版里没有包含wget,请安装它
yum -y install wget

创建镜像

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-07-17T08:14:24Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/db5d11d7-0006-4b14-a5d5-71b18a41eb85/file |
| id               | db5d11d7-0006-4b14-a5d5-71b18a41eb85                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | db84902f7b1a4553a97684f210395abe                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13287936                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2017-07-17T08:14:25Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+
--file      #镜像要在当前目录
命令完成后会将镜像存放在/var/lib/glance/images下
ls /var/lib/glance/images/
db5d11d7-0006-4b14-a5d5-71b18a41eb85

确认镜像的上传并验证属性:

openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| db5d11d7-0006-4b14-a5d5-71b18a41eb85 | cirros | active |
+--------------------------------------+--------+--------+

Over~

留言
Loading...

发表评论

电子邮件地址不会被公开。 必填项已用*标注