文章总目录
Glance 服务功能
•OpenStack镜像服务( glance )使用户能够发现、注册并检索虚拟机镜像( .img文件)
•它提供了一个REST API 接口,使用户可以查询虚拟机镜像元数据和检索一个实际的镜像文件
•不论是简单的文件系统还是OpenStack 对象存储,你都可以通过镜像服务在不同的位置存储虚拟机镜像
•默认情况下,上传的虚拟机镜像存储路径为/var/lib/glance/images/
glance-api:一个用来接收镜像发现、检索和存储的API 接口
glance-registry:用来存储、处理和检索镜像的元数据。元数据包含对象的大小和类型。
glance-registry是一个OpenStack镜像服务使用的内部服务,不要透露给用户
Database:用于存储镜像的元数据的大小、类型,支持大多数数据库,一般选择MySQL 或SQLite
Storage repository for image files:镜像文件的存储仓库。支持包括普通文件系统在内的各种存储类型。包括对象存储、块设备、HTTP、Amazon S3,但有些存储只支持只读访问
Image Identifiers:就是Image URL ,格式/images/全局唯一
ImageStatus
➢Queued:镜像ID 已被保留,镜像还没有上传
➢Saving:镜像正在被上传
➢Active:镜像可以使用了
➢Killed:镜像损坏或者不可用
➢Deleted:镜像被删除
Disk Format
➢Raw:This is unstructured disk image format
➢Vhd:VMWare、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
一、安装先决条件
1、创建数据库
a.以数据库管理员root的身份登录数据库
[root@controller ~]# mysql -uroot -pa
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 5.5.37-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
b.创建glance数据库
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.00 sec)
c.创建数据库用户glance,并授予其对glance数据库的管理权限
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';
Query OK, 0 rows affected (0.00 sec)
2、启用admin环境脚本
[root@controller ~]# source admin-openrc.sh
3、创建认证服务凭证
a.创建glance用户
[root@controller ~]# keystone user-create --name glance --pass GLANCE_PASS
+----------+----------------------------------+
| Property | Value |
+----------+----------------------------------+
| email | |
| enabled | True |
| id | aec25e44755d425cb8948bafc47d5071 |
| name | glance |
| username | glance |
+----------+----------------------------------+
b.将glance用户链接到service租户和admin角色
[root@controller ~]# keystone user-role-add --user glance --tenant service --role admin
c.创建glance服务
[root@controller ~]# keystone service-create --name glance --type image --description "OpenStackImage Service"
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| description | OpenStackImage Service |
| enabled | True |
| id | 4436c2e4a7c940ea895a3b84484c02a5 |
| name | glance |
| type | image |
+-------------+----------------------------------+
4、为OpenStack镜像服务创建认证服务端点admin(管理),internal(内部),public(公共)
[root@controller ~]# keystone endpoint-create --service-id $(keystone service-list |awk '/image/{print $2}') --publicurl http://controller.nice.com:9292 --internalurl http://controller.nice.com:9292 --adminurl http://controller.nice.com:9292 --region regionOne
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| adminurl | http://controller.nice.com:9292 |
| id | bb5cce3c4f0f4528812fbb7796ab0f89 |
| internalurl | http://controller.nice.com:9292 |
| publicurl | http://controller.nice.com:9292 |
| region | regionOne |
| service_id | 4436c2e4a7c940ea895a3b84484c02a5 |
+-------------+----------------------------------+
构建完成
[root@controller images]# yum install -y lrzsz
[root@controller images]# ls
cirros-0.3.3-x86_64-disk.img
[root@controller ~]# source admin-openrc.sh
[root@controller images]# glance image-create --name "cirros-0.3.3-x86_64" --file cirros-0.3.3-x86_64-disk.img --disk-format qcow2 --container-format bare --is-public True --progress
[=============================>] 100%
+------------------+--------------------------------------+
| Property | Value |
+------------------+--------------------------------------+
| checksum | 133eae9fb1c98f45894a4e60d8736619 |
| container_format | bare |
| created_at | 2020-07-24T11:25:08 |
| deleted | False |
| deleted_at | None |
| disk_format | qcow2 |
| id | 807f460b-566a-4989-b166-dc83248d4a40 |
| is_public | True |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros-0.3.3-x86_64 |
| owner | dc4de4d7ecda4ed898b5e0d82809d2ad |
| protected | False |
| size | 13200896 |
| status | active |
| updated_at | 2020-07-24T11:25:09 |
| virtual_size | None |
+------------------+--------------------------------------+
测试成功
二、安装并配置镜像服务组件
1、安装软件包
[root@controller ~]# yum install openstack-glance python-glanceclient
2、编辑文件更改配置文件
[root@controller ~]# vim /etc/glance/glance-api.conf
a.修改[database]小节,配置数据库连接:
[database]...
connection = mysql://glance:GLANCE_DBPASS@controller.nice.com/glance
b.修改[keystone_authtoken]和[paste_deploy]小节,配置认证服务访问:[keystone_authtoken]
...
auth_uri= http://controller.nice.com:5000/v2.0
identity_uri= http://controller.nice.com:35357
admin_tenant_name= service
admin_user= glance
admin_password= GLANCE_PASS
[paste_deploy]
...
flavor = keystone
c.(可选)在[DEFAULT]小节中配置详细日志输出。方便排错。[DEFAULT]...verbose = True
3、编辑/etc/glance/glance-registry.con文件,并完成下列配置:
a.在[database]小节中配置数据库连接:
[database]
...
connection = mysql://glance:GLANCE_DBPASS@controller.nice.com/glance
b.在[keystone_authtoken]和[paste_deploy]小节中配置认证服务访问
[keystone_authtoken]
...
auth_uri= http://controller.nice.com:5000/v2.0
identity_uri= http://controller.nice.com:35357
admin_tenant_name= service
admin_user= glanceadmin_password= GLANCE_PASS[paste_deploy]...flavor = keystone
c.在[glance_store]小节中配置本地文件系统存储和镜像文件的存放路径
[glance_store]
...
default_store= filefile
system_store_datadir= /var/lib/glance/images/
d.(可选)在[DEFAULT]小节中配置详细日志输出。方便排错。
[DEFAULT]
...
verbose = True
4、初始化镜像服务的数据库
[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance
启动镜像服务并设置开机自动启动:
[root@controller ~]# systemctl enable openstack-glance-api.service openstack-glance-registry.service
ln -s '/usr/lib/systemd/system/openstack-glance-api.service' '/etc/systemd/system/multi-user.target.wants/openstack-glance-api.service'
ln -s '/usr/lib/systemd/system/openstack-glance-registry.service' '/etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service'
[root@controller ~]# systemctl start openstack-glance-api.service openstack-glance-registry.service
glance image-create相关选项含义:
--name <NAME>镜像名称。
--file <FILE>要上传文件及路径。
--disk-format <DISK_FORMAT>镜像的磁盘格式。可以支持:ami, ari, aki, vhd, vmdk, raw, qcow2, vdi,iso格式。
--container-format <CONTAINER_FORMAT>镜像容器格式。可以支持:ami, ari, aki, bare, ovf格式。
--is-public {True,False}镜像是否可以被公共访问。
--progress显示上传进度
[root@controller images]# glance image-list
+--------------------------------------+---------------------+-------------+------------------+----------+--------+
| ID | Name | Disk Format | Container Format | Size | Status |
+--------------------------------------+---------------------+-------------+------------------+----------+--------+
| 807f460b-566a-4989-b166-dc83248d4a40 | cirros-0.3.3-x86_64 | qcow2 | bare | 13200896 | active |
+--------------------------------------+---------------------+-------------+------------------+----------+--------+