OpenStack系列之一:手动部署OpenStack Queens(3.镜像服务)


title: OpenStack系列之一:手动部署OpenStack Queens(3.镜像服务)
categories: Linux
tags:
- OpenStack
timezone: Asia/Shanghai
date: 2019-01-21

镜像服务概览

Image服务(glance)使用户能够发现,注册和检索虚拟机映像。它提供了一个 REST API,使您可以查询虚拟机图像元数据并检索实际图像。您可以将通过Image服务提供的虚拟机映像存储在各种位置,从简单的文件系统到OpenStack Object Storage等对象存储系统。

为简单起见,本指南介绍如何配置Image服务以使用file后端,后端上载并存储在托管Image服务的控制器节点上的目录中。默认情况下,此目录为/var/lib/glance/images/。

第一步:安装和配置

这个部分描述如何在控制节点上安装和配置镜像服务,即 glance。简单来说,这个配置将镜像保存在本地文件系统中。

1.先决条件

安装和配置镜像服务之前,你必须创建创建一个数据库、服务凭证和API端点。

  • 1.完成下面的步骤以创建数据库:
以下有两处xiaoliu,请根据自己情况修改
# 1.用数据库连接客户端以 root 用户连接到数据库服务器:
mysql -u root -p

# 2.创建 glance 数据库:
CREATE DATABASE glance;

# 3.对``glance``数据库授予恰当的权限:
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'xiaoliu';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'xiaoliu';
  • 2.获得 admin 凭证来获取只有管理员能执行的命令的访问权限:

    source /home/admin-openrc
    echo $OS_USERNAME

  • 3.要创建服务证书,完成这些步骤:

    1.创建 glance 用户:

    openstack user create --domain default --password-prompt glance

    2.添加 admin 角色到 glance 用户和 service 项目上(这个命令执行后没有输出)。

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

    3.创建glance服务实体:

    openstack service create --name glance --description “OpenStack Image” image

  • 4.创建镜像服务的 API 端点:

以下有3处controller,请根据自己情况修改
openstack endpoint create --region RegionOne image public http://controller:9292
openstack endpoint create --region RegionOne image internal http://controller:9292
openstack endpoint create --region RegionOne image admin http://controller:9292
  • 5.以上命令输出展示

    [root@controller home]# openstack user create --domain default --password-prompt glance
    User Password:
    Repeat User Password:
    ±--------------------±---------------------------------+
    | Field | Value |
    ±--------------------±---------------------------------+
    | domain_id | default |
    | enabled | True |
    | id | efd4832cc5794f83a70bf2852d17521e |
    | name | glance |
    | options | {} |
    | password_expires_at | None |
    ±--------------------±---------------------------------+
    [root@controller home]# openstack role add --project service --user glance admin
    [root@controller home]# openstack service create --name glance --description “OpenStack Image” image
    ±------------±---------------------------------+
    | Field | Value |
    ±------------±---------------------------------+
    | description | OpenStack Image |
    | enabled | True |
    | id | 59e4adffc7db4be6b0ecd3cd47c0bc70 |
    | name | glance |
    | type | image |
    ±------------±---------------------------------+
    [root@controller home]# openstack endpoint create --region RegionOne image public http://controller:9292
    ±-------------±---------------------------------+
    | Field | Value |
    ±-------------±---------------------------------+
    | enabled | True |
    | id | 3328e712166d48f4a65f0bc35e4e87ed |
    | interface | public |
    | region | RegionOne |
    | region_id | RegionOne |
    | service_id | 59e4adffc7db4be6b0ecd3cd47c0bc70 |
    | service_name | glance |
    | service_type | image |
    | url | http://controller:9292 |
    ±-------------±---------------------------------+
    [root@controller home]# openstack endpoint create --region RegionOne image internal http://controller:9292
    ±-------------±---------------------------------+
    | Field | Value |
    ±-------------±---------------------------------+
    | enabled | True |
    | id | 07c2923d2335461ebf44a11c213a5a40 |
    | interface | internal |
    | region | RegionOne |
    | region_id | RegionOne |
    | service_id | 59e4adffc7db4be6b0ecd3cd47c0bc70 |
    | service_name | glance |
    | service_type | image |
    | url | http://controller:9292 |
    ±-------------±---------------------------------+
    [root@controller home]# openstack endpoint create --region RegionOne image admin http://controller:9292
    ±-------------±---------------------------------+
    | Field | Value |
    ±-------------±---------------------------------+
    | enabled | True |
    | id | 455920af8d694678bbc9f681534a9038 |
    | interface | admin |
    | region | RegionOne |
    | region_id | RegionOne |
    | service_id | 59e4adffc7db4be6b0ecd3cd47c0bc70 |
    | service_name | glance |
    | service_type | image |
    | url | http://controller:9292 |
    ±-------------±---------------------------------+

