Openstack——Glance的基本原理及部署

什么是Glance

OpenStack Glance是一种提供发现,注册,和下载的镜像服务。OpenStack Glance是一个提供虚拟机镜像的集中式仓库。通过Glance的RESTful API,可以查询镜像元数据下载镜像。虚拟机的镜像可以很方便的存储在各种地方,从简单的文件系统到对象存储系统(如OpenStack Swift项目)。

在Glane里镜像被当做模板来存储,用于启动新实例。 Glance是一个可以组织和管理大量虚拟磁盘镜像的独立服务。Glance为云磁盘镜像提供了一个端到端的解决方案。它还可以从正在运行的实例建立快照用于备份虚拟机的状态。

Glance 镜像格式

   1. RAW:RAW即常说的裸格式,它其实就是没有格式,最大的特点就是简单,数据写入什么就是什么,不做任何修饰,所以再性能方面很不错,甚至不需要启动这个镜像的虚拟机,只需要文件挂载即可直接读写内部数据。并且由于RAW格式简单,因此RAW和其他格式之间的转换也更容易。在KVM的虚拟化环境下,有很多使用RAW格式的虚拟机。

   2. QCOW2:它是QEMU的CopyOn Write特性的磁盘格式,主要特性是磁盘文件大小可以随着数据的增长而增长。譬如创建一个10GB的虚拟机,实际虚拟机内部只用了5GB,那么初始的qcow2磁盘文件大小就是5GB。与RAW相比,使用这种格式可以节省一部分空间资源。

   3. VHD:VHD也是一种通用的磁盘格式。微软公司的Virtual PC和Hyper-V使用的就是VHD格式。VirtualBox也提供了对VHD的支持。如果要在OpenStack上使用Hyper-V的虚拟化,就应该上传VHD格式的镜像文件。

   4. VMDK:VMware创建的一个虚拟机磁盘格式,目前也是一个开放的通用格式,除了VMware自家的产品外,QEMU和VirtualBox也提供了对VMDK格式的支持。

   5. VDI:Oracle公司的VirtualBox虚拟软件所使用的格式。

   6. ISO:ISO是指一种存档数据文件在光盘上的格式。

   7. AKI、ARI、AMI:Amazon公司的AWS所使用的镜像格式。

容器格式

   1. BARE:没有容器的一种镜像元数据格式。

   2. OVF:开放虚拟化格式。

   3. OVA:开放虚拟化设备格式。

   4. AKI、ARI:Amazon公司的AWS所使用的镜像格式。

Glance镜像状态

   1. Queued:初始化镜像状态,在镜像文件刚刚被创建,在glance数据库中已经保存了镜像标示符,但还没有上传至glance中,此时的glance对镜像数据没有任何描述,其存储空间为0。

   2. Saving:镜像的原始数据在上传中的一种过度状态,它产生在镜像数据上传至glance的过程中,一般来讲,glance收到一个image请求后,才将镜像上传给glance。

   3. Active:镜像成功上传完毕以后的一种状态,它表明glance中可用的镜像。

   4. Killed:镜像上传失败或者镜像文件不可读的情况下,glance将镜像状态设置成Killed。

   5. Deleted:镜像文件马上会被删除,只是当前glance这种仍然保留该镜像文件的相关信息和原始镜像数据。

   6. Pending_delete:镜像文件马上会被删除,镜像文件不能恢复。

Glance任务的各种状态

在这里插入图片描述

queued:没有上传image数据,只有db中的元数据

saving:正在上传image data。

active:当镜像上传完毕,镜像就可以被使用,此时属于active

deactivated:表示任何非管理员用户都无权访问镜像数据,禁止下载镜像,也禁止镜像导出和镜像克隆之类的操作(请求镜像数据的操作)

killed:表示上传过程中发生错误,并且镜像不可读

deleted:glance已经保存了该镜像的数据,但是该镜像不在可用,处于该状态的镜像将在不久后被自动删除

pending_delete:与delete想说,glance还没有清除镜像数据,处于该状态的镜像不可恢复

