上一篇:构建基于openEuler2209的OpenStack云平台(二)
3 安装和配置Image服务(glance service)
Image服务(glance)使用户能够发现、注册和检索虚拟机映像。它提供了一个RESTAPI,使用户能够查询虚拟机映像元数据并检索实际映像。用户可以将通过Image服务提供的虚拟机映像存储在各种位置,从简单的文件系统到OpenStack object storage等对象存储系统。
OpenStack Image服务是IaaS的核心。它接受来自最终用户或OpenStack Compute组件的磁盘或服务器映像和元数据定义的API请求。它还支持在各种存储库类型上存储磁盘或服务器映像,包括OpenStack对象存储。
3.1 先决条件
在安装和配置Image服务之前,必须创建glance数据库、服务凭据和API端点。
3.1.1 创建glance数据库,并授予权限
[root@xgk-ctl ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.5.16-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> exit
Bye
3.1.2 加载admin-openrc文件获取管理员凭证
[root@xgk-ctl ~]# source /etc/keystone/admin-openrc
3.1.3 创建服务凭证
1、Create the glance user
[root@xgk-ctl ~]# openstack user create --domain default --password-prompt glance
User Password:#设置glance用户密码,如GLANCE_PASS
Repeat User Password:
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | eb880d777a4d4508b9ac2d71492c194f |
| name | glance |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
2、将管理员角色添加到glance用户和服务项目
[root@xgk-ctl ~]# openstack role add --project service --user glance admin
3、创建glance服务实体
[root@xgk-ctl ~]# openstack service create --name glance --description "OpenStack Image" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | a20b8773f4fd4140af1565b037364599 |
| name | glance |
| type | image |
+-------------+----------------------------------+
3.1.4 创建镜像服务API端点
1、创建public端点
[root@xgk-ctl ~]# openstack endpoint create --region RegionOne image public http://xgk-ctl:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | ae46992b3eb6490386cdb11d45a26077 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | a20b8773f4fd4140af1565b037364599 |
| service_name | glance |
| service_type | image |
| url | http://xgk-ctl:9292 |
+--------------+----------------------------------+
2、创建internal端点
[root@xgk-ctl ~]# openstack endpoint create --region RegionOne image internal http://xgk-ctl:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 40ea739ff7614898b25bb2d8f9172a51 |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | a20b8773f4fd4140af1565b037364599 |
| service_name | glance |
| service_type | image |
| url | http://xgk-ctl:9292 |
+--------------+----------------------------------+
3、创建admin端点
[root@xgk-ctl ~]# openstack endpoint create --region RegionOne image admin http://xgk-ctl:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 261bd9959fce4532b855379ec36e0835 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | a20b8773f4fd4140af1565b037364599 |
| service_name | glance |
| service_type | image |
| url | http://xgk-ctl:9292 |
+--------------+----------------------------------+
3.2 安装和配置组件
3.2.1 安装软件包
[root@xgk-ctl ~]# dnf -y install openstack-glance
3.2.2 编辑/etc/glance/glance-api.conf文件
[root@xgk-ctl ~]# cp -a /etc/glance/glance-api.conf{,.bak}
[root@xgk-ctl ~]# grep -Ev '^$|#' /etc/glance/glance-api.conf.bak > /etc/glance/glance-api.conf
[root@xgk-ctl ~]# vim /etc/glance/glance-api.conf
……此处省略文件部分原有内容……
[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@xgk-ctl/glance
……此处省略文件部分原有内容……
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
……此处省略文件部分原有内容……
[keystone_authtoken]
www_authenticate_uri = http://xgk-ctl:5000
auth_url = http://xgk-ctl:5000
memcached_servers = xgk-ctl:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = GLANCE_PASS
……此处省略文件部分原有内容……
[paste_deploy]
flavor = keystone
……此处省略文件部分原有内容……
3.2.3 初始化镜像数据库
[root@xgk-ctl ~]# su -s /bin/sh -c "glance-manage db_sync" glance
3.2.4 完成安装
1、启动openstack-glance-api.service服务,并将其设置为开机自启动,然后就可以查看9292端口的监听状态
[root@xgk-ctl ~]# systemctl enable openstack-glance-api.service
[root@xgk-ctl ~]# systemctl start openstack-glance-api.service
[root@xgk-ctl ~]# netstat -natp | grep 9292
tcp 0 0 0.0.0.0:9292 0.0.0.0:* LISTEN 93188/python3
2、下载镜像文件
[root@xgk-ctl ~]# wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
3、上传镜像
用 QCOW2 磁盘格式, bare容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它。
[root@xgk-ctl ~]# openstack image create "cirros" --file cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --public
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
| container_format | bare |
| created_at | 2022-12-17T06:47:21Z |
| disk_format | qcow2 |
| file | /v2/images/57ea2d66-8865-4900-b960-fb14b4c6a484/file |
| id | 57ea2d66-8865-4900-b960-fb14b4c6a484 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 83c34dc70d18476097211c384d2e435c |
| properties | os_hidden='False', owner_specified.openstack.md5='', owner_specified.openstack.object='images/cirros', owner_specified.openstack.sha256='' |
| protected | False |
| schema | /v2/schemas/image |
| status | queued |
| tags | |
| updated_at | 2022-12-17T06:47:21Z |
| visibility | public |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------+
4、确认镜像
[root@xgk-ctl ~]# openstack image list
+--------------------------------------+--------+--------+
| ID | Name | Status |
+--------------------------------------+--------+--------+
| 57ea2d66-8865-4900-b960-fb14b4c6a484 | cirros | active |
+--------------------------------------+--------+--------+