• 【openstack N版】——镜像服务glance


    一.openstack镜像服务glance

    1.1 glance介绍

    glance主要是由三部分组成

    • glance-api:接收云系统镜像的创建,删除,读取请求,类似nova-api,通过其他模块(glance-registry及image store)来完成诸如镜像的查找、获取、上传、删除等操作,api监听端口9292。
    • glance-registry:云系统的镜像注册服务,用于与mysql数据库交互,存储或获取镜像的元数据(metadata);提供镜像元数据相关的REST接口,通过glance-registry,可以向数据库中写入或获取镜像各种数据,glance-registry监听端口9191,glance数据库中有两张表,一张是image表,另一张是image property表。image表保存了镜像格式、大小等信息;image property表则主要保存镜像的定制化信息。
    • image store:是一个存储的接口层,通过这个接口,glance可以获取镜像,image store支持的存储有Amazon的S3、Openstack本身的Swift还有注入ceph,sheepdog,GFS等分布式存储。image store是镜像保存与获取的接口,它仅仅是一个接口层,具体的实现需要外部的存储支持。

    1.2 glance环境准备

    1.2.1安装glance包(控制节点)
    1 yum install openstack-glance –y
    1.2.2创建glance库及用户
     1 #登录数据库
     2 [root@linux-node1 ~]# mysql -uroot –p
     3 #创建glance库
     4 MariaDB [(none)]> create database glance;
     5 Query OK, 1 row affected (0.00 sec)
     6 #创建glance用户并授权
     7 MariaDB [(none)]> grant all privileges on glance.* to glance@'localhost' identified by 'glance';
     8 Query OK, 0 rows affected (0.00 sec)
     9 MariaDB [(none)]> grant all privileges on glance.* to glance@'%' identified by 'glance';         
    10 Query OK, 0 rows affected (0.00 sec)
    1.2.3创建openstack的glance用户
    1 #创建glance用户,密码:glance
    2 [root@linux-node1 ~]# openstack user create --domain default   --password-prompt glance
    3 User Password:glance
    +---------------------+----------------------------------+
    | Field               | Value                            |
    +---------------------+----------------------------------+
    | domain_id           | default                          |
    | enabled             | True                             |
    | id                  | ab8dbf65e6214fb285a438aa3f1007f8 |
    | name                | glance                           |
    | password_expires_at | None                             |
    +---------------------+----------------------------------+
    4 #将glance用户加入到service项目并且赋予admin角色 5 [root@linux-node1 ~]# openstack role add --project service --user glance admin

    1.3glance配置

    1.3.1项目及端点配置
     1 #创建glance服务实体
     2 [root@linux-node1 ~]# openstack service create --name glance --description "OpenStack Image" image
    +-------------+----------------------------------+
    | Field       | Value                            |
    +-------------+----------------------------------+
    | description | OpenStack Image                  |
    | enabled     | True                             |
    | id          | 301d1fbc076145f7bf92bf92fb50346d |
    | name        | glance                           |
    | type        | image                            |
    +-------------+----------------------------------+
    3 #创建镜像服务API端点 4 [root@linux-node1 ~]# openstack endpoint create --region RegionOne image public http://192.168.56.11:9292
    +--------------+----------------------------------+
    | Field        | Value                            |
    +--------------+----------------------------------+
    | enabled      | True                             |
    | id           | fc8978523b064b518eab75f40a7db017 |
    | interface    | public                           |
    | region       | RegionOne                        |
    | region_id    | RegionOne                        |
    | service_id   | 301d1fbc076145f7bf92bf92fb50346d |
    | service_name | glance                           |
    | service_type | image                            |
    | url          | http://192.168.56.11:9292        |
    +--------------+----------------------------------+
    5 [root@linux-node1 ~]# openstack endpoint create --region RegionOne image internal http://192.168.56.11:9292
    +--------------+----------------------------------+
    | Field        | Value                            |
    +--------------+----------------------------------+
    | enabled      | True                             |
    | id           | 5da8b564f1244915a8d0bdf1d1f65a18 |
    | interface    | internal                         |
    | region       | RegionOne                        |
    | region_id    | RegionOne                        |
    | service_id   | 301d1fbc076145f7bf92bf92fb50346d |
    | service_name | glance                           |
    | service_type | image                            |
    | url          | http://192.168.56.11:9292        |
    +--------------+----------------------------------+ 6 [root@linux-node1 ~]# openstack endpoint create --region RegionOne image admin http://192.168.56.11:9292
    +--------------+----------------------------------+
    | Field        | Value                            |
    +--------------+----------------------------------+
    | enabled      | True                             |
    | id           | 9f35261f1894470d81abfb8dce6876a4 |
    | interface    | admin                            |
    | region       | RegionOne                        |
    | region_id    | RegionOne                        |
    | service_id   | 301d1fbc076145f7bf92bf92fb50346d |
    | service_name | glance                           |
    | service_type | image                            |
    | url          | http://192.168.56.11:9292        |
    +--------------+----------------------------------+ 7 #查看端点列表 8 [root@linux-node1 ~]# openstack endpoint list
    +----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------------------------+
    | ID                               | Region    | Service Name | Service Type | Enabled | Interface | URL                                          |
    +----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------------------------+
    | 46bb270ff4f04b0da6a69a554322bc27 | RegionOne | keystone     | identity     | True    | public    | http://192.168.56.11:5000/v3/                |
    | 5da8b564f1244915a8d0bdf1d1f65a18 | RegionOne | glance       | image        | True    | internal  | http://192.168.56.11:9292                    |
    | 77bca853dafb413da29dcbac4bed9305 | RegionOne | keystone     | identity     | True    | admin     | http://192.168.56.11:35357/v3/               |
    | 7cc4f83fc4f34cf9b1ec5033739aefc1 | RegionOne | keystone     | identity     | True    | internal  | http://192.168.56.11:35357/v3/               |
    | 9f35261f1894470d81abfb8dce6876a4 | RegionOne | glance       | image        | True    | admin     | http://192.168.56.11:9292                    |
    | fc8978523b064b518eab75f40a7db017 | RegionOne | glance       | image        | True    | public    | http://192.168.56.11:9292                    |
    +----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------------------------+
    1.3.2 glance连接数据配置
     1 #修改glance-api配置文件
     2 [root@linux-node1 ~]# vim /etc/glance/glance-api.conf
     3 #连接数据库配置
     4 [database]
     5 connection = mysql+pymysql://glance:glance@192.168.56.11/glance
     6 #修改registry配置文件
     7 [root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
     8 #连接数据库配置
     9 [database]
    10 connection = mysql+pymysql://glance:glance@192.168.56.11/glance
    11 #将数据导入数据库
    12 [root@linux-node1 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
    13 #检查数据
    14 [root@linux-node1 ~]# mysql -uglance -pglance -h192.168.56.11 -e "use glance;show tables"
    +----------------------------------+
    | Tables_in_glance                 |
    +----------------------------------+
    | artifact_blob_locations          |
    | artifact_blobs                   |
    | artifact_dependencies            |
    | artifact_properties              |
    | artifact_tags                    |
    | artifacts                        |
    | 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                            |
    +----------------------------------+
    1.3.3glance连接keystone配置
     1 #编辑glance-api配置文件
     2 [root@linux-node1 ~]# vim /etc/glance/glance-api.conf
     3 #在keystone_authtoken标签下添加连接keystone配置
     4 [keystone_authtoken]
     5 auth_uri = http://192.168.56.11:5000
     6 auth_url = http://192.168.56.11:35357
     7 memcached_servers = 192.168.56.11:11211
     8 auth_type = password
     9 project_domain_name = default
    10 user_domain_name = default
    11 project_name = service
    12 username = glance
    13 password = glance
    14 #配置认证服务访问,打开注释
    15 flavor = keystone
    16 #配置本地文件系统和镜像存储位置,打开注释
    17 stores = file,http
    18 #配置默认存储,打开注释
    19 default_store = file
    20 #配置文件系统存储数据目录,打开注释
    21 filesystem_store_datadir = /var/lib/glance/images
    1.3.4glance配置registry
     1 #修改配置文件
     2 [root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
     3 #在keystone_authtoken标签下配置连接keystone
     4 [keystone_authtoken]
     5 auth_uri = http://192.168.56.11:5000
     6 auth_url = http://192.168.56.11:35357
     7 memcached_servers = 192.168.56.11:11211
     8 auth_type = password
     9 project_domain_name = default
    10 user_domain_name = default
    11 project_name = service
    12 username = glance
    13 password = glance
    14 #配置认证服务访问,打开注释
    15 flavor = keystone

    1.4启动glance服务

    1 #允许开机自启
    2 [root@linux-node1 ~]# systemctl enable openstack-glance-api.service \
    3 openstack-glance-registry.service
    4 #启动服务
    5 [root@linux-node1 ~]# systemctl start openstack-glance-api.service \
    6 openstack-glance-registry.service

    二.测试glance

    2.1上传镜像

    注: 把镜像放到任意目录下,执行以下命令,进入那个目录,否则要加绝对路径

    1 #上传一个官方提供的小镜像来测试
    2 [root@linux-node1 ~]# openstack image create "cirros" \
    3 --file cirros-0.3.4-x86_64-disk.img \
    4 --disk-format qcow2 --container-format bare \
    5 --public
    +------------------+------------------------------------------------------+
    | Field            | Value                                                |
    +------------------+------------------------------------------------------+
    | checksum         | ee1eca47dc88f4879d8a229cc70a07c6                     |
    | container_format | bare                                                 |
    | created_at       | 2017-02-24T07:03:19Z                                 |
    | disk_format      | qcow2                                                |
    | file             | /v2/images/ed2e38dd-7975-46dc-9ca9-cc3e497ccff0/file |
    | id               | ed2e38dd-7975-46dc-9ca9-cc3e497ccff0                 |
    | min_disk         | 0                                                    |
    | min_ram          | 0                                                    |
    | name             | cirros                                               |
    | owner            | d24a61dd3ecb43cb9e8a5f6539c6a2bb                     |
    | protected        | False                                                |
    | schema           | /v2/schemas/image                                    |
    | size             | 13287936                                             |
    | status           | active                                               |
    | tags             |                                                      |
    | updated_at       | 2017-02-24T07:03:20Z                                 |
    | virtual_size     | None                                                 |
    | visibility       | public                                               |
    +------------------+------------------------------------------------------+

    2.2查看镜像列表

    1 #新版本查看镜像列表命令
    2 [root@linux-node1 ~]# openstack image list
    3 #蓝版本查看镜像列表命令
    4 [root@linux-node1 ~]# glance image-list
    +--------------------------------------+--------+--------+
    | ID                                   | Name   | Status |
    +--------------------------------------+--------+--------+
    | ed2e38dd-7975-46dc-9ca9-cc3e497ccff0 | cirros | active |
    +--------------------------------------+--------+--------+

    【开源是一种精神,分享是一种美德】

      — By GoodCook

      — 笔者QQ:253097001

      — 欢迎大家随时来交流

      —原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。

  • 相关阅读:
    复制、删除、移动文件、获取文件的版本信息、更改文件属性,删除只读文件
    How to use the MQ?
    StreamReader、 StreamWriter
    我的第一个AJAX程序
    XML操作
    SQL 使用XML数据修改语言
    认识 ASP.NET 3.5 MVC 路由解析分析
    北京2008奥运会开幕式&闭幕式下载(NBCBT附字幕)
    认识 ASP.NET 3.5 MVC 路由 理解默认路由表
    每天都有新发现 2009年10月21日 Decimal 和存储过程OUTPUT
  • 原文地址:https://www.cnblogs.com/goodcook/p/6438649.html
Copyright © 2020-2023  润新知