2.安全并配置组件
# 默认配置文件在各发行版本中可能不同。
# 你可能需要添加这些部分,选项而不是修改已经存在的部分和选项。
# 另外,在配置片段中的省略号(...)表示默认的配置选项你应该保留。
  • 1.安装软件包:

    yum install -y openstack-glance

  • 2.编辑文件 /etc/glance/glance-api.conf 并完成如下动作:

以下有4处controller,请根据自己实际情况更改
以下有2处xiaoliu,请根据自己实际情况更改
cp /etc/glance/glance-api.conf /etc/glance/glance-api.conf.bak
cat /etc/glance/glance-api.conf.bak | grep -v "^#" | grep -v '^$' > /etc/glance/glance-api.conf
vim /etc/glance/glance-api.conf

# 1.在 [database] 部分,配置数据库访问:
# 将``GLANCE_DBPASS`` 替换为你为镜像服务选择的密码。
[database]
...
connection = mysql+pymysql://glance:xiaoliu@controller/glance

# 2.在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问:
# 将 GLANCE_PASS 替换为你为认证服务中你为 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 = xiaoliu

[paste_deploy]
# ...
flavor = keystone

# 3.在 [glance_store] 部分,配置本地文件系统存储和镜像文件位置:
[glance_store]
# ...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
  • 3.编辑文件 /etc/glance/glance-registry.conf并完成如下动作:
以下有4处controller,请根据自己实际情况更改
以下有2处xiaoliu,请根据自己实际情况更改
cp /etc/glance/glance-registry.conf /etc/glance/glance-registry.conf.bak
cat /etc/glance/glance-registry.conf.bak | grep -v "^#" | grep -v '^$' > /etc/glance/glance-registry.conf
vim /etc/glance/glance-registry.conf

# 1.在 [database] 部分,配置数据库访问:
# 将``GLANCE_DBPASS`` 替换为你为镜像服务选择的密码。
[database]
# ...
connection = mysql+pymysql://glance:xiaoliu@controller/glance

# 2.在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问:
# 将 GLANCE_PASS 替换为你为认证服务中你为 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 = xiaoliu

[paste_deploy]
# ...
flavor = keystone

# 3.在 [keystone_authtoken] 中注释或者删除其他选项。
  • 4.写入镜像服务数据库:

    su -s /bin/sh -c “glance-manage db_sync” glance

  • 5.验证数据库是否写入成功

    应该有15张表

    mysql -uroot -p’xiaoliu’ -D glance -se “show tables;”
    mysql -uroot -p’xiaoliu’ -D glance -se “show tables;” | wc -l

3.完成安装:启动镜像服务、配置他们随机启动:
systemctl enable openstack-glance-api.service openstack-glance-registry.service
systemctl stop openstack-glance-api.service openstack-glance-registry.service
systemctl start openstack-glance-api.service openstack-glance-registry.service
systemctl status openstack-glance-api.service openstack-glance-registry.service

第二步:验证操作

使用 CirrOS <http://launchpad.net/cirros>__对镜像服务进行验证,CirrOS是一个小型的Linux镜像可以用来帮助你进行 OpenStack部署测试。

关于如何下载和构建镜像的更多信息,参考OpenStack Virtual Machine Image Guide <http://docs.openstack.org/image-guide/>。关于如何管理镜像的更多信息,参考OpenStack用户手册 <http://docs.openstack.org/user-guide/common/cli-manage-images.html>

1.获得 admin 凭证来获取只有管理员能执行的命令的访问权限:
source /home/admin-openrc
echo $OS_USERNAME
2.下载源镜像:
wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
3.使用 QCOW2 磁盘格式, bare 容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它:
# OpenStack 是动态生成 ID 的,因此您看到的输出会与示例中的命令行输出不相同。
openstack image create "cirros" \
                --file cirros-0.4.0-x86_64-disk.img \
                --disk-format qcow2 --container-format bare \
                --public
4.确认镜像的上传并验证属性:
openstack image list
5.以上命令输出展示
[root@controller home]# 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       | 2019-01-20T11:30:30Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/6cc21209-0d33-477c-a37e-eeed6b34f3ad/file |
| id               | 6cc21209-0d33-477c-a37e-eeed6b34f3ad                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                               |
| owner            | e72d68bddd2a4d07847201304b746b0b                     |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 12716032                                             |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2019-01-20T11:30:30Z                                 |
| virtual_size     | None                                                 |
| visibility       | public                                               |
+------------------+------------------------------------------------------+

[root@controller home]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 6cc21209-0d33-477c-a37e-eeed6b34f3ad | cirros | active |
+--------------------------------------+--------+--------+
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值