Openstack 部署之 Glance(四)

首页 / ☁️Cloud / 正文

一、Glance基础

1、Glance概述

它在OpenStack中的项目名称为Glance,在早期的OpenStack版本中,Glance只有管理镜像的功能,并不具备镜像存储功能,现在Glance已发展成为镜像上传、检索、管理和存储等多种功能的OpenStack核心服务。我们基于Openstack是构建基本的IaaS平台对外提供虚拟机,而虚拟机在创建时必须为选择需要安装的操作系统,Glance服务就是为该选择提供不同的操作系统镜像。

2、Glance组件

  • Glance-API

主要用来响应各种REST请求然后通过其它模块(主要是glance-registry组件和后端存储接口)完成镜像的上传、删除、查询等操作。可以简单的再分为两部分:一层中间件,它主要是做一些对请求的解析工作(如分析出版本号), 另外一部分提供实际的服务(如与镜像上传下载的后端存储接口交互)。默认绑定端口是9292。

  • Glance-Registry

镜像注册服务用于提供镜像元数据的REST接口。主要工作是存储或者获取镜像的元数据,与MySQL数据库进行交互。也可以简单的再细分为两部分,API和具体的Server。元数据是指镜像相关的一些信息(如id,size, status,location,checksum,min_disk,min_ram,owner等)真正的镜像数据保存在实际所使用的后端存储里(如Swift,S3,Filesystem等)。默认绑定的端口是9191。

  • database (db)

image 的 metadata 都保存在 database 中,默认 MySQL。

  • store backend

严格来说store backend不属于Glance的组件,这里把它单独分出来只是为了方便理解,它只是一个接口层,提供镜像存储和查询的接口。具体的实现则需要外部存储(Swift,S3,等)的支持。

二、Glance配置

(1) mysql 创库授权

  • 登陆数据库,无密码的话直接 mysql 回车即可
[root@controller ~]# mysql -u root -p
  • 创建glance数据库
MariaDB [(none)]> CREATE DATABASE glance;
  • 授予对glance数据库的正确访问权限
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS';
MariaDB [(none)]>  GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';
MariaDB [(none)]> quit

(2) 在keystone创建服务用户,并关联角色

  • 创建用户
[root@controller ~]# openstack user create --domain default --password GLANCE_PASS  glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 01066dd3eacc47a09d71b0d7c18b743e |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
  • 给 glance 关联 admin 角色
[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          | 8d22c9ed24f244f9b5c2bc9e175a497d |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

(3) 在keystone上注册api访问地址

  • 创建镜像服务API
[root@controller ~]# openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 4119b06d329e4a16b4546286cf3f946c |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8d22c9ed24f244f9b5c2bc9e175a497d |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 97220fed62fe4c919fb1531e53e27840 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8d22c9ed24f244f9b5c2bc9e175a497d |
| 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           | 58ca9263e57b44079fea0b514e0b6157 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8d22c9ed24f244f9b5c2bc9e175a497d |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

(4) 安装 openstack-glance 软件包

[root@controller ~]# yum install openstack-glance -y

#注:CentOS 8 安装会报错,示例如下:
[root@controller yum.repos.d]# yum install -y openstack-glance                                                                                         Repository extras is listed more than once in the configuration
Last metadata expiration check: 0:00:40 ago on Tue 24 Aug 2021 10:38:15 PM CST.
Error: 
 Problem: package openstack-glance-1:19.0.4-1.el8.noarch requires python3-glance = 1:19.0.4-1.el8, but none of the providers can be installed
  - cannot install the best candidate for the job
  - nothing provides python3-httplib2 needed by python3-glance-1:19.0.4-1.el8.noarch
  - nothing provides python3-pyxattr needed by python3-glance-1:19.0.4-1.el8.noarch
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

解决:下载 python3-httplib2,python3-pyxattr 并安装 再执行 yum install openstack-glance -y
[root@controller rpmpackage]# wget https://rpmfind.net/linux/centos/8.3.2011/PowerTools/x86_64/os/Packages/python3-pyxattr-0.5.3-18.el8.x86_64.rpm
[root@controller rpmpackage]# sudo rpm -i python3-pyxattr-0.5.3-18.el8.x86_64.rpm
[root@controller rpmpackage]# sudo wget https://rpmfind.net/linux/centos/8.3.2011/PowerTools/x86_64/os/Packages/python3-httplib2-0.10.3-4.el8.noarch.rpm
[root@controller rpmpackage]# sudo rpm -i python3-httplib2-0.10.3-4.el8.noarch.rpm

(5) 修改glance配置文件

[root@controller ~]# cp /etc/glance/glance-api.conf /etc/glance/glance-api.conf.bak
[root@controller ~]# grep -Ev "^#|^$" /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf
[root@controller ~]# vi /etc/glance/glance-api.conf
[DEFAULT]
[cinder]
[cors]
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
[file]
[glance.store.http.store]
[glance.store.rbd.store]
[glance.store.sheepdog.store]
[glance.store.swift.store]
[glance.store.vmware_datastore.store]
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
[image_format]
[keystone_authtoken]
www_authenticate_uri  = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS
[oslo_concurrency]
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_middleware]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
[store_type_location_strategy]
[task]
[taskflow_executor]

(6) 同步数据库

[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance

(7) 启动服务

[root@controller ~]# systemctl enable openstack-glance-api.service
[root@controller ~]# systemctl start openstack-glance-api.service

(8) 验证服务

[root@controller /]# openstack image create "cirros"   --file cirros-0.4.0-x86_64-disk.img   --disk-format qcow2 --container-format bare   --public
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | 443b7623e27ecf03dc9e01ee93f67afe                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2021-08-22T04:25:56Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/c35fcda2-bbed-470c-8b1d-68c2f42afeba/file                                                                                                                                       |
| id               | c35fcda2-bbed-470c-8b1d-68c2f42afeba                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | cirros                                                                                                                                                                                     |
| owner            | 37297436d3384cf18dde714da386d2af                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 12716032                                                                                                                                                                                   |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2021-08-22T04:25:56Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | public                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

三、参考文章

感谢以下文章和博主的帮助!

玩转 OpenStack(四)Keystone、Glance - 简书 (jianshu.com)

打赏
文章目录