glance包含的组件

glance-api

接受api请求,并提供相应操作,包括发现、检索、存储

glance-registry

存储、处理、检索镜像的元数据,元数据包括例如镜像大小、类型等

Database

可以选择组件喜欢的数据库存储进行元数据,大多数使用MySQL或者SQLite.

Storage repository for image files

指的是存储镜像文件的仓库或者称为backend,可以是:

1本地文件存储(或者任何挂载到glance-api控制节点的文件系统)

2.对象存储Object Stroage(Swift)

3.块存储RADOS(ceph)

4.VMware数据存储

5.HTTP

Glance工作流程图

https://images2015.cnblogs.com/blog/1092539/201702/1092539-20170215172914394-1740768822.png

Glance的部署

创建数据库实例和数据库用户

[root@ct ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 21
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.001 sec)

MariaDB [(none)]> grant all privileges on glance .* TO 'glance'@'%'IDENTIFIED BY 'GLANCE_DBPASS';
Query OK, 0 rows affected (0.003 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> exit
Bye

创建用户、修改配置文件

#创建用户前,需要首先执行管理员环境变量脚本(此处已经在~/.bashrc 中定义过了)
[root@ct ~]# openstack user create --domain default --password GLANCE_PASS glance  ###创建glance用户
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | c2ef2593782a488c8b93fafa2f5b44a3 |
| 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
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 8c1ab12614254bd2b8d268d729700c44 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
[root@ct ~]# openstack service list
+----------------------------------+----------+----------+
| ID                               | Name     | Type     |
+----------------------------------+----------+----------+
| 79560875e0cb4985a7f927b931f7b414 | keystone | identity |
| 8c1ab12614254bd2b8d268d729700c44 | 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           | 4d3b0f21087540f4976f3190182d4013 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c1ab12614254bd2b8d268d729700c44 |
| 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           | 776f66d39b354a20987333c20e203ad8 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c1ab12614254bd2b8d268d729700c44 |
| 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           | 69032b21e6b24496b73304f5c567a0d4 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c1ab12614254bd2b8d268d729700c44 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://ct:9292                   |
+--------------+----------------------------------+

安装配置 openstack-glance

1、安装openstack-glance

yum -y install openstack-glance

2、配置glance

#修改glance-api.conf配置,参数如下
[root@ct glance]# vi 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
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
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]
#修改glance-registry.conf配置如下
[root@ct glance]# vi glance-registry.conf
[DEFAULT]
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@ct/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_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

3、初始化数据库

