OpenStack 之 Glance 安装

创建 glance 数据库,并授权

[root@openstack ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 23
Server version: 10.1.20-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

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

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

安装 glance

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

编辑配置文件 /etc/glance/glance-api.conf,完成如下配置修改

[database] 下,配置数据库连接:

[database]
# ...
connection = mysql+pymysql://glance:glance@192.168.1.140/glance

[keystone_authtoken][paste_deploy] 下,配置认证服务

[keystone_authtoken]
# ...
www_authenticate_uri  = http://192.168.1.140:5000
auth_url = http://192.168.1.140:5000
memcached_servers = 192.168.1.140:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = glance

[paste_deploy]
# ...
flavor = keystone

[glance_store] 下,配置本地文件系统存储和本地镜像文件:

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

编辑 /etc/glance/glance-registry.conf文件完成如下配置:

[database] 下,配置数据库连接:

[database]
# ...
connection = mysql+pymysql://glance:glance@192.168.1.140/glance

[keystone_authtoken][paste_deploy] 下,配置认证服务

www_authenticate_uri = http://192.168.1.140:5000
auth_url = http://192.168.1.140:5000
memcached_servers = 192.168.1.140:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = glance

[paste_deploy]
# ...
flavor = keystone

同步数据库

[root@openstack ~]# su -s /bin/sh -c "glance-manage db_sync" glance
/usr/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py:1352: 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] Running upgrade queens_expand01 -> rocky_expand01, add os_hidden column to images table
INFO  [alembic.runtime.migration] Running upgrade rocky_expand01 -> rocky_expand02, add os_hash_algo and os_hash_value columns to images table
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: rocky_expand02, current revision(s): rocky_expand02
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] Running upgrade queens_contract01 -> rocky_contract01
INFO  [alembic.runtime.migration] Running upgrade rocky_contract01 -> rocky_contract02
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Upgraded database to: rocky_contract02, current revision(s): rocky_contract02
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
Database is synced successfully.

验证数据库是否同步成功

[root@openstack ~]# mysql -h 192.168.1.140 -u glance -pglance -e "USE glance; 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                            |
+----------------------------------+

启动服务

[root@openstack ~]# systemctl enable openstack-glance-api.service \
  openstack-glance-registry.service
[root@openstack ~]# systemctl start openstack-glance-api.service \
  openstack-glance-registry.service

验证服务是否启动正常

