当前位置:   article > 正文

云计算|OpenStack|社区版OpenStack安装部署文档(四 --- 镜像服务glance安装部署---Rocky版)_openstack安装glance

openstack安装glance

前言:

1,glance作用和特性

用户使用镜像服务 (glance) 允许来创建,查询虚拟机镜像。它提供了一个 REST API,允许查询虚拟机镜像的 metadata 并获取一个现存的镜像

可以将虚拟机镜像存储到各种位置,如简单的文件系统或者是对象存储系统,例如 OpenStack 对象存储, 并通过镜像服务使用

上传指定的文件作为后端配置镜像服务,默认目录是 /var/lib/glance/images/

(glance)使用户能够发现、注册和检索虚拟机映像。它提供了一个REST API,使您能够查询虚拟机映像元数据并检索实际映像。您可以将通过映像服务提供的虚拟机映像存储在各种位置,从简单的文件系统到OpenStack对象存储等对象存储系统。总的来说,就是一个专门管理镜像的服务。

,2,glance镜像服务的组件

glance-api:

用于接收镜像REST API的调用,诸如镜像查找,获取,上传,删除

glance-registry:

用于与mysql数据库交互,监听端口为9191,

提供镜像元数据相关的REST接口,用于存储、处理和恢复镜像的元数据(metadata),元数据包括项诸如大小和类型。
通过glance-registry可以向数据库中写入或获取镜像的各种数据
其中有两张表,image表保存了镜像格式大小等信息,image property表保存进行的定制化信息
注意:glance-registry是私有内部服务,用于服务OpenStack Image服务。不能向用户暴露

image:镜像文件的存储仓库

支持多种类型的仓库,它们有普通文件系统、对象存储、RADOS块设备、HTTP、以及亚马逊S3。另外,其中一些仓库仅支持只读方式使用。

image store:

是一个存储的接口层,通过这个接口glance可以获取镜像,支持的存储有亚马逊的S3,openstack本身的swift,还有ceph,sheepdog,GlusterFS等分布式存储
image store是镜像保存与获取的接口,仅仅是一个接口层,具体的实现需要外部的存储支持

数据库:

存放镜像元数据,用户是可以依据个人喜好选择数据库的,多数的部署使用MySQL或SQLite,本例使用的是mariadb

元数据定义服务:

通用的API,是用于为厂商,管理员,服务,以及用户自定义元数据。
这种元数据可用于不同的资源,例如镜像,工件,卷,配额以及集合。
一个定义包括了新属性的键,描述,约束以及可以与之关联的资源的类型。

本文将基于官方文档来部署,并根据自己的实际情况进行修改说明。

官方文档链接:OpenStack Docs: Install and configure (Red Hat)

一,

数据库初始化

登陆MySQL,运行以下SQL语句:

创建glance服务使用的数据库,创建数据库用户glance并赋予数据库操作权限

  1. create database glance;
  2. GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance123456';
  3. GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance123456';
  4. flush privileges;

二,

在keystone上面注册glance

1,

Create the glance user

openstack user create --domain default --password=glance glance

输出如下:

  1. +---------------------+----------------------------------+
  2. | Field | Value |
  3. +---------------------+----------------------------------+
  4. | domain_id | default |
  5. | enabled | True |
  6. | id | 889842492a2f45cc9ddc5d1eae2d64f1 |
  7. | name | glance |
  8. | options | {} |
  9. | password_expires_at | None |
  10. +---------------------+----------------------------------+

2,

在keystone上将glance用户添加为service项目的admin角色(权限)

  1. openstack role add --project service --user glance admin
  2. #注:此命令无输出为正确

3,

创建glance镜像服务的实体

在创建前,我们先看一下有哪些service(服务),就一个keystone

  1. [root@openstack1 ~]# openstack service list
  2. +----------------------------------+----------+----------+
  3. | ID | Name | Type |
  4. +----------------------------------+----------+----------+
  5. | 0aefcadb64fc4bdc8195f5a9df0cc516 | keystone | identity |
  6. +----------------------------------+----------+----------+

OK,创建一个glance相关的service:

  1. openstack service create --name glance --description "OpenStack Image" image
  2. openstack service list

输出如下:

