美文网首页
4. Glance(Rocky) - 镜像服务

4. Glance(Rocky) - 镜像服务

作者: 找呀找提莫 | 来源:发表于2020-07-19 19:50 被阅读0次

4.1 Glance说明

4.1.1 Glance服务功能

  • OpenStack镜像服务(Glance)使用户能够发现、注册并检索虚拟机镜像(.img文件);
  • 它提供了一个 REST API 接口,使用户可以查询虚拟机镜像源数据和检索一个实际的镜像文件;
  • 不论是简单的文件系统还是 OpenStack 对象存储,你都可以通过镜像服务在不同位置存储虚拟镜像
  • 默认情况下,上传的虚拟机镜像存储路径为 /var/lib/glance/images/

4.1.2 组件说明

  • glance-api

    一个用来接收镜像、发现、检索和存储的API接口;

  • glance-registry

    用来存储、处理和检索镜像的元数据;

    元数据包换对象的大小和类型;

    glance-registry是一个OpenStack镜像服务使用的内部服务,不要透露给用户;

  • DataBase

    用户存储镜像的元数据的大小、类型,支持大多数数据库,一般选择MySQLSQLite

  • Storage repository for image files

    镜像文件的存储仓库;

    支持包括普通文件系统在内的各种存储类型;

    包括对象存储、块设备、HTTP、Amazon S3,但有些存储只支持只读访问;

  • Image Identifiers

    Image URL,格式<Glance Server Location>/images/<ID>

    全局唯一;

  • Image Status

    • Queued 镜像ID已被保留,镜像还没有上传
    • Saving 镜像正在被上传
    • Active 镜像可以使用
    • Killed 镜像损坏或者不可用
    • Deleted 镜像被删除
  • Disk Format

    • Raw This si unstructured disk image format
    • Vhd VMare、XEN、Microsoft、VirtualBox
    • Vmdk common format
    • Vdi VirtualBox、QEMU emulator
    • ISO optical disc
    • Qcow2 QEMU emulator
    • Aki Amazon Kernel Image
    • Ari Amazon RamDisk Image
    • Ami Amazon Machine Image
  • Container Format

    • Bare
    • Ovf
    • Aki
    • Ami
    • Ari

4.2 部署 Glance

4.2.1 创建Clance数据库

CREATE DATABASE glance;

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';

FLUSH PRIVILEGES;

4.2.2 创建Glance用户

加载 admin 凭证,来获取管理员命令的执行权限

source admin-openrc

创建 glance 用户

openstack user create --domain default --password-prompt glance
User Password:glance
Repeat User Password:glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 4f080a83b50d4a118cf8912f2caff239 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

glance用户分配 admin 角色,并加入到 service 项目

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

创建glance服务

openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 926ff884210448eba132cb949a974d95 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

创建glance API 端点

openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | ea975e2fa8c04cbeafe3ad31fc838202 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 926ff884210448eba132cb949a974d95 |
| 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           | 0d0fb6f4838c461f89fd465018aef4a4 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 926ff884210448eba132cb949a974d95 |
| 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           | 0b924b6956b84495bc92f28ad58791f3 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 926ff884210448eba132cb949a974d95 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

4.2.3 安装配置Glance

# 安装Glance
yum install -y openstack-glance

# 配置Glance
vim /etc/glance/glance-api.conf

配置数据库连接

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

配置本地文件系统存储和镜像文件位置

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

4.2.4 初始化数据库

su -s /bin/sh -c "glance-manage db_sync" glance

4.2.5 启动服务

systemctl start openstack-glance-api
systemctl enable openstack-glance-api

4.3 验证服务

获取admin凭证执行admin命令

source admin-openrc

4.3.1 最快测试方法

手动生成一个.img文件,传到Glance上;

dd if=/dev/zero of=test.img bs=1M count=10

openstack image create "test" --file test.img --disk-format qcow2 --container-format bare --public

4.3.2 官方测试方法

下载镜像

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

使用 qcow2磁盘格式、bare容器格式 上传到glance服务,并设置为public;让所有项目都可以访问;

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       | 2020-07-18T15:21:52Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/2ab0cd11-0aa3-4735-a85f-2c348de0a89d/file |
| id               | 2ab0cd11-0aa3-4735-a85f-2c348de0a89d                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | c6f8d8041d5c4f128c4d6c489156b875                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13287936                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2020-07-18T15:21:53Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+

查看上传后的镜像信息

openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 2ab0cd11-0aa3-4735-a85f-2c348de0a89d | cirros | active |
+--------------------------------------+--------+--------+

相关文章

网友评论

      本文标题:4. Glance(Rocky) - 镜像服务

      本文链接:https://www.haomeiwen.com/subject/khprkktx.html