A04. openstack架构实战-glance服务安装

镜像服务 (glance) 允许用户发现、注册和获取虚拟机镜像。它提供了一个 REST API,允许您查询虚拟机镜像的 metadata 并获取一个现存的镜像。您可以将虚拟机镜像存储到各种位置,从简单的文件系统到对象存储系统—-例如 OpenStack 对象存储, 并通过镜像服务使用。

 

1:创建glance数据库:

MariaDB [keystone]> CREATE DATABASE glance;
Query OK, 1 row affected (0.00 sec)

2:对glance数据库授权

MariaDB [keystone]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
-> IDENTIFIED BY 'huayun';
Query OK, 0 rows affected (0.01 sec)

MariaDB [keystone]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
-> IDENTIFIED BY 'huayun';
Query OK, 0 rows affected (0.00 sec)

 

要创建服务凭证,请完成以下步骤:

[root@controller01 ~]# source admin-openrc

1:创建glance用户:

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

2:添加admin角色搭配glance用户和service项目上

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

3:在keystone创建glance服务

[root@controller01 ~]# openstack service create --name glance \
> --description "OpenStack Image" image
+-------------+----------------------------------+
| Field | Value |
+-------------+----------------------------------+
| description | OpenStack Image |
| enabled | True |
| id | 4d5a4cbfc6644cf39601fca9244d1152 |
| name | glance |
| type | image |
+-------------+----------------------------------+

4:在keystone创建镜像服务api接口

全局接口api:public

[root@controller01 ~]# openstack endpoint create --region RegionOne \
> image public http://controller01:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 4aa6a612f66e4a7d9c16891df2f2503e |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 4d5a4cbfc6644cf39601fca9244d1152 |
| service_name | glance |
| service_type | image |
| url | http://controller01:9292 |
+--------------+----------------------------------+

internal:内部接口api

[root@controller01 ~]# openstack endpoint create --region RegionOne \
> image internal http://controller01:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | f95905ed24314bc697e1528cddf4290c |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 4d5a4cbfc6644cf39601fca9244d1152 |
| service_name | glance |
| service_type | image |
| url | http://controller01:9292 |
+--------------+----------------------------------+

管理员接口 api

[root@controller01 ~]# openstack endpoint create --region RegionOne \
> image admin http://controller01:9292
+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 949d6ac87e5e483882a7f91d1fbfd85b |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 4d5a4cbfc6644cf39601fca9244d1152 |
| service_name | glance |
| service_type | image |
| url | http://controller01:9292 |
+--------------+----------------------------------+

5:安装glance软件包:

[root@controller01 ~]# yum install openstack-glance -y 

 

6:编辑/etc/glance/glance-api.conf文件并完成以下操作:

备份glance配置文件:

[root@controller01 ~]# cp /etc/glance/glance-api.conf /etc/glance/glance-api.conf.bak

 

在该[database]部分中,配置数据库访问

[database]
connection = mysql+pymysql://glance:huayun@controller01/glance

 

[keystone_authtoken][paste_deploy]部分中,配置身份服务访问:

[keystone_authtoken]
auth_uri = http://controller01:5000
auth_url = http://controller01:5000
memcached_servers = controller01:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = huayun

 

[paste_deploy]
flavor = keystone

 

在该[glance_store]部分中,配置本地文件系统存储和图像文件的位置:

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

 

7: 编辑文件 /etc/glance/glance-registry.conf并完成如下动作:

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

[database]
connection = mysql+pymysql://glance:huayun@controller01/glance

 

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

[keystone_authtoken]
auth_uri = http://controller01:5000
auth_url = http://controller01:5000
memcached_servers = controller01:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = huayun

 

[paste_deploy]
flavor = keystone

 

4:同步配置信息,写入镜像服务数据库:

[root@controller01 ~]# su -s /bin/sh -c "glance-manage db_sync" glance
/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1336: OsloDBDeprecationWarning: EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade
expire_on_commit=expire_on_commit, _conf=conf)
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> liberty, liberty initial
INFO [alembic.runtime.migration] Running upgrade liberty -> mitaka01, add index on created_at and updated_at columns of 'images' table
INFO [alembic.runtime.migration] Running upgrade mitaka01 -> mitaka02, update metadef os_nova_server
INFO [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_expand01, add visibility to images
INFO [alembic.runtime.migration] Running upgrade ocata_expand01 -> pike_expand01, empty expand for symmetry with pike_contract01
INFO [alembic.runtime.migration] Running upgrade pike_expand01 -> queens_expand01
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: queens_expand01, current revision(s): queens_expand01
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Database migration is up to date. No migration needed.
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade mitaka02 -> ocata_contract01, remove is_public from images
INFO [alembic.runtime.migration] Running upgrade ocata_contract01 -> pike_contract01, drop glare artifacts tables
INFO [alembic.runtime.migration] Running upgrade pike_contract01 -> queens_contract01
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: queens_contract01, current revision(s): queens_contract01
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
Database is synced successfully.

 

查看数据库是否同步成功:

[root@controller01 ~]# mysql -uroot -phuayun glance -e "show tables"
+----------------------------------+
| Tables_in_glance |
+----------------------------------+
| alembic_version |
| image_locations |
| image_members |
| image_properties |
| image_tags |
| images |
| metadef_namespace_resource_types |
| metadef_namespaces |
| metadef_objects |
| metadef_properties |
| metadef_resource_types |
| metadef_tags |
| migrate_version |
| task_info |
| tasks |
+----------------------------------+

 

5:设置glance的开机启动

[root@controller01 ~]# systemctl enable openstack-glance-api.service && systemctl enable openstack-glance-registry.service 

[root@controller01 ~]# 0

查看glance监控的端口

 

 

 

验证镜像服务:

1:下载源镜像:

[root@controller01 ~]#  wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img

2:使用 QCOW2 磁盘格式, bare 容器格式上传镜像到镜像服务并设置公共可见,这样所有的项目都可以访问它:

[root@controller01 ~]# 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 | 2020-05-24T07:26:06Z |
| disk_format | qcow2 |
| file | /v2/images/423fe51f-6c08-4ba5-9248-fb107788b555/file |
| id | 423fe51f-6c08-4ba5-9248-fb107788b555 |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | f4228d6dfa07453c84996e5f2be19ca2 |
| protected | False |
| schema | /v2/schemas/image |
| size | 12716032 |
| status | active |
| tags | |
| updated_at | 2020-05-24T07:26:06Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+

[root@controller01 ~]# glance image-list
+--------------------------------------+--------+
| ID | Name |
+--------------------------------------+--------+
| 423fe51f-6c08-4ba5-9248-fb107788b555 | cirros |
+--------------------------------------+--------+

 

查看镜像存放路径:

[root@controller01 ~]# md5sum /var/lib/glance/images/423fe51f-6c08-4ba5-9248-fb107788b555
443b7623e27ecf03dc9e01ee93f67afe /var/lib/glance/images/423fe51f-6c08-4ba5-9248-fb107788b555

[root@controller01 ~]# md5sum cirros-0.4.0-x86_64-disk.img
443b7623e27ecf03dc9e01ee93f67afe cirros-0.4.0-x86_64-disk.img

 

posted @ 2020-05-24 15:28  Mr-呵呵哒  阅读(213)  评论(0编辑  收藏  举报