004-官网安装openstack之-glance镜像服务

1.glance概念理解

        OpenStack镜像服务是IaaS的镜像服务。其镜像服务主要是由glance组件实现。它接受磁盘镜像或服务器镜像API请求和来自终端用户或OpenStack计算组件的元数据定义。

  Glance镜像服务也支持包括OpenStack对象存储在内的多种类型仓库上的磁盘镜像或服务器镜像存储用户使用镜像服务 (glance) 允许来创建,查询虚拟机镜像。它提供的 REST API,允许查询虚拟机镜像的 metadata 并获取一个现有的镜像。可以将虚拟机镜像存储到各种位置,如文件系统或对象存储,块存储(ceph作为后端存储)上传指定的镜像文件作为后端配置镜像服务。

其默认目录是 :/var/lib/glance/images/

2.glance服务中的两个组件

glance-api:
用于接收镜像REST API的调用,诸如镜像查找,获取,上传,删除
glance-registry:
用于与mysql数据库交互,监听端口为9191,
提供镜像元数据相关的REST接口,用于存储、处理和恢复镜像的元数据(metadata),元数据包括项诸如大小和类型。
通过glance-registry可以向数据库中写入或获取镜像的各种数据
其中的两张表image和property,image表保存了镜像格式大小等信息,image property表保存进行的定制化信息

image:镜像文件的存储仓库
支持多种类型的仓库,它们有普通文件系统、对象存储、RADOS块设备、HTTP、以及亚马逊S3。另外,其中一些仓库仅支持只读方式使用。
image store:
是一个存储的接口层,通过这个接口glance可以获取镜像,支持的存储有亚马逊的S3,openstack中的swift,和ceph,GlusterFS等分布式存储
image store是镜像保存与获取的接口,仅仅是一个接口层,具体的实现需要外部的存储支持.

3.控制节点安装glance服务

(1)创建glance数据库

[root@controller ~]# mysql -uroot -p123456
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)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'controller' 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)]> quit
Bye

(2)keystone中注册glance信息,创建glance相关用户信息

创建glance用户,在glance的在local_user表中创建glance用户

root@controller ~]# source admin-openrc 
[root@controller ~]# openstack user create --domain default --password=glance glance
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 716529d21e9541c0baf660ef3bda5aba |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
查看用户
[root@controller ~]# openstack user list
+----------------------------------+--------+
| ID                               | Name   |
+----------------------------------+--------+
| 35a3fdebbc6c4a9797397ae0aa036bf3 | myuser |
| 5d52ade18b88414bb3ab5a29b8709da0 | admin  |
| 716529d21e9541c0baf660ef3bda5aba | glance |
+----------------------------------+--------+
[root@controller ~]# 

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

[root@controller ~]# openstack role add --project service --user glance admin

(4)创建glance镜像服务的实体,在service表中增加glance项目

[root@controller ~]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | f8aa494bd88a455189c760d518a7623c |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
查看服务实体列表
[root@controller ~]# openstack service list
+----------------------------------+----------+----------+
| ID                               | Name     | Type     |
+----------------------------------+----------+----------+
| 0449383fe6604841b73bc815ffbb6ac5 | keystone | identity |
| f8aa494bd88a455189c760d518a7623c | glance   | image    |
+----------------------------------+----------+----------+
[root@controller ~]# 

(5)创建镜像服务的 API 端点(endpoint端点)

[root@controller ~]# openstack endpoint create --region RegionOne image public http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 834d4e1b4fcd46a4893096218373d392 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f8aa494bd88a455189c760d518a7623c |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne image internal http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 1ea86afadbd74e189cbf4f209327048a |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f8aa494bd88a455189c760d518a7623c |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
[root@controller ~]# openstack endpoint create --region RegionOne image admin http://controller:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 96a1fcfb72c242f8abfa3b066226a25a |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f8aa494bd88a455189c760d518a7623c |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+
查看endpoint端点列表
[root@controller ~]# openstack endpoint list
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+
| ID                               | Region    | Service Name | Service Type | Enabled | Interface | URL                        |
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+
| 1ea86afadbd74e189cbf4f209327048a | RegionOne | glance       | image        | True    | internal  | http://controller:9292     |
| 4958b09872894953b50257fd3ee41cfa | RegionOne | keystone     | identity     | True    | internal  | http://controller:5000/v3/ |
| 8191331923ef477aa9eb08c33c968671 | RegionOne | keystone     | identity     | True    | public    | http://controller:5000/v3/ |
| 834d4e1b4fcd46a4893096218373d392 | RegionOne | glance       | image        | True    | public    | http://controller:9292     |
| 96a1fcfb72c242f8abfa3b066226a25a | RegionOne | glance       | image        | True    | admin     | http://controller:9292     |
| d239bdcfaa0046f89919833333ef01d4 | RegionOne | keystone     | identity     | True    | admin     | http://controller:5000/v3/ |
+----------------------------------+-----------+--------------+--------------+---------+-----------+----------------------------+
[root@controller ~]# 
镜像服务endpoint

4.安装glance相关软件 

(1)安装glance相关软件包

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

(2)openstack命令行方式修改glance-api.conf配置文件

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
glane-api文件

(3)openstack命令行方式修改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 ~]# 
galnce-registry文件

5.同步glance数据库

1)初始化glance数据库(生成15张表)

[root@controller ~]# su -s /bin/sh -c "glance-manage db_sync" glance

2)同步完成进行测试验证

[root@controller ~]# mysql -uglance -pglance -hcontroller -e "use glance;show tables;"
[root@controller ~]# mysql -uglance -pglance -hcontroller -e "use glance;show tables;"|wc -l
16
[root@controller ~]# 

6.启动glance镜像服务且设置开机自启动

[root@controller ~]# systemctl start openstack-glance-api openstack-glance-registry
[root@controller ~]# systemctl enable openstack-glance-api openstack-glance-registry

7.检查配置是否正确

1)上传小的cirror测试镜像

[root@controller ~]# source /root/admin-openrc 
[root@controller ~]#wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
[root@controller ~]#mv cirros-0.4.0-x86_64-disk.img cirror.img
[root@controller ~]# openstack image create "cirror-test"  --file /root/cirros.img --disk-format qcow2 --container-format bare --public

2)查看是否上传成功

[root@controller ~]# openstack image list
+--------------------------------------+-------------+--------+
| ID                                   | Name        | Status |
+--------------------------------------+-------------+--------+
| c522952d-9d3b-4f6d-8edb-e9d85c33cae6 | cirror-test | active |
+--------------------------------------+-------------+--------+
可以看到刚才上传的名为cirror-test的glance镜像.

至此,glance镜像服务安装配置完毕,欢迎探讨。

 

posted @ 2020-02-16 16:48  精灵中的二丫  阅读(626)  评论(0)    收藏  举报