openstack部署之glance

简介

  Glance是Openstack的镜像服务。可以让用户注册、查找和检索在Openstack环境中使用的虚拟镜像。Openstack镜像服务支持将镜像文件存储在各种类型的存储环境中。例如本地文件系统或分布式文件系统,如Openstack的对象存储服务(Swift)。下边我们开始部署Glance组件。

创建数据库

与keystone部署一样,需要先创建名为glance的数据库

$ mysql -u root -p
MariaDB [(none)]> CREATE DATABASE glance;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';

组件部署

Glance分为两个子服务,如下所示

  • Glance-api:接受云系统镜像的创建、删除、读取服务
  • Glance-Registry:云系统的镜像注册服务

安装

# yum install openstack-glance

配置

编辑/etc/glance/glance-api.conf文件

[database]
# ...
connection = mysql+pymysql://glance:glance@192.168.46.130/glance
#...
[keystone_authtoken]
auth_uri = http://192.168.46.130:5000
auth_url = http://192.168.46.130:35357
memcached_servers = 192.168.46.130:11211 #memcached的端口
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
#...
[paste_deploy]
# ...
flavor = keystone
#...
[glance_store]
# ...
stores = file,http
default_store = file 
filesystem_store_datadir = /var/lib/glance/images/  #设置镜像本地存储

编辑 /etc/glance/glance-registry.conf ,需要修改的配置与/etc/glance/glance-api.conf类似

[database]
# ...
connection = mysql+pymysql://glance:glance@192.168.46.130/glance
#...
[keystone_authtoken]
auth_uri = http://192.168.46.130:5000
auth_url = http://192.168.46.130:35357
memcached_servers = 192.168.46.130:11211  #memcached的端口
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = glance
#...
[paste_deploy]
# ...
flavor = keystone

初始化glance数据库

# su -s /bin/sh -c "glance-manage db_sync" glance  

启动服务

# systemctl enable openstack-glance-api.service openstack-glance-registry.service
# systemctl start openstack-glance-api.service openstack-glance-registry.service

在keystone注册Glance

经过以上操作可以说Glance已经基本部署完成了,但是这样的话,其他组件是无法使用Glance的,接下来还需要在keystone中做注册,因为openstack的其他组件访问Glance时,都是先到keystone上做认证,获得访问Glance的权限,也就是得到一个token,然后才能访问Glance。

  • 先把环境变量设置上去,使用之前保存的脚本
source admin-openstack.sh
  • 创建glance用户
$ openstack user create --domain default --password-prompt glance

User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 3f4e777c4062483ab8d9edd7dff829df |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
  • 添加角色和项目
$ openstack role add --project service --user glance admin
  • 注册服务
$ openstack service create --name glance --description "OpenStack Image" image  #不能乱改

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
  • 注册endpoint
[root@localhost ~]# openstack endpoint create --region RegionOne image public http://192.168.46.130:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 3bf50e2feba3467c8ee661615f015376 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d408f9afadf24865b0213971a0a93efe |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.46.130:9292       |
+--------------+----------------------------------+
[root@localhost ~]# openstack endpoint create --region RegionOne  image internal http://192.168.46.130:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 6c36fa5d0f8841e899e022fea24e725f |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d408f9afadf24865b0213971a0a93efe |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.46.130:9292       |
+--------------+----------------------------------+
[root@localhost ~]# openstack endpoint create --region RegionOne image admin http://192.168.46.130:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 6b6d54d2f0034a01b25ccd14f82425ca |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | d408f9afadf24865b0213971a0a93efe |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.46.130:9292       |
+--------------+----------------------------------+

以上三个endpoint是可以设置三个不同的IP的,public为公网,internal为内网,admin为管理。可以设置三个不同的url分别部署在不同的主机上。本次我们只使用了一个主机部署,所以设置的都一样。

验证Glance安装

至此Glance我们就完成部署了,下边执行命令验证Glance是否正常

[root@localhost ~]# openstack image list

[root@localhost ~]# 

如果以上命令正常执行,则说明Glance部署成功

加载镜像

  • 设置环境变量
source admin-openstack.sh
  • 下载镜像
$ wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img
  • 加载镜像
$ openstack image create "cirros" 
  --file cirros-0.3.5-x86_64-disk.img 
  --disk-format qcow2 --container-format bare 
  --public

+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | 133eae9fb1c98f45894a4e60d8736619                     |
| container_format | bare                                                 |
| created_at       | 2015-03-26T16:52:10Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/cc5c6982-4910-471e-b864-1098015901b5/file |
| id               | cc5c6982-4910-471e-b864-1098015901b5                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | ae7a98326b9c455588edd2656d723b9d                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 13200896                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2015-03-26T16:52:10Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+
  • 查看镜像
$ openstack image list

+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
+--------------------------------------+--------+--------+

其他

如果在部署过程中服务报错,可以在/var/log/glance/目录下查看glance的日志,如下:

可以在日志中查看ERROR的信息。当然在/var/log/keystone/下同样可以看到keystone的日志。

原文地址:https://www.cnblogs.com/baihl/p/10707412.html