近期在学习OpenStack,分享一下Rocky版本的OpenStack安装过程,请各位大佬多多关注,不当之处望斧正。

      本小节分享Glance组件的安装配置。接上小节:CentOS7-徒手安装OpenStack(Rocky版)系列-02-Keystone认证组件安装配置

***本节操作命令均在控制节点执行****


1. 基本概念

    Glance是OpenStack中提供镜像服务(Image Service)的组件,主要是给用户提供创建、查询虚拟机镜像的metadata并获取一个现存的镜像(image)。其具体功能为:

  • 提供REST API,让用户能够查询和获取image的元数据和image本身。
  • 支持多种方式存储image,包括普通的文件系统,Swift、Amazon S3,文件存储等。
  • 对Instance执行Snapshot 创建新的image。

    通过镜像服务使用上传指定的文件作为后端配置镜像服务,将虚拟机镜像存储到指定位置,默认目录是 /var/lib/glance/images/

1.1 Glance的架构

open stack 安装 placement常用相关命令 openstack组件安装_openstack rocky 安装

(1)Glance API

    glance-api是系统后台运行的服务进程,对外提供REST API,响应image査询、获取和存储的调用,glance-api不会真正处理请求。如果是与image metadata (元数据)相关的操作,glance-api会把请求转发给glance-registry;如果是与image自身存取相关的操作,glance-api会把请求转发给该image的store backend。

(2)Glance registry

    glance-registry是系统后台运行的服务进程,用于与数据库交互,用于存储、处理和恢复镜像的元数据(metadata),元数据包括项诸如大小和类型。通过glance-registry可以向数据库中写入或获取镜像的各种数据,其中有两张表,image表保存了镜像格式大小等信息,image property表保存进行的定制化信息。

    Glance支持多种格式的image,包括:

  • raw – 非结构化的镜像格式
  • vhd – 一种通用的虚拟机磁盘格式, 可用于Vmware、Xen、Microsoft Virtual PC/Virtual Server/Hyper-V、VirtualBox等。
  • vmdk – Vmware的虚拟机磁盘格式, 同样也支持多种Hypervisor
  • vdi – VirtualBox、QEMU等支持的虚拟机磁盘格式
  • iso – 光盘存档格式
  • qcow2 – 一种支持QEMU并且可以动态扩展的磁盘格式
  • aki – Amazon Kernel 镜像
  • ari – Amazon Ramdisk 镜像
  • ami – Amazon 虚拟机镜像

(3)Database

    用来存放image的metadata,默认为MySQL 数据库。

(4)Image  Store

    Image Store是一个存储的接口层,通过这个接口,glance可以获取镜像,Image Store支持有Amazon的S3,OpenStack本身的swift,还有诸如ceph,GlusterFS等分布式存储。Image Store仅仅是一个接口处,具体的实现需要外部的存储支持。具体使用哪种存储是在/etc/glance/glance-api.conf中配置的。

2.  安装Glance

2.1 创建glance数据库

#To create the database
[root@controller ~]# mysql -predhat
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.20-MariaDB MariaDB Server
Copyright (c) 2000, 2016, 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.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| glance             |
| information_schema |
| keystone           |
| mysql              |
| performance_schema |
+--------------------+
5 rows in set (0.01 sec)
MariaDB [(none)]> exit
Bye
[root@controller ~]

2.2 在Keystone上注册Glance

(1)在keystone上创建glance用户
[root@controller ~]# cd /server/tools/
[root@controller tools]# source keystone-admin-pass.sh
[root@controller tools]# openstack user create --domain default --password=glance glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 417263d5a1d44e7486a52f5466794b57 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
[root@controller tools]# openstack user list
+----------------------------------+--------+
| ID                               | Name   |
+----------------------------------+--------+
| 07d8304d0e7346f5940e3b7842f88f2d | myuser |
| 417263d5a1d44e7486a52f5466794b57 | glance |
| 7129dac220e041acabf74d8f722bc080 | admin  |
+----------------------------------+--------+
(2)在keystone上将glance用户添加为service项目的admin角色
[root@controller tools]# openstack role add --project service --user glance admin
(3)创建镜像服务的实体
[root@controller tools]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 0360d744466f45028fd796a2eb2d77d4 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
[root@controller tools]#  openstack service list
+----------------------------------+----------+----------+
| ID                               | Name     | Type     |
+----------------------------------+----------+----------+
| 0360d744466f45028fd796a2eb2d77d4 | glance   | image    |
| 16f472518085448da6542ff821e1e6d0 | keystone | identity |
+----------------------------------+----------+----------+
(4)创建镜像服务的API 端点-API endpoints
# 在endpoint表增加3条项目
[root@controller tools]# openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 58a5d5b3bb034bac8f7aae27d7b2ebd4 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 0360d744466f45028fd796a2eb2d77d4 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@controller tools]# openstack endpoint create --region RegionOne image internal http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | b330695be0684de0b2e92ef7b71a31f0 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 0360d744466f45028fd796a2eb2d77d4 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@controller tools]# openstack endpoint create --region RegionOne image admin http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 488dbbe8394142a38901fbb4eba0f92e |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 0360d744466f45028fd796a2eb2d77d4 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@controller tools]# openstack endpoint list
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+
| ID                               | Region    | Service Name | Service Type | Enabled | Interface | URL                        |
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+
| 488dbbe8394142a38901fbb4eba0f92e | RegionOne | glance       | image        | True    | admin     | http://controller:9292     |
| 58a5d5b3bb034bac8f7aae27d7b2ebd4 | RegionOne | glance       | image        | True    | public    | http://controller:9292     |
| 7a635e94e3b2405e80bf0d8ac1797635 | RegionOne | keystone     | identity     | True    | internal  | http://controller:5000/v3/ |
| 9611f6055bba4ccd988c0b3e899962d6 | RegionOne | keystone     | identity     | True    | public    | http://controller:5000/v3/ |
| b330695be0684de0b2e92ef7b71a31f0 | RegionOne | glance       | image        | True    | internal  | http://controller:9292     |
| ea048b8741a444abb6dad98648c4cbb9 | RegionOne | keystone     | identity     | True    | admin     | http://controller:5000/v3/ |
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+
#glance在keystone上面注册完成,可以进行安装

