OpenStack Wallaby 部署3 镜像服务 Glance

👌 2021-05-08 OpenStack Wallaby 部署3 镜像服务-glance

FileInfo Filename - OpenStack Wallaby 部署简介 Version - v1.0.2105(2021/05/08 ~ 2021/05/10) Author - standuke Email - shadowdoker@gmail.com DescriptionKey - Glance installation of OpenStack Wallaby deployment

版本修订记录:

v1.0.2105:2021-05-07:建立 OpenStack Wallaby 部署3 镜像服务-glance,修订人:standuke

[TOC]

MariaDB 创建用户

  1. 创建数据库
CREATE DATABASE glance;
  1. 授予权限

GLANCE_DBPASS = GLANCE

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
 IDENTIFIED BY 'GLANCE_DBPASS';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
 IDENTIFIED BY 'GLANCE_DBPASS';
 flush privileges;

keystone 创建相关信息

生效管理员用户

. admin-openrc

创建用户、服务

  1. 创建 glance 用户
openstack user create --domain default --password-prompt glance

+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 47d82b6275844ddb9ef9053a20892521 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
  1. 赋予 glance 用户、service 项目 admin 角色

此处的 service 项目已经在 keystone 的 2. 创建服务「Service」 步骤完成了,所以只需要赋予角色即可

openstack role add --project service --user glance admin

该命令不提供任何输出。
  1. 创建 glance 服务实体
openstack service create --name glance --description "OpenStack Image" image

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 8894d10830b84a6aa333d2534745656c |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

创建服务 endpoint

openstack endpoint create --region RegionOne image public http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | aaabde94a26341d39e93e41cd8aa0407 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8894d10830b84a6aa333d2534745656c |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

openstack endpoint create --region RegionOne image internal http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 646ca2a253c14386b2d85bf53c8ddee8 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8894d10830b84a6aa333d2534745656c |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

openstack endpoint create --region RegionOne image admin http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 47a440c573e24bd4b3aec173903b8f17 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8894d10830b84a6aa333d2534745656c |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

部署 glance

安装软件包

apt install glance

修改配置文件

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

GLANCE_DBPASS = GLANCE

vim /etc/glance/glance-api.conf

[database]
# ...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

[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

[paste_deploy]
# ...
flavor = keystone

[glance_store]
# ...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
  1. 初始化 glance 数据库
su -s /bin/sh -c "glance-manage db_sync" glance

Upgraded database to: wallaby_contract01, current revision(s): wallaby_contract01
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Database is synced successfully.

启动 glance

systemctl start glance-api.service
systemctl enable glance-api.service

里程碑

下载测试用镜像

wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img

上传镜像至 glance

  1. 使用 qcow2 磁盘格式,raw 格式和公共可见将 img 上传 glance 服务,以便所有项目都可以访问
glance image-create --name "cirros" \
 --file cirros-0.4.0-x86_64-disk.img \
 --disk-format qcow2 --container-format bare \
 --visibility=public
 
 +------------------+----------------------------------------------------------------------------------+
| Property         | Value                                                                            |
+------------------+----------------------------------------------------------------------------------+
| checksum         | 443b7623e27ecf03dc9e01ee93f67afe                                                 |
| container_format | bare                                                                             |
| created_at       | 2021-05-08T06:18:45Z                                                             |
| disk_format      | qcow2                                                                            |
| id               | f824fa97-8e8e-4229-8bc6-8204ba8a2f46                                             |
| min_disk         | 0                                                                                |
| min_ram          | 0                                                                                |
| name             | cirros                                                                           |
| os_hash_algo     | sha512                                                                           |
| os_hash_value    | 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e |
|                  | 2161b5b5186106570c17a9e58b64dd39390617cd5a350f78                                 |
| os_hidden        | False                                                                            |
| owner            | b78ed759bf184f21bb0a1461d5d9607d                                                 |
| protected        | False                                                                            |
| size             | 12716032                                                                         |
| status           | active                                                                           |
| tags             | []                                                                               |
| updated_at       | 2021-05-08T06:18:45Z                                                             |
| virtual_size     | 46137344                                                                         |
| visibility       | public                                                                           |
+------------------+----------------------------------------------------------------------------------+
  1. 确认上传成功
glance image-list

+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| f824fa97-8e8e-4229-8bc6-8204ba8a2f46 | cirros |
+--------------------------------------+--------+