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

1.3glance配置

1.3.1项目及端点配置
 #创建glance服务实体
[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                            |
+-------------+----------------------------------+
#创建镜像服务API端点
[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        |
+--------------+----------------------------------+
[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        |
+--------------+----------------------------------+
[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        |
+--------------+----------------------------------+
#查看端点列表
[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连接数据配置
 #修改glance-api配置文件
[root@linux-node1 ~]# vim /etc/glance/glance-api.conf
#连接数据库配置
[database]
connection = mysql+pymysql://glance:glance@192.168.56.11/glance
#修改registry配置文件
[root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
#连接数据库配置
[database]
connection = mysql+pymysql://glance:glance@192.168.56.11/glance
#将数据导入数据库
[root@linux-node1 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
#检查数据
[root@linux-node1 ~]# mysql -uglance -pglance -h192.168.56. -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配置
 #编辑glance-api配置文件
[root@linux-node1 ~]# vim /etc/glance/glance-api.conf
#在keystone_authtoken标签下添加连接keystone配置
[keystone_authtoken]
auth_uri = http://192.168.56.11:5000
auth_url = http://192.168.56.11:35357
memcached_servers = 192.168.56.11:
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
#配置认证服务访问,打开注释
flavor = keystone
#配置本地文件系统和镜像存储位置,打开注释
stores = file,http
#配置默认存储,打开注释
default_store = file
#配置文件系统存储数据目录,打开注释
filesystem_store_datadir = /var/lib/glance/images
1.3.4glance配置registry
 #修改配置文件
[root@linux-node1 ~]# vim /etc/glance/glance-registry.conf
#在keystone_authtoken标签下配置连接keystone
[keystone_authtoken]
auth_uri = http://192.168.56.11:5000
auth_url = http://192.168.56.11:35357
memcached_servers = 192.168.56.11:
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
#配置认证服务访问,打开注释
flavor = keystone

1.4启动glance服务

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

二.测试glance

2.1上传镜像

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

 #上传一个官方提供的小镜像来测试
[root@linux-node1 ~]# openstack image create "cirros" \
--file cirros-0.3.-x86_64-disk.img \
--disk-format qcow2 --container-format bare \
--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查看镜像列表

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

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

— By GoodCook

— 笔者QQ:253097001

— 欢迎大家随时来交流

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

上一篇:samba搭建


下一篇:Windows 安装服务 的两种方式