可以看到多了一个service

  1. [root@openstack1 ~]# openstack service create --name glance --description "OpenStack Image" image
  2. +-------------+----------------------------------+
  3. | Field | Value |
  4. +-------------+----------------------------------+
  5. | description | OpenStack Image |
  6. | enabled | True |
  7. | id | 4fb6e6f07d5041deb8c3e317f54f8f6c |
  8. | name | glance |
  9. | type | image |
  10. +-------------+----------------------------------+
  11. [root@openstack1 ~]# openstack service list
  12. +----------------------------------+----------+----------+
  13. | ID | Name | Type |
  14. +----------------------------------+----------+----------+
  15. | 0aefcadb64fc4bdc8195f5a9df0cc516 | keystone | identity |
  16. | 4fb6e6f07d5041deb8c3e317f54f8f6c | glance | image |
  17. +----------------------------------+----------+----------+

4,创建glance服务的检查点:

注:这个地方还是和老版本一样,没有改变,不过一般也是不会出错的,注意是192.168.123.130的主机名 openstack1

  1. openstack endpoint create --region RegionOne image public http://openstack1:9292
  2. openstack endpoint create --region RegionOne image internal http://openstack1:9292
  3. openstack endpoint create --region RegionOne image admin http://openstack1:9292

输出如下:

  1. [root@openstack1 ~]# openstack endpoint create --region RegionOne image public http://openstack1:9292
  2. +--------------+----------------------------------+
  3. | Field | Value |
  4. +--------------+----------------------------------+
  5. | enabled | True |
  6. | id | 0dff640b6887445c91f6b697d38b63f3 |
  7. | interface | public |
  8. | region | RegionOne |
  9. | region_id | RegionOne |
  10. | service_id | 4fb6e6f07d5041deb8c3e317f54f8f6c |
  11. | service_name | glance |
  12. | service_type | image |
  13. | url | http://openstack1:9292 |
  14. +--------------+----------------------------------+
  15. [root@openstack1 ~]# openstack endpoint create --region RegionOne image internal http://openstack1:9292
  16. +--------------+----------------------------------+
  17. | Field | Value |
  18. +--------------+----------------------------------+
  19. | enabled | True |
  20. | id | 23bb125457d54ee18d384c37596854ea |
  21. | interface | internal |
  22. | region | RegionOne |
  23. | region_id | RegionOne |
  24. | service_id | 4fb6e6f07d5041deb8c3e317f54f8f6c |
  25. | service_name | glance |
  26. | service_type | image |
  27. | url | http://openstack1:9292 |
  28. +--------------+----------------------------------+
  29. [root@openstack1 ~]# openstack endpoint create --region RegionOne image public http://openstack1:9292
  30. +--------------+----------------------------------+
  31. | Field | Value |
  32. +--------------+----------------------------------+
  33. | enabled | True |
  34. | id | 0bd355f15aaa4526a4a306f212a9471f |
  35. | interface | public |
  36. | region | RegionOne |
  37. | region_id | RegionOne |
  38. | service_id | 4fb6e6f07d5041deb8c3e317f54f8f6c |
  39. | service_name | glance |
  40. | service_type | image |
  41. | url | http://openstack1:9292 |
  42. +--------------+----------------------------------+

查询检查点:

总共是六个endpoint,表示正确,不能多也不能少

  1. [root@openstack1 ~]# openstack endpoint list
  2. +----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+
  3. | ID | Region | Service Name | Service Type | Enabled | Interface | URL |
  4. +----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+
  5. | 09fb81fcb9fd48a2b24acd4874bddc76 | RegionOne | glance | image | True | internal | http://openstack1:9292 |
  6. | 4199c37c0d2c4e6990899581538987d3 | RegionOne | glance | image | True | admin | http://openstack1:9292 |
  7. | 900b2ea657b04c4d89cf740bb3c74050 | RegionOne | keystone | identity | True | public | http://openstack1:5000/v3/ |
  8. | 9e03fca7bea64ecf8c89abc4459142c4 | RegionOne | keystone | identity | True | internal | http://openstack1:5000/v3/ |
  9. | b276b0e8921e4d879c3cac5f7c4256bf | RegionOne | glance | image | True | public | http://openstack1:9292 |
  10. | ba2d3158fd724aa19a009131a9d6b864 | RegionOne | keystone | identity | True | admin | http://openstack1:5000/v3/ |
  11. +----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+

如果某个endpoint创建的时候错误了,比如手抖写错了或者重复创建了(允许重复创建,创建的记录在MySQL数据库内),可以删除,删除命令为:

  1. openstack endpoint delete ID
  2. 例如删除第一个:
  3. openstack endpoint delete 09fb81fcb9fd48a2b24acd4874bddc76

以上的步骤都是写入到了keystone这个数据库内了,这里不要搞错了,不是glance数据库,glance数据库还没开始使用 