[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.
/usr/lib/python2.7/site-packages/pymysql/cursors.py:170: Warning: (1280, u"Name 'alembic_version_pkc' ignored for PRIMARY key.")
  result = self._query(query)
INFO  [alembic.runtime.migration] Running upgrade  -> liberty, liberty initial
INFO  [alembic.runtime.migration] Running upgrade liberty -> mitaka01, add index on created_at and updated_at columns of 'images' table
INFO  [alembic.runtime.migration] Running upgrade mitaka01 -> mitaka02, update metadef os_nova_server
INFO  [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_expand01, add visibility to images
INFO  [alembic.runtime.migration] Running upgrade ocata_expand01 -> pike_expand01, empty expand for symmetry with pike_contract01
INFO  [alembic.runtime.migration] Running upgrade pike_expand01 -> queens_expand01
INFO  [alembic.runtime.migration] Running upgrade queens_expand01 -> rocky_expand01, add os_hidden column to images table
INFO  [alembic.runtime.migration] Running upgrade rocky_expand01 -> rocky_expand02, add os_hash_algo and os_hash_value columns to images table
INFO  [alembic.runtime.migration] Running upgrade rocky_expand02 -> train_expand01, empty expand for symmetry with train_contract01
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: train_expand01, current revision(s): train_expand01
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Database migration is up to date. No migration needed.
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_contract01, remove is_public from images
INFO  [alembic.runtime.migration] Running upgrade ocata_contract01 -> pike_contract01, drop glare artifacts tables
INFO  [alembic.runtime.migration] Running upgrade pike_contract01 -> queens_contract01
INFO  [alembic.runtime.migration] Running upgrade queens_contract01 -> rocky_contract01
INFO  [alembic.runtime.migration] Running upgrade rocky_contract01 -> rocky_contract02
INFO  [alembic.runtime.migration] Running upgrade rocky_contract02 -> train_contract01
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: train_contract01, current revision(s): train_contract01
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Database is synced successfully.

4、开启glance服务

[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

5、查看端口

[root@ct glance]# netstat -anpt |grep 9292
tcp        0      0 0.0.0.0:9292            0.0.0.0:*               LISTEN      54679/python2

6、授予openstack-glance-api.service对存储目录的可写权限

[root@ct ~]# chown -hR glance:glance /var/lib/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       | 2020-12-19T13:36:22Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/3a95b0f9-1082-4451-b489-d01afecf9199/file                                                                                                                                       |
| id               | 3a95b0f9-1082-4451-b489-d01afecf9199                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | cirros                                                                                                                                                                                     |
| owner            | ef5a0f088efb43b482d09ddf47dfd808                                                                                                                                                           |
| 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       | 2020-12-19T13:36:23Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | public                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

查看刚刚创建的镜像,有两种方式

[root@ct ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 3a95b0f9-1082-4451-b489-d01afecf9199 | cirros | active |
+--------------------------------------+--------+--------+
[root@ct ~]# glance image-list
+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| 3a95b0f9-1082-4451-b489-d01afecf9199 | cirros |
+--------------------------------------+--------+

虚拟机运行时需要镜像的支持,所以在openstack上创建虚拟机,要先行部署,首先得创建glance数据库并对其授权,然后创建open stack用户,授权并管理,其次配置glance(修改glance-api.conf、glance-registry.conf),最后初始化数据库,上传实例镜像即可使用Glance服务。

【腾讯云】云产品限时秒杀,爆款1核2G云服务器,首年99元

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenStack中,RabbitMQ是消息代理的核心组件,负责处理各种消息,包括API请求、队列通信和通知。为了保证高可用性和可扩展性,我们可以将RabbitMQ部署为集群。 以下是在OpenStack部署RabbitMQ集群的步骤: 1. 安装RabbitMQ软件包 在每个节点上安装RabbitMQ软件包。可以使用以下命令进行安装: ``` sudo apt-get install rabbitmq-server ``` 2. 配置RabbitMQ 在每个节点上,编辑RabbitMQ配置文件/etc/rabbitmq/rabbitmq-env.conf,指定以下环境变量: ``` NODE_IP_ADDRESS=<本地IP> NODE_PORT=5672 CLUSTER_WITH=<其他节点IP> ``` 其中,NODE_IP_ADDRESS是本地IP地址,CLUSTER_WITH是其他节点的IP地址。这些变量将用于RabbitMQ节点间通信。 3. 启用RabbitMQ插件 在每个节点上启用RabbitMQ集群插件。可以使用以下命令启用插件: ``` sudo rabbitmq-plugins enable rabbitmq_management rabbitmq_peer_discovery_aws ``` 4. 启动RabbitMQ节点 在每个节点上启动RabbitMQ节点。可以使用以下命令启动节点: ``` sudo rabbitmq-server -detached ``` 5. 将节点加入集群 在任何一个节点上,执行以下命令将节点加入集群: ``` sudo rabbitmqctl stop_app sudo rabbitmqctl join_cluster rabbit@<其他节点名称> sudo rabbitmqctl start_app ``` 其中,<其他节点名称>是集群中的其他节点的名称。 6. 验证集群状态 在任何一个节点上,执行以下命令验证集群状态: ``` sudo rabbitmqctl cluster_status ``` 如果输出包含所有节点的信息,则集群已成功部署。 注意:在部署RabbitMQ集群时,需要确保集群节点之间的网络连接正常,并且防火墙已正确配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值