OpenStack部署之添加镜像服务三

OpenStack 的镜像服务 (glance) 允许用户发现、注册和恢复虚拟机镜像。它提供了一个 REST API,允许您查询虚拟机镜像的 metadata 并恢复一个实际的镜像。您可以存储虚拟机镜像通过不同位置的镜像服务使其可用,就像 OpenStack 对象存储那样从简单的文件系统到对象存储系统。

前提条件

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

一、创建glance数据库并赋予权限.

[root@Controller-Node ~]#mysql -uroot -p123456
MariaDB [(none)]> CREATE DATABASE glance;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'glance';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance';
MariaDB [(none)]> exit

二、获得 admin 凭证来获取只有管理员能执行命令的访问权限

[root@Controller-Node ~]# source admin-openrc.sh

三、要创建服务证书,完成这些步骤:

1.创建 glance 用户:

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

执行如下:

[root@Controller-Node ~]# openstack user create --domain default --password-prompt glance
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 21b02fedd86d434fa17459abb95ed796 |
| name                | glance                           |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
[root@Controller-Node ~]# 

2.添加 admin 角色到 glance 用户和 service 项目上。

[root@Controller-Node ~]# openstack role add --project service --user glance admin

3.创建glance服务实体

$openstack service create --name glance \
   --description "OpenStack Image service" image

执行如下:
[root@Controller-Node ~]# openstack service create --name glance \
>   --description "OpenStack Image service" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image service          |
| enabled     | True                             |
| id          | 6e658520634d45d3bebd30de4b1b7aa4 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
[root@Controller-Node ~]# 

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

$openstack endpoint create --region RegionOne \
  image public http://10.20.9.13:9292

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

$openstack endpoint create --region RegionOne \
  image admin http://10.20.9.13:9292
  
执行如下;

[root@Controller-Node ~]# openstack endpoint create --region RegionOne \
>   image public http://10.20.9.13:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 9710889c161d4ce78ed58d5cc5d1419b |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 6e658520634d45d3bebd30de4b1b7aa4 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://10.20.9.13:9292           |
+--------------+----------------------------------+
[root@Controller-Node ~]# openstack endpoint create --region RegionOne \
>   image internal http://10.20.9.13:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 663cabb9fa5f40bf8362b89ed6756c16 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 6e658520634d45d3bebd30de4b1b7aa4 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://10.20.9.13:9292           |
+--------------+----------------------------------+
[root@Controller-Node ~]# openstack endpoint create --region RegionOne \
>   image admin http://10.20.9.13:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | e8a34c6870fb459fbd3d29cc27e583af |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 6e658520634d45d3bebd30de4b1b7aa4 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://10.20.9.13:9292           |
+--------------+----------------------------------+
[root@Controller-Node ~]# 

四、安装并配置组件

1.安装软件包:

[root@Controller-Node ~]# yum install openstack-glance python-glance python-glanceclient

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

1.> 在 [database] 部分,配置数据库访问:

[database]
...
connection = mysql://glance:glance@10.20.9.13/glance

2.>在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问:

[keystone_authtoken]
...
auth_uri = http://10.20.9.13:5000
auth_url = http://10.20.9.13:35357
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = glance
password = glance


[paste_deploy]
...
flavor = keystone

3.> 在 [glance_store]部分,配置本地文件系统存储和镜像文件位置:

[glance_store]
...
default_store = file
filesystem_store_datadir = /var/lib/glance/images/

4.> 在 [DEFAULT] 部分,配置 noop 禁用通知,因为他们只适合与可选的Telemetry 服务:

[DEFAULT]
...
notification_driver = noop
verbose = True

3.编辑文件 /etc/glance/glance-registry.conf 并完成如下操作.

1.>在 [database] 部分,配置数据库访问:

[database]
...
connection = mysql://glance:glance@10.20.9.13/glance

2.>在 [keystone_authtoken] 和 [paste_deploy] 部分,配置认证服务访问:

[keystone_authtoken]
...
auth_uri = http://10.20.9.13:5000
auth_url = http://10.20.9.13:35357
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = glance
password = glance


[paste_deploy]
...
flavor = keystone

3.> 在[DEFAULT] 部分,配置 noop 禁用通知,因为他们只适合与可选的Telemetry 服务:

[DEFAULT]
...
notification_driver = noop
verbose = True

4.写入镜像服务数据库:

[root@Controller-Node ~]# su -s /bin/sh -c "glance-manage db_sync" glance

5.完成安装启动镜像服务、配置他们随机启动:

#systemctl enable openstack-glance-api.service openstack-glance-registry.service
#systemctl start openstack-glance-api.service openstack-glance-registry.service

五、验证操作

1.获取admin权限

[root@Controller-Node ~]# source admin-openrc.sh 

2.下载源镜像

#wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img

3.上传镜像

glance image-create --name "cirros" \
  --file cirros-0.3.4-x86_64-disk.img \
  --disk-format qcow2 --container-format bare \
  --visibility public --progress
  
执行如下
[root@Controller-Node ~]# glance image-create --name "cirros" \
>   --file cirros-0.3.4-x86_64-disk.img \
>   --disk-format qcow2 --container-format bare \
>   --visibility public --progress
[=============================>] 100%
+------------------+--------------------------------------+
| Property         | Value                                |
+------------------+--------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6     |
| container_format | bare                                 |
| created_at       | 2018-10-09T08:39:50Z                 |
| disk_format      | qcow2                                |
| id               | a2f8c5d3-6c5a-4a18-b19a-25163de90eec |
| min_disk         | 0                                    |
| min_ram          | 0                                    |
| name             | cirros                               |
| owner            | 6effb77cf0ba48a7a65a2c2235bbb726     |
| protected        | False                                |
| size             | 13287936                             |
| status           | active                               |
| tags             | []                                   |
| updated_at       | 2018-10-09T08:39:51Z                 |
| virtual_size     | None                                 |
| visibility       | public                               |
+------------------+--------------------------------------+
[root@Controller-Node ~]# 

4.确认镜像的上传并验证属性.

[root@Controller-Node ~]# glance image-list
+--------------------------------------+--------+
| ID                                   | Name   |
+--------------------------------------+--------+
| a2f8c5d3-6c5a-4a18-b19a-25163de90eec | cirros |
+--------------------------------------+--------+
[root@Controller-Node ~]# 

 

参考文档:https://docs.openstack.org/liberty/zh_CN/install-guide-rdo/glance.html

 

posted @ 2018-10-09 15:52  梦徒  阅读(986)  评论(0)    收藏  举报