# 至此,glance在keystone上面注册完成,可以进行下一步的安装

三,

安装glance相关软件

1,

Python的版本问题

#这里不能使用Python3,必须使用Python2.7或者非Python-3.5

# 在当前版本中有一个bug在Python3.5中可能会有ssl方面的问题,以下是详情页面

2,

安装软件:

yum install openstack-glance python-glance python-glanceclient -y

3,

修改glance服务的配置文件

这里采用一个快速修改的方式,使用openstack-utils:

glance-api服务:

主要是需要仔细核对用户和密码以及主机名,例如,第一行的数据库密码不能错了,否则后面建表可能会失败的哦

  1. openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:glance123456@openstack1/glance
  2. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://openstack1:5000
  3. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://openstack1:5000
  4. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers openstack1:11211
  5. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
  6. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
  7. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
  8. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
  9. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
  10. openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password glance
  11. openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
  12. openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
  13. openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
  14. openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/

glance-registry服务:

  1. openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:glance123456@openstack1/glance
  2. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://openstack1:5000
  3. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://openstack1:5000
  4. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers openstack1:11211
  5. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password
  6. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default
  7. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default
  8. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service
  9. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance
  10. openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password glance
  11. openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone

核对配置文件:

  1. [root@openstack1 ~]# grep '^[a-z]' /etc/glance/glance-api.conf
  2. connection = mysql+pymysql://glance:glance_DBPASS@openstack1/glance
  3. stores = file,http
  4. default_store = file
  5. filesystem_store_datadir = /var/lib/glance/images/
  6. www_authenticate_uri = http://openstack1:5000
  7. auth_url = http://openstack1:5000
  8. memcached_servers = openstack1:11211
  9. auth_type = password
  10. project_domain_name = Default
  11. user_domain_name = Default
  12. project_name = service
  13. username = glance
  14. password = glance
  15. flavor = keystone
  1. [root@openstack1 ~]# grep '^[a-z]' /etc/glance/glance-registry.conf
  2. connection = mysql+pymysql://glance:glance_DBPASS@openstack1/glance
  3. www_authenticate_uri = http://openstack1:5000
  4. auth_url = http://openstack1:5000
  5. memcached_servers = openstack1:11211
  6. auth_type = password
  7. project_domain_name = Default
  8. user_domain_name = Default
  9. project_name = service
  10. username = glance
  11. password = glance
  12. flavor = keystone

四,

初始化同步glance数据库

如果有任何问题,比如,下面这个命令失败,可以查看日志文件:/var/log/glance/api.log

su -s /bin/sh -c "glance-manage db_sync" glance

输出如下:

