实验环境

在安装和配置映像服务之前,必须创建数据库、服务凭据和 API 终结点。

1.创建数据库

  • 使用数据库访问客户端以用户身份连接到数据库服务器:root

    1. [root@controller ~]# mysql -u root -pcom.123
  • 创建数据库:glance

    MariaDB [(none)]> CREATE DATABASE glance;
    Query OK, 1 row affected (0.001 sec)
    
  • 授予对数据库的适当访问权限:glance ``` MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO ‘glance’@’localhost’ IDENTIFIED BY ‘com.123’; Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO ‘glance’@’%’ IDENTIFIED BY ‘com.123’; Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> exit Bye

<a name="enjC8"></a>
### 2.源凭据以访问仅管理员 CLI 命令:admin

[root@controller ~]# . admin-openrc

<a name="YlNya"></a>
### 3.要创建服务凭据,请完成以下步骤:

- 创建用户:glance
- password:com.123

[root@controller ~]# openstack user create —domain default —password-prompt glance User Password: Repeat User Password: +——————————-+—————————————————+ | Field | Value | +——————————-+—————————————————+ | domain_id | default | | enabled | True | | id | 4d4a93dd0a6c4abbb754759ba7200eb2 | | name | glance | | options | {} | | password_expires_at | None | +——————————-+—————————————————+


- 将角色添加到用户和项目: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 | 115e557bc8c14c9c92854f0379ca8a9e | | name | glance | | type | image | +——————-+—————————————————+ [root@controller ~]#

<a name="S1Tpv"></a>
### 4.创建影像服务 API 终结点:

[root@controller ~]# openstack endpoint create —region RegionOne image public http://controller:9292 +———————+—————————————————+ | Field | Value | +———————+—————————————————+ | enabled | True | | id | ca5da90616d548e18397b3dbecc8aadb | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | 115e557bc8c14c9c92854f0379ca8a9e | | 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 | de8a12eda1304a3bb0f1fc9dc319af56 | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | 115e557bc8c14c9c92854f0379ca8a9e | | 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 | 80597c730c814890ac992895e98ceee4 | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | 115e557bc8c14c9c92854f0379ca8a9e | | service_name | glance | | service_type | image | | url | http://controller:9292 | +———————+—————————————————+

<a name="cRZsw"></a>
## 一、安装和配置
<a name="u9zPw"></a>
### 1.安装软件包

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

<a name="WQdXl"></a>
### 2.编辑文件并完成以下操作:**/etc/glance/glance-api.conf**

配置数据库访问

[database] connection = mysql+pymysql://glance:com.123@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 = com.123 [paste_deploy] flavor = keystone

配置本地文件系统存储和映像文件的位置:[glance_store]

[glance_store] stores = file,http default_store = file filesystem_store_datadir = /var/lib/glance/images/

<a name="RbviE"></a>
### 3.填充影像服务数据库:

[root@controller glance]# su -s /bin/sh -c “glance-manage db_sync” glance INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. /usr/lib/python2.7/site-packages/pymysql/cursors.py:170: Warning: (1280, u”Name ‘alembic_version_pkc’ ignored for PRIMARY key.”) result = self._query(query) INFO [alembic.runtime.migration] Running upgrade -> liberty, liberty initial INFO [alembic.runtime.migration] Running upgrade liberty -> mitaka01, add index on created_at and updated_at columns of ‘images’ table INFO [alembic.runtime.migration] Running upgrade mitaka01 -> mitaka02, update metadef os_nova_server INFO [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_expand01, add visibility to images INFO [alembic.runtime.migration] Running upgrade ocata_expand01 -> pike_expand01, empty expand for symmetry with pike_contract01 INFO [alembic.runtime.migration] Running upgrade pike_expand01 -> queens_expand01 INFO [alembic.runtime.migration] Running upgrade queens_expand01 -> rocky_expand01, add os_hidden column to images table INFO [alembic.runtime.migration] Running upgrade rocky_expand01 -> rocky_expand02, add os_hash_algo and os_hash_value columns to images table INFO [alembic.runtime.migration] Running upgrade rocky_expand02 -> train_expand01, empty expand for symmetry with train_contract01 INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. Upgraded database to: train_expand01, current revision(s): train_expand01 INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. Database migration is up to date. No migration needed. INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. INFO [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_contract01, remove is_public from images INFO [alembic.runtime.migration] Running upgrade ocata_contract01 -> pike_contract01, drop glare artifacts tables INFO [alembic.runtime.migration] Running upgrade pike_contract01 -> queens_contract01 INFO [alembic.runtime.migration] Running upgrade queens_contract01 -> rocky_contract01 INFO [alembic.runtime.migration] Running upgrade rocky_contract01 -> rocky_contract02 INFO [alembic.runtime.migration] Running upgrade rocky_contract02 -> train_contract01 INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. Upgraded database to: train_contract01, current revision(s): train_contract01 INFO [alembic.runtime.migration] Context impl MySQLImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. Database is synced successfully.

<a name="N3ifa"></a>
### 4.启动服务,完成配置

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

<a name="QZYSN"></a>
## 二、验证操作

- token [https://www.sdnlab.com/17872.html](https://link.zhihu.com/?target=https%3A//www.sdnlab.com/17872.html)
<a name="ZG8U8"></a>
### 1.源凭据以访问仅管理员 CLI 命令:admin

[root@controller ~]# . admin-openrc

<a name="lqr7D"></a>
### 2.下载源映像:

- -c 采用断点续传

下载镜像请点击:[镜像站](http://download.cirros-cloud.net/0.4.0/)

<a name="jwJdn"></a>
### 3.使用QCOW2磁盘格式、裸容器格式和公共可见性将映像上载到映像服务,以便所有项目都可以访问它:

[root@controller openstack]# 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 | 2022-02-21T02:49:23Z | | disk_format | qcow2 | | id | 3f420824-93a7-453a-92ff-db3b7c0b8f19 | | min_disk | 0 | | min_ram | 0 | | name | cirros | | os_hash_algo | sha512 | | os_hash_value | 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e | | | 2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 | | os_hidden | False | | owner | 8fe34166fe7b4dfa8195490b3ecacb56 | | protected | False | | size | 12716032 | | status | active | | tags | [] | | updated_at | 2022-02-21T02:49:23Z | | virtual_size | Not available | | visibility | public | +—————————+—————————————————————————————————————————+ [root@controller openstack]#

<a name="K7Yjb"></a>
### 4.确认图像的上传并验证属性:

[root@controller openstack]# glance image-list +———————————————————+————+ | ID | Name | +———————————————————+————+ | 3f420824-93a7-453a-92ff-db3b7c0b8f19 | cirros | +———————————————————+————+ [root@controller openstack]#

```