Glance
- 1.镜像
- 2.Glance镜像服务
- 3.镜像格式
- 4.镜像状态
- 5.Images API的版本
- 6.Glance部署
1.镜像
镜像的因为为lmage,通常是指一系列或一个磁盘驱动器的精准副本,镜像文件其实类似与压缩包,它讲特定的一些列文件按照一定的格式制作成单一的文件,以便于用户下载和使用。
2.Glance镜像服务
镜像服务就是用来管理镜像的,让用户能够发现、获取和保存镜像,再openstack中提供镜像服务的是glance,其主要功能如下:
- 查询和获取镜像的元数据和镜像本身
- 注册和上传虚拟机镜像,包括镜像的创建、上传、下载和管理
- 维护镜像信息,包括元数据和镜像本身
- 支持多种方式存储镜像包括普通文件系统
- 对虚拟机实例执行创建快照命令来创建新的镜像,或者备份虚拟机的状态
3.镜像格式
- 虚拟机镜像文件磁盘格式
raw:无结构的磁盘格式
vhd:该格式通用于VMware、Xen、VirtualBox以及其他虚拟机管理程序
vhdx:vhd格式的增强版本,支持更大的磁盘尺寸vmdk一种比较通用的虚拟机磁盘格式
vdi:由VirtualBox虚拟机监控程序和QEMU仿真器支持的磁盘格式
iso:用于光盘(CD-ROM)数据内容的档案格式
ploop:由Virtuozzo支持,用于运行OS容器的磁盘格式
qcow2:由QEMU仿真支持,可动态扩展,支持写时复制(Copy on Write)的磁盘格式
aki:在Glance中存储的Amazon内核格式
ari:在Glance中存储的Amazon虚拟内存盘(Ramdisk)格式
ami:在Glance中存储的Amazon机器格式 - 容器格式
bare:没有容器或元数据“信封"的镜像
ovt:开放虚拟化格式
ova:在Glance中存储的开放虚拟化设备格式
aki:在Glance中存储的Amazon内核格式
ari:在Glance中存储的Amazon虚拟内存盘(Ramdisk)格式
Docker:在Glance中存储的容器文件系统的Dockerd的tar档案
4.镜像状态
queued:这是一种初始化状态,镜像文件刚被创建,在Glance数据库只有其元数据,镜像数据还没有上传至数据库中
saving:是镜像的原始数据在上传到数据库中的一种过渡状态,表示正在上传镜像
uploading:指示已进行导入数据提交调用,此状态下不允许调用PUT/file (saving状态会执行PUT/file,这是另外一种上传的方法)
importing:指示已经完成导入调用,但是镜像还未准备好使用
active:表示当镜像数据成功上传完毕,成为Glance中可用的镜像
deactivated:表示任何非管理员用户都无权访问镜像数据,禁止下载镜像,也禁止镜像导出和镜像克隆之类的操作(只有管理员可以操作,维护)
killed: 表示镜像上传过程中发生错误,镜像不可读
deleted:镜像将在不久后被自动删除,该镜像不可再用,但是目前Glance仍然保留该镜像的相关信息和原始数据
ending_delete:与deleted相似,Glance还没有清除镜像数据,但处于该状态的镜像不可恢复
5.Images API的版本
glance提供的RESTful API目前有两个版本,AP v1和API v2
- v1:只提供基本的镜像和成员操作功能,包括镜像创建、删除、下载、列表、详细信息查询、更新、以及镜像租户成员的创建、删除和列表
- v2:除了支持v1所有功能外,主要增加了镜像位置的添加、删除、修改,元数据和名称空间操作,以及镜像标记操作
6.Glance部署
- 创建数据实例和数据库用户
[root@ct ~]# mysql -u root -p
Enter password:
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> exit
Bye
- 创建Openstack的Glance用户
[root@ct ~]# openstack user create --domain default --password GLANCE_PASS glance //创建用户
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | c30bd80ead2d470d86a0af046a252991 |
| name | glance |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
[root@ct ~]# openstack role add --project service --user glance admin //讲glance用户添加到service项目中,并且给这个项目拥有admin权限
[root@ct ~]# openstack service create --name glance --description "OpenStack Image" image //创建service服务,名称为glance类型为image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | d9f4b5f3d6ab4309a4c0fb3e1be5ba56 |
| name | glance |
| type | image |
+-------------+----------------------------------+
[root@ct ~]# openstack service list //查看是否成功
+----------------------------------+----------+----------+
| ID | Name | Type |
+----------------------------------+----------+----------+
| 640d22ecf62e443197967f90259d11d5 | keystone | identity |
| d9f4b5f3d6ab4309a4c0fb3e1be5ba56 | glance | image |
+----------------------------------+----------+----------+
- 创建镜像API端点,OpenStack使用三种API端点代表三种服务:admin、internal、public
[root@ct ~]# openstack endpoint create --region RegionOne image public http://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | de3658f4b0154e8e9ea75c89e25b0f91 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | d9f4b5f3d6ab4309a4c0fb3e1be5ba56 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
[root@ct ~]# openstack endpoint create --region RegionOne image internal http://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | f71e19aa78e64113884d32d9d8205830 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | d9f4b5f3d6ab4309a4c0fb3e1be5ba56 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
[root@ct ~]# openstack endpoint create --region RegionOne image admin http://ct:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 4687121e17fa43de890a3ff69d99ab2d |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | d9f4b5f3d6ab4309a4c0fb3e1be5ba56 |
| service_name | glance |
| service_type | image |
| url | http://ct:9292 |
+--------------+----------------------------------+
- 安装glance,并修改配置文件
[root@ct ~]# yum -y install openstack-glance
[root@ct ~]# cp -a /etc/glance/glance-api.conf{,.bak}
[root@ct ~]# grep -Ev '^$|#' /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf
- 添加glance-api.conf配置
openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct:11211
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password GLANCE_PASS
openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/
[root@ct glance]# cat glance-api.conf
[DEFAULT]
[cinder]
[cors]
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
[file]
[glance.store.http.store]
[glance.store.rbd.store]
[glance.store.sheepdog.store]
[glance.store.swift.store]
[glance.store.vmware_datastore.store]
[glance_store]
stores = file,http //存储类型,file:文件,http:基于api调用的方式,把镜像放到其他存储上
default_store = file //默认存储方式
filesystem_store_datadir = /var/lib/glance/images/ //指定镜像存放的本地目录
[image_format]
[keystone_authtoken]
www_authenticate_uri = http://ct:5000 //指定认证
auth_url = http://ct:5000
memcached_servers = ct:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service //glance用户针对service项目拥有admin权限
username = glance
password = GLANCE_PASS
[oslo_concurrency]
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_middleware]
[oslo_policy]
[paste_deploy]
flavor = keystone //指定提供认证的服务器为keystone
[profiler]
[store_type_location_strategy]
[task]
[taskflow_executor]
- 修改glance-registry.conf 配置文件
[root@ct glance]# cp -a /etc/glance/glance-registry.conf{,.bak}
[root@ct glance]# grep -Ev '^$|#' /etc/glance/glance-registry.conf.bak > /etc/glance/glance-registry.conf
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct:11211
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password GLANCE_PASS
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
[root@ct glance]#openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/
[root@ct glance]# cat glance-registry.conf
[DEFAULT]
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@t/glance
[keystone_authtoken]
www_authenticate_uri = http://ct:5000
auth_url = http://ct:5000
memcached_servers = ct:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS
[oslo_messaging_amqp]
[oslo_messaging_kafka]
[oslo_messaging_notifications]
[oslo_messaging_rabbit]
[oslo_policy]
[paste_deploy]
flavor = keystone
[profiler]
- 初始化glance数据库,生成相关表结构
[root@ct 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.
.................
Database is synced successfully.
[root@ct glance]# systemctl enable openstack-glance-api.service //开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service.
[root@ct glance]# systemctl start openstack-glance-api.service
[root@ct glance]# netstat -natp | grep 9292
tcp 0 0 0.0.0.0:9292 0.0.0.0:* LISTEN 77320/python2
[root@ct glance]# chown -hR glance:glance /var/lib/glance/ //赋予openstack-glance-api.service服务对存储设备的可写权限
- 提前上传好镜像cirros-0.3.5-x86_64-disk,并导入glance
[root@ct ~]# openstack image create --file cirros-0.3.5-x86_64-disk.img --disk-format qcow2 --container-format bare --public cirros
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum | f8ab98ff5e73ebab884d80c9dc9c7290 |
| container_format | bare |
| created_at | 2021-08-24T08:44:26Z |
| disk_format | qcow2 |
| file | /v2/images/7f00c6b7-d760-40a8-8973-ada9bb90bcd7/file |
| id | 7f00c6b7-d760-40a8-8973-ada9bb90bcd7 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 1d887fccaddf40818980612ce7a900e9 |
| properties | os_hash_algo='sha512', os_hash_value='f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f919ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232', os_hidden='False' |
| protected | False |
| schema | /v2/schemas/image |
| size | 13267968 |
| status | active |
| tags | |
| updated_at | 2021-08-24T08:44:26Z |
| virtual_size | None |
| visibility | public |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@ct ~]# openstack image list //查看
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 7f00c6b7-d760-40a8-8973-ada9bb90bcd7 | cirros | active |
+--------------------------------------+--------+--------+