• OpenStack+CentOS7.6 云平台环境搭建 — 3.镜像服务(glance)


    摘要

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

    为简单起见,本指南介绍如何配置Image服务以使用文件后端,该文件后端上载并存储在托管Image服务的控制器节点上的目录中。默认情况下,此目录为/var/lib/glance/images/。
    在继续之前,请确保控制器节点在此目录中至少有几千兆字节的可用空间。 请记住,由于文件后端通常是控制器节点的本地,因此通常不适合多节点扫视部署。

    OpenStack镜像服务是IaaS的核心服务。
    它接受磁盘镜像或服务器镜像API请求,和来自终端用户或OpenStack计算组件的元数据定义。它也支持包括OpenStack对象存储在内的多种类型仓库上的磁盘镜像或服务器镜像存储。
    大量周期性进程运行于OpenStack镜像服务上以支持缓存。同步复制(Replication)服务保证集群中的一致性和可用性。其它周期性进程包括auditors, updaters, 和 reapers。

    一、Openstack镜像服务组件

    glance-api
    接收镜像API的调用,诸如镜像发现、恢复、存储。
    glance-registry
    存储、处理和恢复镜像的元数据,元数据包括项诸如大小和类型。
    数据库
    存放镜像元数据,用户是可以依据个人喜好选择数据库的,多数的部署使用MySQL或SQLite。
    镜像文件的存储仓库
    支持各种存储库类型,包括普通文件系统(或安装在glance-api控制器节点上的任何文件系统),对象存储,RADOS块设备,VMware数据存储区和HTTP。 请注意,某些存储库仅支持只读用法。
    元数据定义服务
    通用的API,是用于为厂商,管理员,服务,以及用户自定义元数据。这种元数据可用于不同的资源,例如镜像,工件,卷,配额以及集合。一个定义包括了新属性的键,描述,约束以及可以与之关联的资源的类型。

    二、安装和配置镜像服务

    这个部分描述如何在控制节点上安装和配置镜像服务,即 glance。简单来说,这个配置将镜像保存在本地文件系统中。

    2.1、环境描述

    主机名

    内存

    硬盘

    网卡

    系统

    ct

    8

    300+300

    VM1:192.168.100.100

    Centos7.6

    NAT:20.0.0.10

    c1

    8

    300+300

    VM1:192.168.100.101

    Centos7.6

    NAT:20.0.0.20

    c2

    8

    300+300

    VM1:192.168.100.102

    Centos7.6

    NAT:20.0.0.30

    安装和配置镜像服务之前,你必须创建创建一个数据库、服务凭证和API端点

    2.2、数据库创建glance用户并授权(ct上安装)

    1 [root@ct ~]# mysql -u root -p123456
    2 MariaDB [(none)]> CREATE DATABASE glance;
    3 MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS';
    4 MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';
    5 MariaDB [(none)]> flush privileges;
    6 MariaDB [(none)]> exit

    2.3、创建OpenStack的Glance用户

     1 创建用户前,需要首先执行管理员环境变量脚本(此处已经在~/.bashrc 中定义过了)
     2 [root@ct ~]# source ~/.bashrc
     3 
     4 创建glance用户
     5 [root@ct ~]# openstack user create --domain default --password GLANCE_PASS glance    
     6 +---------------------+----------------------------------+
     7 | Field | Value |
     8 +---------------------+----------------------------------+
     9 | domain_id | default |
    10 | enabled | True |
    11 | id | b2a6f8113a6b4ba6bf5e494ff69081dc |
    12 | name | glance |
    13 | options | {} |
    14 | password_expires_at | None |
    15 +---------------------+----------------------------------+
    16 
    17 将glance用户添加到service项目中,并且针对这个项目拥有admin权限;注册glance的API,需要对service项目有admin权限        
    18 [root@ct ~]# openstack role add --project service --user glance admin        
    19 
    20 创建一个service服务,service名称为glance,类型为image            
    21 [root@ct ~]# openstack service create --name glance --description "OpenStack Image" image
    22 +-------------+----------------------------------+
    23 | Field | Value |
    24 +-------------+----------------------------------+
    25 | description | OpenStack Image |
    26 | enabled | True |
    27 | id | 153a09217abe4aecbd324cd9372b1f9e |
    28 | name | glance |
    29 | type | image |
    30 +-------------+----------------------------------+
    31 
    32 openstack service list 查看
    33 [root@ct ~]# openstack service list
    34 +----------------------------------+----------+----------+
    35 | ID                               | Name     | Type     |
    36 +----------------------------------+----------+----------+
    37 | 28d6cc3387ff4b928cbec315405e21bc | glance   | image    |
    38 | e492b263a25c4d788b23bc8d15edd523 | keystone | identity |
    39 +----------------------------------+----------+----------+         

    2.4、创建镜像服务 API 端点

     1 OpenStack使用三种API端点代表三种服务:admin、internal、public
     2 [root@ct ~]# openstack endpoint create --region RegionOne image public http://ct:9292
     3 +--------------+----------------------------------+
     4 | Field | Value |
     5 +--------------+----------------------------------+
     6 | enabled | True |
     7 | id | 36495ec2b54a4a07a8cd83745a3a19b8 |
     8 | interface | public |
     9 | region | RegionOne |
    10 | region_id | RegionOne |
    11 | service_id | 153a09217abe4aecbd324cd9372b1f9e |
    12 | service_name | glance |
    13 | service_type | image |
    14 | url | http://ct:9292 |
    15 +--------------+----------------------------------+
    16 
    17 [root@ct ~]# openstack endpoint create --region RegionOne image internal http://ct:9292
    18 +--------------+----------------------------------+
    19 | Field | Value |
    20 +--------------+----------------------------------+
    21 | enabled | True |
    22 | id | 8a1893ba8035440f8e4a7bdc440ffef8 |
    23 | interface | internal |
    24 | region | RegionOne |
    25 | region_id | RegionOne |
    26 | service_id | 153a09217abe4aecbd324cd9372b1f9e |
    27 | service_name | glance |
    28 | service_type | image |
    29 | url | http://ct:9292 |
    30 +--------------+----------------------------------+
    31 
    32 [root@ct ~]# openstack endpoint create --region RegionOne image admin http://ct:9292
    33 +--------------+----------------------------------+
    34 | Field | Value |
    35 +--------------+----------------------------------+
    36 | enabled | True |
    37 | id | 59ee7ce4b50d4142b5a66c8ab3c8e01a |
    38 | interface | admin |
    39 | region | RegionOne |
    40 | region_id | RegionOne |
    41 | service_id | 153a09217abe4aecbd324cd9372b1f9e |
    42 | service_name | glance |
    43 | service_type | image |
    44 | url | http://ct:9292 |
    45 +--------------+----------------------------------+

    2.5、安装 openstack-glance 软件包

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

    2.6、修改glance配置文件

    ①修改glance-api.conf配置

     1 [root@ct ~]# cp -a /etc/glance/glance-api.conf{,.bak}
     2 [root@ct ~]# grep -Ev '^$|#' /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf
     3 openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
     4 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken www_authenticate_uri http://ct:5000
     5 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://ct:5000
     6 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers ct:11211
     7 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
     8 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name Default
     9 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name Default
    10 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
    11 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
    12 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password GLANCE_PASS
    13 openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
    14 openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
    15 openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
    16 openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/

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

     1 [root@ct ~]# cp -a /etc/glance/glance-registry.conf{,.bak}
     2 [root@ct ~]# grep -Ev '^$|#' /etc/glance/glance-registry.conf.bak > /etc/glance/glance-registry.conf
     3 openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:GLANCE_DBPASS@ct/glance
     4 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken www_authenticate_uri http://ct:5000
     5 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://ct:5000
     6 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers ct:11211
     7 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password
     8 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name Default
     9 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name Default
    10 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service
    11 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance
    12 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password GLANCE_PASS
    13 openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
    14 openstack-config --set /etc/glance/glance-registry.conf glance_store stores file,http
    15 openstack-config --set /etc/glance/glance-registry.conf glance_store default_store file
    16 openstack-config --set /etc/glance/glance-registry.conf glance_store filesystem_store_datadir /var/lib/glance/images/

    2.7、写入镜像服务数据库

     1 初始化glance数据库,生成相关表结构
     2 [root@ct ~]# su -s /bin/sh -c "glance-manage db_sync" glance
     3 ##省略部分内容
     4 Database is synced successfully.
     5 
     6 开启glance服务
     7 [root@ct ~]# systemctl enable openstack-glance-api.service 
     8 openstack-glance-registry.service
     9 [root@ct ~]# systemctl start openstack-glance-api.service 
    10 openstack-glance-registry.service
    11 
    12 查看端口
    13 [root@ct ~]# netstat -anpt | grep 9292
    14 tcp        0      0 0.0.0.0:9292            0.0.0.0:*               LISTEN      51412/python2    
    15 
    16 修改glance权限
    17 [root@ct ~]# chown -hR glance:glance /var/lib/glance/

    2.8、验证操作

     1 下载源镜像
     2 [root@ct ~]# wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
     3 
     4 使用 QCOW2 磁盘格式, bare 容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它
     5 [root@ct ~]# openstack image create "cirros" 
     6 --file cirros-0.3.5-x86_64-disk.img 
     7 --disk-format qcow2 --container-format bare 
     8 --public
     9 +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    10 | Field            | Value                                                                                                                                                                                      |
    11 +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    12 | checksum         | f8ab98ff5e73ebab884d80c9dc9c7290                                                                                                                                                           |
    13 | container_format | bare                                                                                                                                                                                       |
    14 | created_at       | 2020-12-18T06:00:51Z                                                                                                                                                                       |
    15 | disk_format      | qcow2                                                                                                                                                                                      |
    16 | file             | /v2/images/fd197925-4879-4330-aa57-b89f108973e0/file                                                                                                                                       |
    17 | id               | fd197925-4879-4330-aa57-b89f108973e0                                                                                                                                                       |
    18 | min_disk         | 0                                                                                                                                                                                          |
    19 | min_ram          | 0                                                                                                                                                                                          |
    20 | name             | cirros                                                                                                                                                                                     |
    21 | owner            | 370dfb2a30b8442d90e59a20b862655a                                                                                                                                                           |
    22 | properties       | os_hash_algo='sha512', os_hash_value='f0fd1b50420dce4ca382ccfbb528eef3a38bbeff00b54e95e3876b9bafe7ed2d6f919ca35d9046d437c6d2d8698b1174a335fbd66035bb3edc525d2cdb187232', os_hidden='False' |
    23 | protected        | False                                                                                                                                                                                      |
    24 | schema           | /v2/schemas/image                                                                                                                                                                          |
    25 | size             | 13267968                                                                                                                                                                                   |
    26 | status           | active                                                                                                                                                                                     |
    27 | tags             |                                                                                                                                                                                            |
    28 | updated_at       | 2020-12-18T06:00:52Z                                                                                                                                                                       |
    29 | virtual_size     | None                                                                                                                                                                                       |
    30 | visibility       | public                                                                                                                                                                                     |
    31 +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    32 
    33 确认镜像的上传并验证属性
    34 [root@ct ~]# openstack image list
    35 +--------------------------------------+--------+--------+
    36 | ID                                   | Name   | Status |
    37 +--------------------------------------+--------+--------+
    38 | fd197925-4879-4330-aa57-b89f108973e0 | cirros | active |
    39 +--------------------------------------+--------+--------+

    总结

    至此OpenStack的镜像服务已基本完成,Glanc组件主要是提供虚拟机镜像模板的注册与管理

  • 相关阅读:
    Mooncake (排序+贪心)
    The Black Hole of Numbers (strtoint+inttostr+sort)
    随机排序
    EF 随机排序
    禁用DropDownList的Items
    sql之left join、right join、inner join的区别
    SQL优化-索引
    .net 面试问题 汇总
    从简单的例子理解泛型
    1.1 使用内置的Camera应用程序捕获图像
  • 原文地址:https://www.cnblogs.com/xuhao0705/p/14154867.html
Copyright © 2020-2023  润新知