搭建 OpenStack(Q 版)Glance 组件

简介

  • 基于 Ubuntu/CentOS 系统,搭建 OpenStack(Q 版)Glance 组件

在 Controller 节点

数据库

  • 进入数据库
1
$ mysql -u root -p
  • 创建数据库
1
MariaDB [(none)]> CREATE DATABASE glance;
  • 赋予数据库权限
1
2
3
4
5
# <GLANCE_DBPASS>为自定义密码
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
  IDENTIFIED BY 'GLANCE_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
  IDENTIFIED BY 'GLANCE_DBPASS';
  • 退出数据库
1
MariaDB [(none)]> exit

安装 Glance 组件

CentOS/Ubuntu 系统

  • 重新加载 admin 用户的管理凭据
1
$ source /openstack/admin-openrc
  • 创建 glance 用户
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ 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                             |
+---------------------+----------------------------------+
  • 为项目 service 与用户 glance 添加角色 admin
1
$ openstack role add --project service --user glance admin
  • 创建 image 服务实体
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ openstack service create --name glance \
  --description "OpenStack Image" image

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
  • 创建 image 服务的访问端点 endpoint
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$ openstack endpoint create --region RegionOne \
  image public http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 340be3625e9b4239a6415d034e98aace |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

$ openstack endpoint create --region RegionOne \
  image internal http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | a6e4b153c2ae4c919eccfdbb7dceb5d2 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

$ openstack endpoint create --region RegionOne \
  image admin http://controller:9292

+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 0c37ed58103f4300a84ff125a539032d |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292           |
+--------------+----------------------------------+

Ubuntu 系统

  • 安装软件包
1
$ apt install glance

CentOS 系统

  • 安装软件包
1
$ yum install openstack-glance

CentOS/Ubuntu 系统

  • 配置 Glance 服务
1
$ vim /etc/glance/glance-api.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[database]
# <GLANCE_DBPASS>为 Glance 数据库的密码
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
# 配置使用 Keystone 服务
# <GLANCE_DBPASS>为 Glance 数据库的密码
[keystone_authtoken]
auth_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_PASS
 
[paste_deploy]
flavor = keystone
 
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
  • 配置 Glance 服务(注册)
1
$ vim /etc/glance/glance-registry.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
[database]
# <GLANCE_DBPASS>为 Glance 数据库的密码
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
# 配置使用 Keystone 服务
# <GLANCE_DBPASS>为 Glance 数据库的密码
[keystone_authtoken]
auth_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_PASS
 
[paste_deploy]
flavor = keystone
  • 同步数据库
1
$ su -s /bin/sh -c "glance-manage db_sync" glance

Ubuntu 系统

  • 重启 Glance 服务
1
2
$ service glance-registry restart
$ service glance-api restart

CentOS 系统

  • 重启 Glance 服务
1
2
3
4
$ systemctl enable openstack-glance-api.service \
  openstack-glance-registry.service
$ systemctl start openstack-glance-api.service \
  openstack-glance-registry.service

测试操作

CentOS/Ubuntu 系统

  • 重新加载 admin 用户的管理凭据
1
$ source /openstack/admin-openrc
  • 下载测试镜像

如果系统未自带 wget ,请自行手动安装

1
2
3
4
# 切换目录
$ cd /openstack
# 使用 wget 下载镜像
$ wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
  • 上传测试镜像
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ openstack image create "cirros" \
  --file cirros-0.4.0-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                                               |
+------------------+------------------------------------------------------+
  • 获取已上传镜像的属性
1
2
3
4
5
6
7
$ openstack image list

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

参考链接