注意要 按顺序 搭建服务,在 CentOS 7 安装 Openstack Rocky 版本 - 环境搭建 的基础上安装服务。

Image service - 镜像服务(Glance)

控制节点 安装,这里默认是将镜像存储在本地,之后安装了存储服务再进行修改

数据库配置

连接数据库

1
2
# 连接数据库,密码 mariadb-123456
mysql -u root -p

数据库操作

1
2
3
4
5
6
7
8
9
-- 创建数据库
CREATE DATABASE glance;

-- 创建用户 glance ,密码为 mariadb-glance,并授予权限
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'mariadb-glance';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'mariadb-glance';

-- 创建完毕退出
exit

身份认证和 API 配置

创建用户 glance 并添加到 admin 角色

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 加载环境变量
. admin-openrc

# 创建用户,设置密码为 glance
openstack user create --domain default --password-prompt glance
# User Password:
# Repeat User Password:
# +---------------------+----------------------------------+
# | Field | Value |
# +---------------------+----------------------------------+
# | domain_id | default |
# | enabled | True |
# | id | ce5950a133a045178dc59a4c9eb4e5a1 |
# | name | glance |
# | options | {} |
# | password_expires_at | None |
# +---------------------+----------------------------------+


# 将用户添加到 admin 角色
openstack role add --project service --user glance admin
# 无输出

创建服务实体和服务 API 端点

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
51
52
53
54
55
56
57
58
59
60
# 创建服务实体
openstack service create --name glance --description "OpenStack Image" image
# +-------------+----------------------------------+
# | Field | Value |
# +-------------+----------------------------------+
# | description | OpenStack Image |
# | enabled | True |
# | id | 39682403c1b94b78bf88983346fb6e67 |
# | name | glance |
# | type | image |
# +-------------+----------------------------------+


# 创建服务 API 端点(endpoint)
openstack endpoint create --region RegionOne image public http://controller:9292
# +--------------+----------------------------------+
# | Field | Value |
# +--------------+----------------------------------+
# | enabled | True |
# | id | 2abbe79de976438ba69b41a301f50270 |
# | interface | public |
# | region | RegionOne |
# | region_id | RegionOne |
# | service_id | 39682403c1b94b78bf88983346fb6e67 |
# | 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 | 6676693aa08e4acd9a5ec0e83bca1964 |
# | interface | internal |
# | region | RegionOne |
# | region_id | RegionOne |
# | service_id | 39682403c1b94b78bf88983346fb6e67 |
# | 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 | 83c87b7b8c5e4ab6ac13988efa716b46 |
# | interface | admin |
# | region | RegionOne |
# | region_id | RegionOne |
# | service_id | 39682403c1b94b78bf88983346fb6e67 |
# | service_name | glance |
# | service_type | image |
# | url | http://controller:9292 |
# +--------------+----------------------------------+

安装和配置 glance

安装软件包

1
2
# 安装
yum install openstack-glance -y

修改配置文件 /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
[database]
connection = mysql+pymysql://glance:mariadb-glance@controller/glance

[keystone_authtoken]
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

[paste_deploy]
flavor = keystone

[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

修改另一个配置文件 /etc/glance/glance-registry.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[database]
connection = mysql+pymysql://glance:mariadb-glance@controller/glance

[keystone_authtoken]
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

[paste_deploy]
flavor = keystone

启用镜像服务

1
2
3
4
5
6
7
8
# 填充数据库
su -s /bin/sh -c "glance-manage db_sync" glance
# ...
# Database is synced successfully.

# 启用服务
systemctl enable openstack-glance-api.service openstack-glance-registry.service
systemctl start openstack-glance-api.service openstack-glance-registry.service

验证

控制节点 上运行

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
# 更新环境变量
. admin-openrc

# 下载源镜像
wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img

# 上传镜像到镜像服务,公开可见(所有项目都可以访问)
openstack image create "cirros" \
--file cirros-0.4.0-x86_64-disk.img \
--disk-format qcow2 --container-format bare \
--public
# +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
# | Field | Value
# +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
# | checksum | 443b7623e27ecf03dc9e01ee93f67afe
# | container_format | bare
# | created_at | 2020-12-26T02:27:31Z
# | disk_format | qcow2
# | file | /v2/images/af73bd20-bdcf-47a2-af78-29fe3e98053b/file
# | id | af73bd20-bdcf-47a2-af78-29fe3e98053b
# | min_disk | 0
# | min_ram | 0
# | name | cirros
# | owner | 052158381fee46e693571c9dfb6ae3f5
# | properties | os_hash_algo='sha512', os_hash_value='6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78', os_hidden='False' |
# | protected | False
# | schema | /v2/schemas/image
# | size | 12716032
# | status | active
# | tags |
# | updated_at | 2020-12-26T02:27:31Z
# | virtual_size | None
# | visibility | public
# +------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+


# 确认镜像上传到镜像服务
openstack image list
# +--------------------------------------+--------+--------+
# | ID | Name | Status |
# +--------------------------------------+--------+--------+
# | af73bd20-bdcf-47a2-af78-29fe3e98053b | cirros | active |
# +--------------------------------------+--------+--------+

参阅