崬城衞 发表于 2017-12-4 23:42:37

3、OpenStack Image(镜像)服务

  1、概述
  xxx
  2、准备 安装和配置 镜像 服务的 环境
  2.1、创建一个数据库,服务凭证和API endpoints
  2.1.1、登录mysql数据库



# mysql -u root -p
  2.1.2、创建glance 数据库



MariaDB [(none)]> CREATE DATABASE glance;
Query OK, 1 row affected (0.01 sec)
  2.1.3、授予glance数据库的正确访问权限



MariaDB [(none)]> grant all privileges on glance .* to 'glance'@'localhost' \
-> identified by 'PASSWORD';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on glance .* to 'glance'@'%'identified by 'PASSWORD';
Query OK, 0 rows affected (0.00 sec)
  2.2、调用admin-openrc凭据



# source admin-openrc
  2.3、创建服务凭据
  2.3.1、创建glance用户



# openstack user create --domain default --password-prompt glance
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id         | default                        |
| enabled             | True                           |
| id                  | 243f718f20684941a8a3a3f41594d91d |
| name                | glance                           |
| password_expires_at | None                           |
+---------------------+----------------------------------+
  2.3.2、将admin角色添加到glance用户和 service项目中



# openstack role add --project service --user glance admin
  2.3.4、创建glance service entity



# openstack service create --name glance \
>   --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled   | True                           |
| id          | 60fb47009a77459c87af0f176277ba82 |
| name      | glance                           |
| type      | image                            |
+-------------+----------------------------------+
  2.3.5、创建镜像服务API endpoint,分别创建public、internal、admin



# openstack endpoint create --region RegionOne \
>   image public http://controller:9292
+--------------+----------------------------------+
| Field      | Value                            |
+--------------+----------------------------------+
| enabled      | True                           |
| id         | b7c7c5525c1a46e98a03b7ba0cd895ea |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 60fb47009a77459c87af0f176277ba82 |
| 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         | 87c42a845cc2443796f61526945f8341 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 60fb47009a77459c87af0f176277ba82 |
| 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         | 26a91288caa84538bea13f6eb1670901 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 60fb47009a77459c87af0f176277ba82 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://controller:9292         |
+--------------+----------------------------------+
  3、安装和配置镜像服务
  3.1、安装glance



yum install openstack-glance
  3.2、配置glance(/etc/glance/glance-api.conf)
  3.2.1、在节点中,配置数据库访问




...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
  3.2.2、在和部分,配置身份服务访问
  NOTICE:注释掉或删除该部分中的任何其他选项 。




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

...
flavor = keystone
  3.2.3、在节中,配置本地文件系统存储和映像文件的位置




...
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
  3.3、配置glance(/etc/glance/glance-registry.conf)
  3.3.1、在节中,配置数据库访问




...
connection = mysql+pymysql://glance:GLANCE_DBPASS@controller/glance
  3.3.2、在和部分,配置身份服务访问




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

NOTICE:注释掉或删除该部分中的任何其他选项 。

...
flavor = keystone
  3.3.3、填充图像服务数据库



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

Option "verbose" from group "DEFAULT" is deprecated for removal.Its value may be silently ignored in the future.
/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1171: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade
expire_on_commit=expire_on_commit, _conf=conf)
/usr/lib/python2.7/site-packages/pymysql/cursors.py:166: Warning: (1831, u'Duplicate index `ix_image_properties_image_id_name`. This is deprecated and will be disallowed in a future release.')
result = self._query(query)
  NOTICE:忽略此输出中的任何废弃消息。
  3.3.4、启动镜像服务并设置为随机自启动



# systemctl enable openstack-glance-api.service \
openstack-glance-registry.service
# systemctl start openstack-glance-api.service \
openstack-glance-registry.service
  4、验证操作
  使用CirrOS验证图像服务的操作,这 是一个小型的Linux映像,可帮助您测试OpenStack部署。
  4.1、调用admin-openrc凭据



# source admin-openrc
  4.2、安装wget,下载镜像



# yum install wget
# wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
  4.3、使用QCOW2磁盘格式,裸机 容器格式和公共可见性将图像上传到图像服务 ,所以所有项目都可以访问它



# openstack image create "cirros" \
>   --file cirros-0.3.4-x86_64-disk.img \
>   --disk-format qcow2 --container-format bare \
>   --public
+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | ee1eca47dc88f4879d8a229cc70a07c6                     |
| container_format | bare                                                 |
| created_at       | 2017-07-19T10:54:04Z                                 |
| disk_format      | qcow2                                                |
| file             | /v2/images/69c87155-bd76-4ae7-bfce-53ad912b0463/file |
| id               | 69c87155-bd76-4ae7-bfce-53ad912b0463               |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | cirros                                             |
| owner            | 2ca49bfa14cb4229b8cc868ea0eede81                     |
| protected      | False                                                |
| schema         | /v2/schemas/image                                    |
| size             | 13287936                                             |
| status         | active                                             |
| tags             |                                                      |
| updated_at       | 2017-07-19T10:54:06Z                                 |
| virtual_size   | None                                                 |
| visibility       | public                                             |
+------------------+------------------------------------------------------+
  4.4、确认镜像上传状态正常(active)



# openstack image list
+--------------------------------------+--------+--------+
| ID                                 | Name   | Status |
+--------------------------------------+--------+--------+
| 69c87155-bd76-4ae7-bfce-53ad912b0463 | cirros | active |
+--------------------------------------+--------+--------+
页: [1]
查看完整版本: 3、OpenStack Image(镜像)服务