超详细Openstack核心组件 您所在的位置:网站首页 OpenStack功能模板介绍 超详细Openstack核心组件

超详细Openstack核心组件

2024-06-29 12:24| 来源: 网络整理| 查看: 265

目录 Glance镜像服务Glance镜像服务Glance架构详解Glance工作流程 项目:OpenStack-Glance组件部署创建数据库实例和数据库用户创建用户、修改配置文件 总结

Glance镜像服务

概述

它在OpenStack中的项目名称为Glance。在早期的OpenStack版本中,Glance只有管理镜像的功能,并不具备镜像存储功能。现在,Glance已发展成为集镜像上传、检索、管理和存储等多种功能的OpenStack核心服务。

镜像

镜像的英文为Image,又译为映象,通常是指一系列文件或一个磁盘驱动器的精确副本。镜像文件其实和ZIP压缩包类似,它将特定的一系列文件按照一定的格式制作成单一的文件,以方便用户下载和使用。 Glance镜像服务

镜像服务 镜像服务就是用来管理镜像的,让用户能够发现、获取和保存镜像。在openStack中提供镜像服务的是Glance,其主要功能如下:

查询和获取镜像的元数据和镜像本身注册和上传虚拟机镜像,包括镜像的创建、上传、下载和管理维护镜像信息,包括元数据和镜像本身。支持多种方式存储镜像,包括普通的文件系统、Swift、Amazon s3等对虚拟机实例执行创建快照命令来创建新的镜像,或者备份虚拟机的状态。

lmages API的版本 Glance提供的RESTful API目前有两个版本:API v1和API v2

v1只提供基本的镜像和成员操作功能,包括镜像创建、删险下载、列表、详细信息查询、更新,以及镜像租户成员的创建、删除和列表。v2除了支持v1的所有功能外,主要增加了镜像位置的添加、删除、修改,元数据和名称空间操作,以及镜像标记操作。

注:两个版本对镜像存储支持相同,v1从N版开始已经过时,迁移路径使用v2进行替代

镜像格式 虚拟机镜像文件磁盘格式:

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:没有容器或元数据“信封”的镜像ovf:开放虚拟化格式ova:在Glance中存储的开放虚拟化设备格式aki:在Glance中存储的Amazon内核格式ari:在Glance中存储的Amazon虚拟内存盘(Ramdisk)格式Docker:在Glance中存储的容器文件系统的Dockerd的tar档案

注:如果不能确定选择哪种容器格式,那么简单地容器格式指定为bare是安全

Glance架构详解

架构图 在这里插入图片描述

客户端是Glance服务应用程序使用者,是OpenStack命令行工具、Horizon或Nova服务glance-api是系统后台运行的服务进程,是进Glance的入口。它对外提供RESTAPI,负责接收用户的RESTful请求,响应镜像查询、获取和存储的调用。glance-registry是系统后台运行的glance注册服务进程,负责处理与镜像元数据相关的RESTful请求,元数据包括镜像大小、类型等信息。Glance-api接收的请求如果是与镜像的元数据相关的摸作, glance-api会把请求转发给glance-registry。 glance-registry会解析请求内容,并与数据库交互,存储、处理、检索镜像的元数据。glance-api对外提供API,而glance-registry的API只由glance-api使用。Glance的DB模块存储的是镜像的元数据,可以选用MYSQL、MariaDB、SQLite等数据库。镜像的元数据通过glance-registry存放在数据库中。注意,镜像本身(chunk数据)是通过glance存储驱动存放到各种存储后端中的。存储后端(Store Backend) Glance自身并不存储镜像,它将镜像存放在后端存储系统中。镜像本身的数据通过glance_store存放在各种后端,并可从中获取。支持本地存储、对象存储、RBD块设备、Sheepdog分布式存储、Cinder块存储、VMware数据存储。具体使用哪种 backend,是在 /etc/glance/glance-api.conf中配置的[glance_store] Glance工作流程

流程解析

OpenStack的操作都需经Keystone进行身份认证(AuthN)并授权(AuthZ),Glance也不例外。Glance是一个C/S架构,提供一个REST API,用户就通 RESTAPI来执行镜像的各种操作。Glance Domain Controller是一个主要的中间件,相当于调度器,作用是将Glance内部服务的操作分发到以下各个功能层Auth(授权):用来控制镜像的访问权限,决定镜像自己或者它的属性是否可以被修改,只有管理员或镜像的拥有者才可以执行修改操作。roperty Protection(属性保护):这是个可选层,要在Glance配置文件中设置了property_protection_file参数才会生效。它提供两种类型的镜像属性,一种是核心属性,在镜像参数中指定;另一种是元数据属性,可以被附加到一个镜像上的任一键值对。该层通过调用Glance的public API管理对meta属性的访问,也可以在配置文件中限制该访问。Notifier(消息通知):将镜像变化的消息和使用镜像时发生的错误和警告添加到消息队列中。

在这里插入图片描述

项目:OpenStack-Glance组件部署

继Keystone介绍及部署完成后,继续部署Glance

创建数据库实例和数据库用户 [root@ct ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 36 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_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.000 sec) MariaDB [(none)]> exit Bye

在这里插入图片描述

创建用户、修改配置文件

创建OpenStack的Glance用户 创建用户前,需要首先执行管理员环境变量脚本(此处已经在~/.bashrc 中定义过了)