2.3 安装Glance相关软件

(1)检查python版本,在当前版本中有一个bug在Python3.5中可能会有ssl方面的问题,以下是详情页面:https://docs.openstack.org/glance/rocky/install/get-started.html#running-glance-under-python3

[root@controller tools]# python --version

Python 2.7.5

(2)安装glance软件

[root@controller tools]# yum install openstack-glance python-glance python-glanceclient -y

(3)编辑/etc/glance/glance-api.conf 文件

###安装openstack-utils  使用openstack-config 快速配置
[root@controller ~]# yum install -y openstack-utils
###
openstack-config --set  /etc/glance/glance-api.conf database connection  mysql+pymysql://glance:glance@controller/glance
openstack-config --set  /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://controller:5000
openstack-config --set  /etc/glance/glance-api.conf keystone_authtoken auth_url http://controller:5000
openstack-config --set  /etc/glance/glance-api.conf keystone_authtoken memcached_servers  controller: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
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@controller ~]# grep '^[a-z]' /etc/glance/glance-api.conf
connection = mysql+pymysql://glance:glance@controller/glance
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = glance
flavor = keystone
[root@controller ~]#
(4)编辑/etc/glance/glance-registry.conf文件
openstack-config --set  /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:glance@controller/glance
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://controller:5000
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken auth_url http://controller:5000
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken memcached_servers controller:11211
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken auth_type password
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken project_name service
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken username glance
openstack-config --set  /etc/glance/glance-registry.conf keystone_authtoken password glance
openstack-config --set  /etc/glance/glance-registry.conf paste_deploy flavor keystone
###查看生效的配置
[root@controller ~]# grep '^[a-z]' /etc/glance/glance-registry.conf
connection = mysql+pymysql://glance:glance@controller/glance
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = glance
flavor = keystone
[root@controller ~]#
###以上,glance服务安装完毕,该服务需要启动

2.4 同步Glance数据库

(1)# 生成的相关表(15张表)
[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance
/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1352: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade
  expire_on_commit=expire_on_commit, _conf=conf)
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
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] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: rocky_expand02, current revision(s): rocky_expand02
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] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: rocky_contract02, current revision(s): rocky_contract02
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Database is synced successfully
(2)进行连接测试
[root@controller ~]# mysql -h192.168.137.100 -uglance -pglance -e "use glance;show tables;"+----------------------------------+
| Tables_in_glance                 |
+----------------------------------+
| alembic_version                  |
| image_locations                  |
| image_members                    |
| image_properties                 |
| image_tags                       |
| images                           |
| metadef_namespace_resource_types |
| metadef_namespaces               |
| metadef_objects                  |
| metadef_properties               |
| metadef_resource_types           |
| metadef_tags                     |
| migrate_version                  |
| task_info                        |
| tasks                            |
+----------------------------------+
[root@controller ~]# mysql -h192.168.137.100 -uglance -pglance -e "use glance;show tables;" | wc -l
16
[root@controller ~]#

2.5 启动Glance数据库