[root@openstack ~]# systemctl status openstack-glance-api.service   openstack-glance-registry.service     
● openstack-glance-api.service - OpenStack Image Service (code-named Glance) API server
   Loaded: loaded (/usr/lib/systemd/system/openstack-glance-api.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-01-12 12:03:04 CST; 6s ago
 Main PID: 10713 (glance-api)
   CGroup: /system.slice/openstack-glance-api.service
           ├─10713 /usr/bin/python2 /usr/bin/glance-api
           ├─10743 /usr/bin/python2 /usr/bin/glance-api
           ├─10744 /usr/bin/python2 /usr/bin/glance-api
           ├─10745 /usr/bin/python2 /usr/bin/glance-api
           ├─10746 /usr/bin/python2 /usr/bin/glance-api
           ├─10747 /usr/bin/python2 /usr/bin/glance-api
           ├─10748 /usr/bin/python2 /usr/bin/glance-api
           ├─10749 /usr/bin/python2 /usr/bin/glance-api
           └─10750 /usr/bin/python2 /usr/bin/glance-api

Jan 12 12:03:06 openstack glance-api[10713]: /usr/lib/python2.7/site-packages/paste/deploy/loadwsgi.py:22: Deprecation...ately.
Jan 12 12:03:06 openstack glance-api[10713]: return pkg_resources.EntryPoint.parse("x=" + s).load(False)
Jan 12 12:03:06 openstack glance-api[10713]: /usr/lib/python2.7/site-packages/paste/deploy/loadwsgi.py:22: Deprecation...ately.
Jan 12 12:03:06 openstack glance-api[10713]: return pkg_resources.EntryPoint.parse("x=" + s).load(False)
Jan 12 12:03:07 openstack glance-api[10713]: /usr/lib/python2.7/site-packages/paste/deploy/loadwsgi.py:22: Deprecation...ately.
Jan 12 12:03:07 openstack glance-api[10713]: return pkg_resources.EntryPoint.parse("x=" + s).load(False)
Jan 12 12:03:07 openstack glance-api[10713]: /usr/lib/python2.7/site-packages/paste/deploy/loadwsgi.py:22: Deprecation...ately.
Jan 12 12:03:07 openstack glance-api[10713]: return pkg_resources.EntryPoint.parse("x=" + s).load(False)
Jan 12 12:03:07 openstack glance-api[10713]: /usr/lib/python2.7/site-packages/paste/deploy/util.py:55: DeprecationWarn...filter
Jan 12 12:03:07 openstack glance-api[10713]: val = callable(*args, **kw)

● openstack-glance-registry.service - OpenStack Image Service (code-named Glance) Registry server
   Loaded: loaded (/usr/lib/systemd/system/openstack-glance-registry.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-01-12 12:03:04 CST; 6s ago
 Main PID: 10714 (glance-registry)
   CGroup: /system.slice/openstack-glance-registry.service
           ├─10714 /usr/bin/python2 /usr/bin/glance-registry
           ├─10735 /usr/bin/python2 /usr/bin/glance-registry
           ├─10736 /usr/bin/python2 /usr/bin/glance-registry
           ├─10737 /usr/bin/python2 /usr/bin/glance-registry
           ├─10738 /usr/bin/python2 /usr/bin/glance-registry
           ├─10739 /usr/bin/python2 /usr/bin/glance-registry
           ├─10740 /usr/bin/python2 /usr/bin/glance-registry
           ├─10741 /usr/bin/python2 /usr/bin/glance-registry
           └─10742 /usr/bin/python2 /usr/bin/glance-registry

Jan 12 12:03:06 openstack glance-registry[10714]: /usr/lib/python2.7/site-packages/paste/deploy/loadwsgi.py:22: Depreca...tely.
Jan 12 12:03:06 openstack glance-registry[10714]: return pkg_resources.EntryPoint.parse("x=" + s).load(False)
Jan 12 12:03:06 openstack glance-registry[10714]: /usr/lib/python2.7/site-packages/paste/deploy/loadwsgi.py:22: Depreca...tely.
Jan 12 12:03:06 openstack glance-registry[10714]: return pkg_resources.EntryPoint.parse("x=" + s).load(False)
Jan 12 12:03:06 openstack glance-registry[10714]: /usr/lib/python2.7/site-packages/paste/deploy/loadwsgi.py:22: Depreca...tely.
Jan 12 12:03:06 openstack glance-registry[10714]: return pkg_resources.EntryPoint.parse("x=" + s).load(False)
Jan 12 12:03:06 openstack glance-registry[10714]: /usr/lib/python2.7/site-packages/glance/registry/api/__init__.py:36: ...oval.
Jan 12 12:03:06 openstack glance-registry[10714]: debtcollector.deprecate("Glance Registry service has been "
Jan 12 12:03:06 openstack glance-registry[10714]: /usr/lib/python2.7/site-packages/paste/deploy/util.py:55: Deprecation...ilter
Jan 12 12:03:06 openstack glance-registry[10714]: val = callable(*args, **kw)
Hint: Some lines were ellipsized, use -l to show in full.

创建 keystoen 认证

[root@openstack ~]# openstack user list
+----------------------------------+--------+
| ID                               | Name   |
+----------------------------------+--------+
| 3eadfcb80ec146cda9539270e661da04 | glance |
| 8d5d59cfa782442a8b0a2dc1509282db | admin  |
| a504670c5dd2462a8564ac56fecf922a | myuser |
+----------------------------------+--------+
[root@openstack ~]# openstack role add --project service --user glance admin
[root@openstack ~]# openstack service create --name glance \
>   --description "OpenStack Image" image
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Image                  |
| enabled     | True                             |
| id          | 7df7d803c8484892b890ed669745e1f0 |
| name        | glance                           |
| type        | image                            |
+-------------+----------------------------------+
[root@openstack ~]# openstack endpoint create --region RegionOne \
>   image public http://192.168.1.140:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | aeb41d2dace346e19d43db903a128264 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 7df7d803c8484892b890ed669745e1f0 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.1.140:9292        |
+--------------+----------------------------------+
[root@openstack ~]# openstack endpoint create --region RegionOne   image internal http://192.168.1.140:9292
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 89a5e68791c04761b7cbc3b93654d9f4 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 7df7d803c8484892b890ed669745e1f0 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.1.140:9292        |
+--------------+----------------------------------+
[root@openstack ~]# openstack endpoint create --region RegionOne   image admin http://192.168.1.140:9292   
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 9c8c47515a57403298d95f0afaf3002a |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 7df7d803c8484892b890ed669745e1f0 |
| service_name | glance                           |
| service_type | image                            |
| url          | http://192.168.1.140:9292        |
+--------------+----------------------------------+

下载镜像

wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
[root@openstack ~]# openstack image create "cirros" \
>   --file cirros-0.4.0-x86_64-disk.img \
>   --disk-format qcow2 --container-format bare \
>   --public
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | 6d03f3d7e491e36945a99313eabb3a9d                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2019-01-14T06:45:43Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/2fd4e473-cd41-4391-af79-08376dcdc97e/file                                                                                                                                       |
| id               | 2fd4e473-cd41-4391-af79-08376dcdc97e                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | cirros                                                                                                                                                                                     |
| owner            | 48d70011a03f4639944aaf7b69f97bc4                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='282f01c49f1724233c5a426f717f7a02de546899c3afb5821a64980ea97879a982e48e30d63a5ce9a790b04e99441a9c182f8789d55288830a4716d13a1aafcb', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 3620122                                                                                                                                                                                    |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2019-01-14T06:45:43Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | public                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

验证镜像是否创建成功

[root@openstack ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 2fd4e473-cd41-4391-af79-08376dcdc97e | cirros | active |
+--------------------------------------+--------+--------+
posted @ 2019-01-12 12:04  McSiberiaWolf  阅读(834)  评论(0)    收藏  举报