[root@ct ~]# openstack user create --domain default --password GLANCE_PASS glance //创建glance用户 +---------------------+----------------------------------+ | Field | Value | +---------------------+----------------------------------+ | domain_id | default | | enabled | True | | id | a431ebad7f76419098e0947b45f4c3fd | | name | glance | | options | {} | | password_expires_at | None | +---------------------+----------------------------------+ [root@ct ~]# openstack role add --project service --user glance admin //将glance用户添加到service项目中,并且针对这个项目拥有admin权限;注册glance的API,需要对service项目有admin权限 [root@ct ~]# openstack service create --name glance --description "OpenStack Image" image //创建一个service服务,service名称为glance,类型为image;创建完成后可以通过 openstack service list 查看 +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | OpenStack Image | | enabled | True | | id | bcf685f7401f42d49d3f8b371483eaa1 | | name | glance | | type | image | +-------------+----------------------------------+

1. 创建镜像服务 API 端点,OpenStack使用三种API端点代表三种服务:admin、internal、public

[root@ct ~]# openstack endpoint create --region RegionOne image public http://ct:9292 +--------------+----------------------------------+ | Field | Value | +--------------+----------------------------------+ | enabled | True | | id | 5bdce8d99fe844cab18a180078f8ea45 | | interface | public | | region | RegionOne | | region_id | RegionOne | | service_id | bcf685f7401f42d49d3f8b371483eaa1 | | 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 | 797fec53bace4c68a894669f99b37008 | | interface | internal | | region | RegionOne | | region_id | RegionOne | | service_id | bcf685f7401f42d49d3f8b371483eaa1 | | 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 | 56488edc14654767ba859f59233c786c | | interface | admin | | region | RegionOne | | region_id | RegionOne | | service_id | bcf685f7401f42d49d3f8b371483eaa1 | | service_name | glance | | service_type | image | | url | http://ct:9292 | +--------------+----------------------------------+

2. 安装 openstack-glance 软件包

[root@ct ~]# yum -y install openstack-glance

3. 修改glance配置文件 glance有两个配置文件: /etc/glance/glance-api.conf /etc/glance/glance-registry.conf

[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

4. 添加glance-api.conf配置

修改配置文件参数 [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000 [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000 [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct:11211 [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password GLANCE_PASS [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf glance_store default_store file [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/ [root@ct ~]# cd /etc/glance/ [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 //指定认证的keystone的URI 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 [profiler] [store_type_location_strategy] [task] [taskflow_executor]

5. 修改glance-registry.conf 配置文件

备份、过滤注释信息 [root@ct ~]# cp -a /etc/glance/glance-registry.conf{,.bak} [root@ct ~]# grep -Ev '^$|#' /etc/glance/glance-registry.conf.bak > /etc/glance/glance-registry.conf 修改配置文件参数 [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000 [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000 [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct:11211 [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password GLANCE_PASS [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf glance_store default_store file [root@ct ~]# openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/ 修改参数(配置与glance-api.conf相同) [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@t/glance [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://ct:5000 [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://ct:5000 [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers ct:11211 [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password GLANCE_PASS [root@ct ~]# openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone [root@ct ~]# cd /etc/glance/ [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]

6. 初始化glance数据库,生成相关表结构;(不管有多少个controler,只需要初始化一次即可)

[root@ct ~]# su -s /bin/sh -c "glance-manage db_sync" glance

在这里插入图片描述 7. 开启glance服务(此处开启之后会生成存放镜像的目录/var/lib/glance/image)

[root@ct ~]# 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 ~]# systemctl start openstack-glance-api.service

8. 查看端口(也可以使用lsof -i:9292 )

[root@ct ~]# netstat -natp | grep 9292 tcp 0 0 0.0.0.0:9292 0.0.0.0:* LISTEN 111801/python2

在这里插入图片描述 9. 赋予openstack-glance-api.service服务对存储设备的可写权限(-h:值对符号连接/软链接的文件修改)

[root@ct ~]# chown -hR glance:glance /var/lib/glance/

10. 镜像导入 在这里插入图片描述

[root@ct ~]# ll 总用量 12964 -rw-------. 1 root root 1512 1月 19 15:44 anaconda-ks.cfg -rw-r--r--. 1 root root 13267968 2月 18 17:21 cirros-0.3.5-x86_64-disk.img

在这里插入图片描述

11. 先上传cirros镜像到控制节点的/root,然后导入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-02-18T09:23:56Z | | disk_format | qcow2 | | file | /v2/images/a4ff4b8f-4c46-4bc3-9c0c-2de82b257447/file | | id | a4ff4b8f-4c46-4bc3-9c0c-2de82b257447 | | min_disk | 0 | | min_ram | 0 | | name | cirros | | owner | 667d2c1d9fca46a690b830e6864580c9 | | 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-02-18T09:23:56Z | | virtual_size | None | | visibility | public | +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

11. 查看镜像的两种方式 方式1:

[root@ct ~]# openstack image list +--------------------------------------+--------+--------+ | ID | Name | Status | +--------------------------------------+--------+--------+ | a4ff4b8f-4c46-4bc3-9c0c-2de82b257447 | cirros | active | +--------------------------------------+--------+--------+

方式2:

[root@ct ~]# glance image-list +--------------------------------------+--------+ | ID | Name | +--------------------------------------+--------+ | a4ff4b8f-4c46-4bc3-9c0c-2de82b257447 | cirros | +--------------------------------------+--------+

至此,glance部署完成

总结

因为OpenStack上创建虚拟机需要镜像支持,所以先行进行部署 部署思路:

创建数据库、授权创建openstack用户、授权、管理


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有