4. Glance(Rocky) - 镜像服务
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
用户存储镜像的元数据的大小、类型,支持大多数数据库,一般选择MySQL或SQLite;
- 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数据库
[root@controller ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 27
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> quit
Bye
4.2.2 创建Glance用户
加载 admin
凭证,来获取管理员命令的执行权限
[root@controller ~]# source admin-openrc
[root@controller ~]# env | grep OS
创建 glance
用户
[root@controller ~]# openstack user create --domain default --password-prompt glance
给 glance
用户分配 admin
角色,并加入到 service
项目
[root@controller ~]# openstack role add --project service --user glance admin
创建glance
服务
[root@controller ~]# openstack service create --name glance --description "OpenStack Image" image
创建glance
API 端点
[root@controller ~]# openstack endpoint create --region RegionOne image public http://controller:9292
[root@controller ~]# openstack endpoint create --region RegionOne image internal http://controller:9292
[root@controller ~]# openstack endpoint create --region RegionOne image admin http://controller:9292
4.2.3 安装配置Glance
# 安装Glance
yum install -y openstack-glance
# 配置Glance
vim /etc/glance/glance-api.conf
connection = mysql+pymysql://glance:glance@controller.alec.com/glance
配置认证服务访问
vim /etc/glance/glance-api.conf
配置本地文件系统存储和镜像文件位置
4.2.4 初始化数据库
[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance
[root@controller ~]# systemctl start openstack-glance-api
[root@controller ~]# systemctl enable openstack-glance-api
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service.
4.3 验证服务
获取admin凭证执行admin命令
source admin-openrc
4.3.1 最快测试方法
手动生成一个.img
文件,传到Glance上;
[root@controller ~]# dd if=/dev/zero of=test.img bs=1M count=10
[root@controller ~]# openstack image create "test" --file test.img --disk-format qcow2 --container-format bare –public
查看上传后的镜像信息
注:部分内容引用他人文章,如有侵权请联系删除atlantis_0425@outlook