基于 CentOS 8 手工部署 OpenStack Victoria 版本(四)– 安装 Glance

在 OpenStack 中由 Glance 组件提供镜像服务,使得用户能够发现、注册和检索到虚拟机的镜像,这里我们将 Glance 部署在控制节点上

前提条件

  1. 以 root 身份登录数据库
[root@controller ~]# mysql -u root -p
Enter password:   //输入数据库的密码回车
  1. 创建 Glance 数据库
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.001 sec)
  1. 为 glance 数据库赋予适当的访问权限
其中的 `openstack` 为设置的密码(生产环境中请勿使用该类弱口令作为密码)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'openstack';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'openstack';
  1. 退出数据库
MariaDB [(none)]> exit;
Bye

创建用户和服务凭证

  1. 获取 admin 用户凭据来取得管理员的 CLI 命令权限
[root@controller ~]# . admin-openrc
  1. 创建服务凭证
  • 创建 glance 用户
    为新用户设置一个密码
    [root@controller ~]# openstack user create --domain default --password-prompt glance
    User Password:
    Repeat User Password:
    
    +---------------------+----------------------------------+
    | Field               | Value                            |
    +---------------------+----------------------------------+
    | domain_id           | default                          |
    | enabled             | True                             |
    | id                  | 66b5bbf2c1304903bb0ef022e6309123 |
    | 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          | 1e7b14df8e734d1ab0795bbb8e4a56b4 |
    | name        | glance                           |
    | type        | image                            |
    +-------------+----------------------------------+
    
    
  1. 创建镜像服务 API 端点
[root@controller ~]# openstack endpoint create --region RegionOne image public http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 3e8da310628a4400b1ed0c4e73157572 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 1e7b14df8e734d1ab0795bbb8e4a56b4 |
| 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           | 136045dff1c04b5b9205f0eda04fab0c |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 1e7b14df8e734d1ab0795bbb8e4a56b4 |
| 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           | 4ab281306d9b41f7b7ad88e838c2da09 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 1e7b14df8e734d1ab0795bbb8e4a56b4 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

安装和配置组件

  1. 安装软件包
[root@controller ~]# yum install openstack-glance -y
  1. 编辑配置文件 vim etc/glance/glance-api.conf,并完成以下操作
  • 在 [database] 部分中,配置连接数据库
    将 GLANCE_DBPASS 替换为 Glance 数据库的密码,这里我们设置的密码是 openstack
    [database]
    # ...
    connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
    
  • 在 [keystone_authtoken] 和 [paste_deploy] 部分中,配置连接身份服务
    将 GLANCE_PASS 替换为 Glance 用户的密码,这里我们设置的密码是 openstack
    [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] 部分中,配置使用本地存储存储镜像文件
    [glance_store]
    # ...
    stores = file,http
    default_store = file
    filesystem_store_datadir = /var/lib/glance/images/
    
  1. 填充 glance 数据库
[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance
  1. 启动镜像服务服务设置为开机自启
[root@controller ~]# systemctl enable openstack-glance-api.service
[root@controller ~]# systemctl start openstack-glance-api.service

验证

通过注册一个镜像来验证服务是否正常运行

  1. 获取 admin 用户凭据来取得管理员的 CLI 命令权限
[root@controller ~]# . admin-openrc
  1. 下载一个镜像
[root@controller ~]# wget http://download.rsecc.cn/cirros-0.4.0-x86_64-disk.img
  1. 使用 QCOW2 磁盘格式、bare 容器格式和公共可见性将下载的镜像上载到图像服务,以便所有项目都可以访问
[root@controller ~]# 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-28T07:25:07Z                                                             |
| disk_format      | qcow2                                                                            |
| id               | 5bd98ecd-924f-4345-9d06-5462ac3f78a7                                             |
| min_disk         | 0                                                                                |
| min_ram          | 0                                                                                |
| name             | cirros                                                                           |
| os_hash_algo     | sha512                                                                           |
| os_hash_value    | 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e |
|                  | 2161b5b5186106570c17a9e58b64dd39390617cd5a350f78                                 |
| os_hidden        | False                                                                            |
| owner            | 01ffb904fece44f18bbb4074569a291a                                                 |
| protected        | False                                                                            |
| size             | 12716032                                                                         |
| status           | active                                                                           |
| tags             | []                                                                               |
| updated_at       | 2021-05-28T07:25:08Z                                                             |
| virtual_size     | 46137344                                                                         |
| visibility       | public                                                                           |
+------------------+----------------------------------------------------------------------------------+

  1. 查看上传的镜像的属性
[root@controller ~]# glance image-list
+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| 5bd98ecd-924f-4345-9d06-5462ac3f78a7 | cirros |
+--------------------------------------+--------+
|| 版权声明
作者:Guangran
链接:https://www.rsecc.cn/archives/561.html
声明:如无特别声明本文即为原创文章仅代表个人观点,版权归《广然笔记》所有,欢迎转载,转载请保留原文链接。
THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭
目 录