OpenStack Newton版本部署 ---- 镜像服务(glance)

OpenStack Newton版本部署 ---- 镜像服务(glance)

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

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

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

2)支持多种方式存储image,包括普通的文件系统、SwiftAmazon S3

3)对Instance 执行 Snapshot 创建新的 image

先决条件

1、创建数据库

1root用户登录数据库

$ mysql -u root -p

2)创建glance数据库

mysql> CREATE DATABASE glance;

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

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

2、创建服务凭证

1)输入管理员凭证

$ . admin-openrc

      2)创建glance用户(openstack)

$ openstack user create --domain default --password-prompt glance
 
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 3f4e777c4062483ab8d9edd7dff829df |
| name                | glance                           |
| password_expires_at | None                             |
+---------------------+----------------------------------+

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

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

      4)创建glance服务:

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

3、创建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           |
+--------------+----------------------------------+

安装和配置组件

1、安装

# yum install openstack-glance

2、修改/etc/glance/glance-api.conf配置

1)配置数据库访问

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

用合适密码替换GLANCE_DBPASS。

2)配置认证服务访问

[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用户的密码替换GLANCE_PASS。

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

 

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

4)检查配置

用命令 cat/etc/glance/glance-api.conf | grep -v ^# | grep -v ^$检查配置是否正确。

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

1)数据库访问

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

2)配置认证服务访问

[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

4、填充image服务数据库

# su -s /bin/sh -c "glance-manage db_sync" glance

      可以通过以下命令查看数据库是否填充成功:

MariaDB [(none)]> useglance;

MariaDB [keystone]> showtables;

完成安装

1、启动image服务,并设置开机启动:

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

验证操作

1、输入管理员凭证

$ . admin-openrc

2、下载image

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

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

$ openstack image create "cirros" \
  --file cirros-0.3.4-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                                               |
+------------------+------------------------------------------------------+

4、确认图像已上传:

$ openstack image list
 
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
    +--------------------------------------+--------+--------+
    | 38047887-61a7-41ea-9b49-27987d5e8bb9 | cirros | active |
    +--------------------------------------+--------+--------+

你可能感兴趣的:(OpenStack)