1.镜像服务概览
OpenStack镜像服务是IaaS的核心服务,如同 :ref:`get_started_conceptual_architecture`所示。它接受磁盘镜像或服务器镜像API请求,和来自终端用户或OpenStack计算组件的元数据定义。它也支持包括OpenStack对象存储在内的多种类型仓库上的磁盘镜像或服务器镜像存储。
大量周期性进程运行于OpenStack镜像服务上以支持缓存。同步复制(Replication)服务保证集群中的一致性和可用性。其它周期性进程包括auditors, updaters, 和 reapers。
OpenStack镜像服务包括以下组件:
- glance-api
-
接收镜像API的调用,诸如镜像发现、恢复、存储。
- glance-registry
-
存储、处理和恢复镜像的元数据,元数据包括项诸如大小和类型。
数据库
- 存放镜像元数据,用户是可以依据个人喜好选择数据库的,多数的部署使用MySQL或SQLite。
镜像文件的存储仓库
- 支持多种类型的仓库,它们有普通文件系统、对象存储、RADOS块设备、HTTP、以及亚马逊S3。记住,其中一些仓库仅支持只读方式使用。
元数据定义服务
- 通用的API,是用于为厂商,管理员,服务,以及用户自定义元数据。这种元数据可用于不同的资源,例如镜像,工件,卷,配额以及集合。一个定义包括了新属性的键,描述,约束以及可以与之关联的资源的类型。
2.安装和配置
这个部分描述如何在控制节点上安装和配置镜像服务,即 glance。简单来说,这个配置将镜像保存在本地文件系统中。
2.1先决条件
安装和配置镜像服务之前,你必须新创建一个数据库、服务凭证和API端点。
1)完成下面的步骤以创建数据库:
- 用数据库连接客户端以 root 用户连接到数据库服务器:
[root@controller ~]# mysql -uroot -p123456
- 创建 glance 数据库:
MariaDB [(none)]> CREATE DATABASE glance;
- 对“glance“数据库授予恰当的权限:
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \ IDENTIFIED BY 'GLANCE_DBPASS'; GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \ IDENTIFIED BY 'GLANCE_DBPASS';
用一个合适的密码替换 GLANCE_DBPASS。
- 退出数据库客户端。
2)获得 admin 凭证来获取只有管理员能执行的命令的访问权限:
[root@controller ~]# source admin-openrc
3)创建服务证书,如下步骤:
- 创建 glance 用户:
[root@controller ~]# openstack user create --domain default --password GLANCE_PASS glance
+-----------+----------------------------------+
| Field | Value |
+-----------+----------------------------------+
| domain_id | 30c495cbb6e145cd9e70ffb825c0c710 |
| enabled | True |
| id | 82cbea912a644fd78977c89bcf76988a |
| name | glance |
+-----------+----------------------------------+
- 添加 admin 角色到 glance 用户和 service 项目上。
[root@controller ~]# openstack role add --project service --user glance admin
- 创建“glance“服务实体:
[root@controller ~]# openstack service create --name glance \ --description "OpenStack Image" image +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | 3da8ad2eb4924f6690da54a54d20ed47 | | name | glance | | type | image | +-------------+----------------------------------+
4)创建镜像服务的 API 端点:
[root@controller ~]# openstack endpoint create --region RegionOne \ image public http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | ccd726240ec3491d9955724aefade07b | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | 3da8ad2eb4924f6690da54a54d20ed47 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+ [root@controller ~]# openstack endpoint create --region RegionOne \ image internal http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | d0cb9d0f5b2f45e2a45978fb693ce233 | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | 3da8ad2eb4924f6690da54a54d20ed47 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+ [root@controller ~]# openstack endpoint create --region RegionOne \ image admin http://controller:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 5fc6280579e648bc80eda2ce9374f79b | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | 3da8ad2eb4924f6690da54a54d20ed47 | | service_name | glance | | service_type | image | | url | http://controller:9292 | +--------------+----------------------------------+
3.安装并配置组件
注解说明: 默认配置文件在各发行版本中可能不同。你可能需要添加这些部分,选项而不是修改已经存在的部分和选项。另外,在配置片段中的省略号 (...)表示默认的配置选项你应该保留。
1)安装软件包:
[root@controller ~]# yum install openstack-glance -y
2)编辑文件/etc/glance/glance-api.conf
并完成如下动作:
cp /etc/glance/glance-api.conf{,.bak} grep '^\[' /etc/glance/glance-api.conf.bak >/etc/glance/glance-api.conf
-
在
[database]
部分,配置数据库访问:
[database] ... connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
将“GLANCE_DBPASS“ 替换为你为镜像服务选择的密码。
- 在
[keystone_authtoken] 和 [paste_deploy]
部分,配置认证服务访问:
[keystone_authtoken] ... auth_uri = http://controller:5000 auth_url = http://controller:35357 memcached_servers = controller:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = GLANCE_PASS [paste_deploy] ... flavor = keystone
将 GLANCE_PASS 替换为你为认证服务中你为 glance 用户选择的密码。
- 在 [glance_store] 部分,配置本地文件系统存储和镜像文件位置:
[glance_store]
...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
- MD5值如下
[root@controller ~]# md5sum /etc/glance/glance-api.conf
3e1a4234c133eda11b413788e001cba3 /etc/glance/glance-api.conf
- 文件
/etc/glance/glance-api.conf
的内容如下:
[root@controller ~]# cat /etc/glance/glance-api.conf [DEFAULT] [cors] [cors.subdomain] [database] connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance [glance_store] stores = file,http default_store = file filesystem_store_datadir = /var/lib/glance/images/ [image_format] [keystone_authtoken] auth_uri = http://controller:5000 auth_url = http://controller:35357 memcached_servers = controller:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = GLANCE_PASS [matchmaker_redis] [oslo_concurrency] [oslo_messaging_amqp] [oslo_messaging_notifications] [oslo_messaging_rabbit] [oslo_policy] [paste_deploy] flavor = keystone [profiler] [store_type_location_strategy] [task] [taskflow_executor]
3)编辑文件 “/etc/glance/glance-registry.conf“并完成如下动作:
cp /etc/glance/glance-registry.conf{,.bak} grep '^\[' /etc/glance/glance-registry.conf.bak >/etc/glance/glance-registry.conf vim /etc/glance/glance-registry.conf
在 [database]
部分,配置数据库访问:
[database] ... connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
将“GLANCE_DBPASS“ 替换为你为镜像服务选择的密码。
- 在
[keystone_authtoken]
和[paste_deploy]
部分,配置认证服务访问:
[keystone_authtoken] ... auth_uri = http://controller:5000 auth_url = http://controller:35357 memcached_servers = controller:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = GLANCE_PASS [paste_deploy] ... flavor = keystone
将 GLANCE_PASS 替换为你为认证服务中你为 glance 用户选择的密码。
- MD5值 如下:
[root@controller ~]# md5sum /etc/glance/glance-registry.conf
46acabd81a65b924256f56fe34d90b8f /etc/glance/glance-registry.conf
- 文件 “
/etc/glance/glance-registry.conf
“内容如下:
[root@controller ~]# cat /etc/glance/glance-registry.conf [DEFAULT] [database] connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance [glance_store] [keystone_authtoken] auth_uri = http://controller:5000 auth_url = http://controller:35357 memcached_servers = controller:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = glance password = GLANCE_PASS [matchmaker_redis] [oslo_messaging_amqp] [oslo_messaging_notifications] [oslo_messaging_rabbit] [oslo_policy] [paste_deploy] flavor = keystone [profiler]
4)写入镜像服务数据库;同步数据库:
[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance
#注解说明:
忽略输出中任何不推荐使用的信息。
- 初始化后进行验证
[root@controller ~]# mysql -uroot -p123456 -e "use glance;show tables;"|wc -l 21
3.完成安装
3.1启动镜像服务、配置他们随机启动:
启动镜像服务,并将其配置启动系统时启动,api端口9292
、registry端口9191
~]# systemctl enable openstack-glance-api.service \ openstack-glance-registry.service ~]# systemctl start openstack-glance-api.service \ openstack-glance-registry.service #检测启动的端口 [root@controller ~]# netstat -lntp|grep "9292" tcp 0 0 0.0.0.0:9292 0.0.0.0:* LISTEN 27138/python2
3.2验证操作
使用 `CirrOS <http://launchpad.net/cirros>`__对镜像服务进行验证,CirrOS是一个小型的Linux镜像可以用来帮助你进行 OpenStack部署测试。
注解说明: 在控制节点上执行这些命令。
1)获得 admin 凭证来获取只有管理员能执行的命令的访问权限:
[root@controller ~]# source admin-openrc
2)下载源镜像:
[root@controller ~]# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
#如果上面的镜像访问不了,可以使用下面这个
https://launchpadlibrarian.net/83305348/cirros-0.3.0-x86_64-disk.img
3)使用 QCOW2 磁盘格式, bare 容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它
[root@controller ~]# 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 | 2018-07-17T02:44:51Z | | disk_format | qcow2 | | file | /v2/images/3c354a84-68ef-4123-aa78-a7cde30279e5/file | | id | 3c354a84-68ef-4123-aa78-a7cde30279e5 | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | 61cd0cf561bb47fdbfc903f6fb53e623 | | protected | False | | schema | /v2/schemas/image | | size | 13287936 | | status | active | | tags | | | updated_at | 2018-07-17T02:44:53Z | | virtual_size | None | | visibility | public | +------------------+------------------------------------------------------+
4)确认镜像的上传并验证属性
[root@controller ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 3c354a84-68ef-4123-aa78-a7cde30279e5 | cirros | active |
+--------------------------------------+--------+--------+
#注解说明:
OpenStack 是动态生成 ID 的,因此您看到的输出可能会与示例中的命令行输出不相同
Get busy living or get busy dying. 努力活出精彩的人生,否则便如行尸走肉
- 转载请注明来源:OpenStack系列三之镜像服务Glance
- 本文永久链接地址:https://www.xionghaier.cn/archives/520.html