(1)启动并设置为开机启动
[root@controller ~]# systemctl start openstack-glance-api.service openstack-glance-registry.service
[root@controller ~]# systemctl status openstack-glance-api.service openstack-glance-registry.service
● openstack-glance-api.service - OpenStack Image Service (code-named Glance) API server
   Loaded: loaded (/usr/lib/systemd/system/openstack-glance-api.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-06-13 13:06:04 CST; 7s ago
Main PID: 5814 (glance-api)
   CGroup: /system.slice/openstack-glance-api.service
           ├─5814 /usr/bin/python2 /usr/bin/glance-api
           ├─5842 /usr/bin/python2 /usr/bin/glance-api
           ├─5843 /usr/bin/python2 /usr/bin/glance-api
           └─5844 /usr/bin/python2 /usr/bin/glance-api
Jun 13 13:06:06 controller.fzxz686.com glance-api[5814]: /usr/lib/python2.7/site-packag....
Jun 13 13:06:06 controller.fzxz686.com glance-api[5814]: return pkg_resources.EntryPoin...)
Jun 13 13:06:06 controller.fzxz686.com glance-api[5814]: /usr/lib/python2.7/site-packag....
Jun 13 13:06:06 controller.fzxz686.com glance-api[5814]: return pkg_resources.EntryPoin...)
Jun 13 13:06:08 controller.fzxz686.com glance-api[5814]: /usr/lib/python2.7/site-packag....
Jun 13 13:06:08 controller.fzxz686.com glance-api[5814]: return pkg_resources.EntryPoin...)
Jun 13 13:06:08 controller.fzxz686.com glance-api[5814]: /usr/lib/python2.7/site-packag....
Jun 13 13:06:08 controller.fzxz686.com glance-api[5814]: return pkg_resources.EntryPoin...)
Jun 13 13:06:08 controller.fzxz686.com glance-api[5814]: /usr/lib/python2.7/site-packag...r
Jun 13 13:06:08 controller.fzxz686.com glance-api[5814]: val = callable(*args, **kw)
● openstack-glance-registry.service - OpenStack Image Service (code-named Glance) Registry server
   Loaded: loaded (/usr/lib/systemd/system/openstack-glance-registry.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2020-06-13 13:06:04 CST; 6s ago
Main PID: 5815 (glance-registry)
   CGroup: /system.slice/openstack-glance-registry.service
           ├─5815 /usr/bin/python2 /usr/bin/glance-registry
           ├─5837 /usr/bin/python2 /usr/bin/glance-registry
           ├─5838 /usr/bin/python2 /usr/bin/glance-registry
           └─5839 /usr/bin/python2 /usr/bin/glance-registry
Jun 13 13:06:06 controller.fzxz686.com glance-registry[5815]: /usr/lib/python2.7/site-pa...
Jun 13 13:06:06 controller.fzxz686.com glance-registry[5815]: return pkg_resources.Entry...
Jun 13 13:06:06 controller.fzxz686.com glance-registry[5815]: /usr/lib/python2.7/site-pa...
Jun 13 13:06:06 controller.fzxz686.com glance-registry[5815]: return pkg_resources.Entry...
Jun 13 13:06:07 controller.fzxz686.com glance-registry[5815]: /usr/lib/python2.7/site-pa...
Jun 13 13:06:07 controller.fzxz686.com glance-registry[5815]: return pkg_resources.Entry...
Jun 13 13:06:08 controller.fzxz686.com glance-registry[5815]: /usr/lib/python2.7/site-pa...
Jun 13 13:06:08 controller.fzxz686.com glance-registry[5815]: debtcollector.deprecate("G...
Jun 13 13:06:08 controller.fzxz686.com glance-registry[5815]: /usr/lib/python2.7/site-pa...
Jun 13 13:06:08 controller.fzxz686.com glance-registry[5815]: val = callable(*args, **kw)
Hint: Some lines were ellipsized, use -l to show in full.
[root@controller ~]#
[root@controller ~]# systemctl enable openstack-glance-api.service openstack-glance-registry.service
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-api.service to /usr/lib/systemd/system/openstack-glance-api.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service to /usr/lib/systemd/system/openstack-glance-registry.service.
[root@controller ~]# systemctl list-unit-files |grep openstack-glance*
openstack-glance-api.service                  enabled
openstack-glance-registry.service             enabled
openstack-glance-scrubber.service             disabled

2.6 检查确认安装正常

# 可以下载小型的Linux镜像CirrOS用来进行 OpenStack部署测试。
# 下载地址:http://download.cirros-cloud.net/
(1)下载镜像
从本地下载后,通过ftp的方式上传到服务器上
[root@controller tools]# ll
total 12968
-rw-r--r--. 1 root root 13267968 Jun 13 14:22 cirros-0.3.5-x86_64-disk.img
-rw-r--r--. 1 root root      261 Jun 12 17:26 keystone-admin-pass.sh
-rw-r--r--. 1 root root      266 Jun 12 17:27 keystone-myuser-pass.sh
[root@controller tools]# pwd
/server/tools
[root@controller tools]#
(2)上传镜像到glance
##使用qcow2磁盘格式, bare容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它
[root@controller tools]# source keystone-admin-pass.sh
[root@controller tools]# openstack image create "cirros" --file cirros-0.3.5-x86_64-disk.img --disk-format qcow2 --container-format bare --public
(3)查看镜像
[root@controller tools]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| a2a552a4-5c47-4746-91cc-0d3a499e08ba | cirros | active |
+--------------------------------------+--------+--------+

#以上,可以看到上传的镜像,Glance组件安装配置完成。

参考文档:  

https://docs.openstack.org/glance/rocky/install/get-started.html

-------------END------------

作者:疯子行者