这个警告可以忽略的

  1. root@openstack1 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
  2. /usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1352: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade
  3. expire_on_commit=expire_on_commit, _conf=conf)
  4. INFO [alembic.runtime.migration] Context impl MySQLImpl.
  5. INFO [alembic.runtime.migration] Will assume non-transactional DDL.
  6. INFO [alembic.runtime.migration] Running upgrade -> liberty, liberty initial
  7. INFO [alembic.runtime.migration] Running upgrade liberty -> mitaka01, add index on created_at and updated_at columns of 'images' table
  8. INFO [alembic.runtime.migration] Running upgrade mitaka01 -> mitaka02, update metadef os_nova_server
  9. INFO [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_expand01, add visibility to images
  10. INFO [alembic.runtime.migration] Running upgrade ocata_expand01 -> pike_expand01, empty expand for symmetry with pike_contract01
  11. INFO [alembic.runtime.migration] Running upgrade pike_expand01 -> queens_expand01
  12. INFO [alembic.runtime.migration] Running upgrade queens_expand01 -> rocky_expand01, add os_hidden column to images table
  13. INFO [alembic.runtime.migration] Running upgrade rocky_expand01 -> rocky_expand02, add os_hash_algo and os_hash_value columns to images table
  14. INFO [alembic.runtime.migration] Context impl MySQLImpl.
  15. INFO [alembic.runtime.migration] Will assume non-transactional DDL.
  16. Upgraded database to: rocky_expand02, current revision(s): rocky_expand02
  17. INFO [alembic.runtime.migration] Context impl MySQLImpl.
  18. INFO [alembic.runtime.migration] Will assume non-transactional DDL.
  19. INFO [alembic.runtime.migration] Context impl MySQLImpl.
  20. INFO [alembic.runtime.migration] Will assume non-transactional DDL.
  21. Database migration is up to date. No migration needed.
  22. INFO [alembic.runtime.migration] Context impl MySQLImpl.
  23. INFO [alembic.runtime.migration] Will assume non-transactional DDL.
  24. INFO [alembic.runtime.migration] Context impl MySQLImpl.
  25. INFO [alembic.runtime.migration] Will assume non-transactional DDL.
  26. INFO [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_contract01, remove is_public from images
  27. INFO [alembic.runtime.migration] Running upgrade ocata_contract01 -> pike_contract01, drop glare artifacts tables
  28. INFO [alembic.runtime.migration] Running upgrade pike_contract01 -> queens_contract01
  29. INFO [alembic.runtime.migration] Running upgrade queens_contract01 -> rocky_contract01
  30. INFO [alembic.runtime.migration] Running upgrade rocky_contract01 -> rocky_contract02
  31. INFO [alembic.runtime.migration] Context impl MySQLImpl.
  32. INFO [alembic.runtime.migration] Will assume non-transactional DDL.
  33. Upgraded database to: rocky_contract02, current revision(s): rocky_contract02
  34. INFO [alembic.runtime.migration] Context impl MySQLImpl.
  35. INFO [alembic.runtime.migration] Will assume non-transactional DDL.
  36. Database is synced successfully.

查看创建的新表,总计应该是15个:

  1. [root@openstack1 ~]# mysql -uglance -pglance123456 -e 'use glance;show tables'
  2. +----------------------------------+
  3. | Tables_in_glance |
  4. +----------------------------------+
  5. | alembic_version |
  6. | image_locations |
  7. | image_members |
  8. | image_properties |
  9. | image_tags |
  10. | images |
  11. | metadef_namespace_resource_types |
  12. | metadef_namespaces |
  13. | metadef_objects |
  14. | metadef_properties |
  15. | metadef_resource_types |
  16. | metadef_tags |
  17. | migrate_version |
  18. | task_info |
  19. | tasks |
  20. +----------------------------------+
  21. [root@openstack1 ~]# mysql -uglance -pglance123456 -e 'use glance;show tables' |wc -l
  22. 16

5,

启动两个glance服务,并加入自启:

  1. systemctl enable openstack-glance-api.service openstack-glance-registry.service
  2. systemctl start openstack-glance-api.service openstack-glance-registry.service

五,

测试glance服务是否正常

#可以下载小型的Linux镜像CirrOS用来进行 OpenStack部署测试。

# 下载地址:Index of /

wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img

 上传上面下载的镜像到glance服务上,并设置公共可见:

openstack image create "cirros" --file cirros-0.3.4-x86_64-disk.img  --disk-format qcow2 --container-format bare --public

输出如下:

  1. [root@openstack1 ~]# openstack image create "cirros" --file cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --public
  2. +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  3. | Field | Value |
  4. +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  5. | checksum | ee1eca47dc88f4879d8a229cc70a07c6 |
  6. | container_format | bare |
  7. | created_at | 2023-01-31T14:11:12Z |
  8. | disk_format | qcow2 |
  9. | file | /v2/images/62ed12e2-c3d5-4e9b-bf6b-e0db99e8d2c1/file |
  10. | id | 62ed12e2-c3d5-4e9b-bf6b-e0db99e8d2c1 |
  11. | min_disk | 0 |
  12. | min_ram | 0 |
  13. | name | cirros |
  14. | owner | 7f8efc46f33a40769cf4a4dbad676b77 |
  15. | properties | os_hash_algo='sha512', os_hash_value='1b03ca1bc3fafe448b90583c12f367949f8b0e665685979d95b004e48574b953316799e23240f4f739d1b5eb4c4ca24d38fdc6f4f9d8247a2bc64db25d6bbdb2', os_hidden='False' |
  16. | protected | False |
  17. | schema | /v2/schemas/image |
  18. | size | 13287936 |
  19. | status | active |
  20. | tags | |
  21. | updated_at | 2023-01-31T14:11:13Z |
  22. | virtual_size | None |
  23. | visibility | public |
  24. +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

OK,通过glance服务,查询镜像,能查到证明上传镜像功能没有问题:

  1. [root@openstack1 ~]# openstack image list
  2. +--------------------------------------+--------+--------+
  3. | ID | Name | Status |
  4. +--------------------------------------+--------+--------+
  5. | 62ed12e2-c3d5-4e9b-bf6b-e0db99e8d2c1 | cirros | active |
  6. +--------------------------------------+--------+--------+

至此,glance服务安装部署完毕,下一个章节将安装部署nova服务

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/306937
推荐阅读
相关标签
  

闽ICP备14008679号