OpenStack控制节点Image服务安装部署

介绍

Image Service 的功能是管理Image,让用户能够发现、获取和保存 Image。该服务仅运行在控制节点。

在 OpenStack 中,提供 Image Service 的是 Glance,其具体功能如下:

提供 REST API 让用户能够查询和获取 image 的元数据和 image 本身

支持多种方式存储 image,包括普通的文件系统、Swift、Amazon S3 等

对 Instance 执行 Snapshot 创建新的 image

创建数据库

root用户登录数据库

sudo mysql

创建glance数据库

CREATE DATABASE glance;

创建glance数据库用户并授予权限

GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'GLANCE_DBPASS';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY 'GLANCE_DBPASS';

替换GLANCE_DBPASS为你自己的密码

创建服务凭证

使用管理员用户

. admin-openrc

在openstack中创建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                             |
+---------------------+----------------------------------+

添加admin角色到glance用户和service工程中

openstack role add --project service --user glance admin

创建glance服务

openstack service create --name glance \
--description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 8c2c7f1b9b5049ea9e63757b5533e6d2 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+

创建image服务API

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           |
+--------------+----------------------------------+

安装和配置组件

安装

sudo apt install glance

修改/etc/glance/glance-api.conf文件

配置数据库访问

[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

替换GLANCE_DBPASS为你自己的密码

配置认证服务访问

[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
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_PASS为你自己的密码,并且删除文件中其他的[keystone_authtoken]部分

配置本地文件系统存储和镜像文件路径

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

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

数据库访问

[database]
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance

配置认证服务访问

[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
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_PASS为你自己的密码

导入image服务数据库

sudo -s /bin/sh -c "glance-manage db_sync" glance

完成安装重新启动

sudo service glance-registry restart
sudo service glance-api restart

验证

使用admin用户登录

. admin-openrc

下载镜像

在下载之前由于使用到wget命令,需要配置http代理后使用wget命令

export http_proxy=http://172.17.30.100:50080
export https_proxy=https://172.17.30.100:50080
sudo http_proxy=$http_proxy https_proxy=$https_proxy wget http://download.cirros-cloud.net/0.3.5/cirros-0.3.5-x86_64-disk.img

以qcw2的磁盘格式、bare容器格式、所有人可见的方式将镜像上传到Image service

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 |
+--------------------------------------+--------+--------+

你可能感兴趣的:(OpenStack控制节点Image服务安装部署)