glance-api
glance-api 是系统后台运行的服务进程。 对外提供 REST API,响应 image 查询、获取和存储的调用。
glance-api 不会真正处理请求。 如果操作是与 image metadata(元数据)相关,glance-api 会把请求转发给 glance-registry; 如果操作是与 image 自身存取相关,glance-api 会把请求转发给该 image 的 store backend
glance-registry
glance-registry 是系统后台运行的服务进程。 负责处理和存取 image 的 metadata,例如 image 的大小和类型
Store backend
Glance 自己并不存储 image。 真正的 image 是存放在 backend 中的。 Glance 支持多种 backend,包括:
--A directory on a local file system(这是默认配置)
--GridFS
--Ceph RBD
--Amazon S3
--Sheepdog
--OpenStack Block Storage (Cinder)
--OpenStack Object Storage (Swift)
--VMware ESX
stack@controller:~$ openstack image list
+--------------------------------------+--------------------------+--------+
| ID | Name | Status |
+--------------------------------------+--------------------------+--------+
| fc8eecbe-9f86-4f64-b753-397a0f4104b6 | amphora-x64-haproxy | active |
| cc3ce379-33e0-4e51-876a-57f2d80f88f0 | cirros-0.4.0-x86_64-disk | active |
+--------------------------------------+--------------------------+--------+
存放路径:
stack@controller:~$ ll /opt/stack/data/glance/images/
total 333920
drwxr-xr-x 2 stack stack 4096 6月 15 23:44 ./
drwxr-xr-x 5 stack stack 4096 6月 15 23:42 ../
-rw-r--r-- 1 stack stack 12716032 6月 15 23:42 cc3ce379-33e0-4e51-876a-57f2d80f88f0
-rw-r--r-- 1 stack stack 329206784 6月 15 23:44 fc8eecbe-9f86-4f64-b753-397a0f4104b6
stack@controller:~$ openstack image show -f json cirros-0.4.0-x86_64-disk
{
"checksum": "443b7623e27ecf03dc9e01ee93f67afe",
"container_format": "bare",
"created_at": "2020-06-15T15:42:35Z",
"disk_format": "qcow2",
"file": "/v2/images/cc3ce379-33e0-4e51-876a-57f2d80f88f0/file",
"id": "cc3ce379-33e0-4e51-876a-57f2d80f88f0",
"min_disk": 0,
"min_ram": 0,
"name": "cirros-0.4.0-x86_64-disk",
"owner": "19e61e26bddc4dd9a942c7f7b936cff2",
"properties": {
"os_hidden": false,
"os_hash_algo": "sha512",
"os_hash_value": "6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78",
"owner_specified.openstack.md5": "",
"owner_specified.openstack.sha256": "",
"owner_specified.openstack.object": "images/cirros-0.4.0-x86_64-disk",
"hw_rng_model": "virtio"
},
"protected": false,
"schema": "/v2/schemas/image",
"size": 12716032,
"status": "active",
"tags": [],
"updated_at": "2020-06-15T15:42:35Z",
"visibility": "public"
}
查看glance的log
sudo journalctl -f --unit devstack@g-*
devstack的默认配置
stack@controller:~/devstack$ cat /etc/glance/glance-api.conf | grep -v ^$ | grep -v '#'
[DEFAULT]
logging_exception_prefix = ERROR %(name)s %(instance)s
logging_default_format_string = %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s
logging_context_format_string = %(color)s%(levelname)s %(name)s [%(global_request_id)s %(request_id)s %(project_name)s %(user_name)s%(color)s] %(instance)s%(color)s%(message)s
logging_debug_format_suffix = {{(pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d}}
public_endpoint = http://192.168.101.11/image
registry_host = 192.168.101.11
enable_v1_api = False
transport_url = rabbit://stackrabbit:admin@192.168.101.11:5672/
image_cache_dir = /opt/stack/data/glance/cache/
use_syslog = False
debug = True
[database]
connection = mysql+pymysql://root:admin@127.0.0.1/glance?charset=utf8
[oslo_concurrency]
lock_path = /opt/stack/data/glance/locks
[paste_deploy]
flavor = keystone+cachemanagement
[keystone_authtoken]
memcached_servers = localhost:11211
cafile = /opt/stack/data/ca-bundle.pem
project_domain_name = Default
project_name = service
user_domain_name = Default
password = admin
username = glance
auth_url = http://192.168.101.11/identity
auth_type = password
[oslo_messaging_notifications]
driver = messagingv2
[glance_store]
filesystem_store_datadir = /opt/stack/data/glance/images/
[cors]
allowed_origin = http://192.168.101.11
[key_manager]
backend = barbican
主要参数解释,其余可以参考 https://docs.openstack.org/glance/ussuri/configuration/glance_api.html
image_cache_dir
Base directory for image cache.
This is the location where image data is cached and served out of. All cached images are stored directly under this directory. This directory also contains three subdirectories, namely, incomplete, invalid and queue.
The incomplete subdirectory is the staging area for downloading images. An image is first downloaded to this directory. When the image download is successful it is moved to the base directory. However, if the download fails, the partially downloaded image file is moved to the invalid subdirectory.
The queue``subdirectory is used for queuing images for download. This is used primarily by the cache-prefetcher, which can be scheduled as a periodic task like cache-pruner and cache-cleaner, to cache images ahead of their usage. Upon receiving the request to cache an image, Glance touches a file in the ``queue directory with the image id as the file name. The cache-prefetcher, when running, polls for the files in queue directory and starts downloading them in the order they were created. When the download is successful, the zero-sized file is deleted from the queue directory. If the download fails, the zero-sized file remains and it’ll be retried the next time cache-prefetcher runs.
stack@controller:~$ ll /opt/stack/data/glance/cache/
total 12452
drwxr-xr-x 5 stack stack 4096 6月 20 23:16 ./
drwxr-xr-x 5 stack stack 4096 6月 15 23:42 ../
-rw-r--r-- 1 stack stack 12288 6月 20 23:16 cache.db
-rw-r--r-- 1 stack stack 12716032 6月 16 10:21 cc3ce379-33e0-4e51-876a-57f2d80f88f0
drwxr-xr-x 2 stack stack 4096 6月 16 10:21 incomplete/
drwxr-xr-x 2 stack stack 4096 6月 15 23:42 invalid/
drwxr-xr-x 2 stack stack 4096 6月 15 23:42 queue/
paste_deploy -- flavor(default: keystone)
Deployment flavor to use in the server application pipeline.
Provide a string value representing the appropriate deployment flavor used in the server application pipleline. This is typically the partial name of a pipeline in the paste configuration file with the service name removed.
For example, if your paste section name in the paste configuration file is [pipeline:glance-api-keystone], set flavor to keystone.
glance_store -- filesystem_store_datadir(default: /var/lib/glance/images)
Directory to which the filesystem backend store writes images.
Upon start up, Glance creates the directory if it doesn’t already exist and verifies write access to the user under which glance-api runs. If the write access isn’t available, a BadStoreConfiguration exception is raised and the filesystem store may not be available for adding new images.
NOTE: This directory is used only when filesystem store is used as a storage backend. Either filesystem_store_datadir or filesystem_store_datadirs option must be specified in glance-api.conf. If both options are specified, a BadStoreConfiguration will be raised and the filesystem store may not be available for adding new images.
stack@controller:~$ cat /etc/glance/glance-registry.conf | grep -v ^$ | grep -v '#'
[DEFAULT]
logging_exception_prefix = ERROR %(name)s %(instance)s
logging_default_format_string = %(color)s%(levelname)s %(name)s [-%(color)s] %(instance)s%(color)s%(message)s
logging_context_format_string = %(color)s%(levelname)s %(name)s [%(global_request_id)s %(request_id)s %(project_name)s %(user_name)s%(color)s] %(instance)s%(color)s%(message)s
logging_debug_format_suffix = {{(pid=%(process)d) %(funcName)s %(pathname)s:%(lineno)d}}
graceful_shutdown_timeout = 5
transport_url = rabbit://stackrabbit:admin@192.168.101.11:5672/
use_syslog = False
workers = 2
bind_host = 0.0.0.0
debug = True
[database]
connection = mysql+pymysql://root:admin@127.0.0.1/glance?charset=utf8
[paste_deploy]
flavor = keystone
[keystone_authtoken]
memcached_servers = localhost:11211
cafile = /opt/stack/data/ca-bundle.pem
project_domain_name = Default
project_name = service
user_domain_name = Default
password = admin
username = glance
auth_url = http://192.168.101.11/identity
auth_type = password
[oslo_messaging_notifications]
driver = messagingv2
主要参数解释,其余可以参考 https://docs.openstack.org/glance/ussuri/configuration/glance_registry.html
workers
Number of Glance worker processes to start.
Provide a non-negative integer value to set the number of child process workers to service requests. By default, the number of CPUs available is set as the value for workers limited to 8. For example if the processor count is 6, 6 workers will be used, if the processor count is 24 only 8 workers will be used. The limit will only apply to the default value, if 24 workers is configured, 24 is used.
Each worker process is made to listen on the port set in the configuration file and contains a greenthread pool of size 1000.
NOTE: Setting the number of workers to zero, triggers the creation of a single API process with a greenthread pool of size 1000.
root@controller:~# ps -ef | grep glance-registry
stack 6560 1 0 02:19 ? 00:07:59 /usr/bin/python3.6 /usr/local/bin/glance-registry --config-file=/etc/glance/glance-registry.conf
stack 6671 6560 0 02:20 ? 00:00:00 /usr/bin/python3.6 /usr/local/bin/glance-registry --config-file=/etc/glance/glance-registry.conf
stack 6672 6560 0 02:20 ? 00:00:00 /usr/bin/python3.6 /usr/local/bin/glance-registry --config-file=/etc/glance/glance-registry.conf
1个父进程2个子进程
bind_host(default: 0.0.0.0)
IP address to bind the glance servers to.
Provide an IP address to bind the glance server to. The default value is 0.0.0.0.
Edit this option to enable the server to listen on one particular IP address on the network card. This facilitates selection of a particular network interface for the server.
数据库访问
stack@controller:~$ mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| barbican |
| cinder |
| glance |
| keystone |
| mysql |
| neutron |
| nova_api |
| nova_cell0 |
| nova_cell1 |
| octavia |
| performance_schema |
| placement |
| sys |
+--------------------+
mysql> use glance
mysql> 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 |
+----------------------------------+
mysql> select * from images;
+--------------------------------------+--------------------------+-----------+--------+---------------------+---------------------+------------+---------+-------------+------------------+----------------------------------+----------------------------------+----------+---------+-----------+--------------+------------+-----------+--------------+----------------------------------------------------------------------------------------------------------------------------------+
| id | name | size | status | created_at | updated_at | deleted_at | deleted | disk_format | container_format | checksum | owner | min_disk | min_ram | protected | virtual_size | visibility | os_hidden | os_hash_algo | os_hash_value |
+--------------------------------------+--------------------------+-----------+--------+---------------------+---------------------+------------+---------+-------------+------------------+----------------------------------+----------------------------------+----------+---------+-----------+--------------+------------+-----------+--------------+----------------------------------------------------------------------------------------------------------------------------------+
| cc3ce379-33e0-4e51-876a-57f2d80f88f0 | cirros-0.4.0-x86_64-disk | 12716032 | active | 2020-06-15 15:42:35 | 2020-06-15 15:42:35 | NULL | 0 | qcow2 | bare | 443b7623e27ecf03dc9e01ee93f67afe | 19e61e26bddc4dd9a942c7f7b936cff2 | 0 | 0 | 0 | NULL | public | 0 | sha512 | 6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78 |
| fc8eecbe-9f86-4f64-b753-397a0f4104b6 | amphora-x64-haproxy | 329206784 | active | 2020-06-15 15:44:29 | 2020-06-15 15:44:33 | NULL | 0 | qcow2 | bare | 2e0880d1540b939d59b00e98756ccc5c | 19e61e26bddc4dd9a942c7f7b936cff2 | 0 | 0 | 0 | NULL | public | 0 | sha512 | a67d0e98046a28b5571ee89d0ee51600f5276ef654c7a6dd0ee726e08b35e7dd22166c85d9818ea6a52ac1572e99a8ecbbd85d0ab63ff7ec0bbf07eb1c09d755 |
+--------------------------------------+--------------------------+-----------+--------+---------------------+---------------------+------------+---------+-------------+------------------+----------------------------------+----------------------------------+----------+---------+-----------+--------------+------------+-----------+--------------+----------------------------------------------------------------------------------------------------------------------------------+
API访问
stack@controller:~/devstack$ openstack token issue -f value -c id
gAAAAABe9LHutvUf7-HnnewthBIdqg58Ra5VVkAcRKA8wfyjz-cDzocbktW7SO8dUkwygu2u_J0fecf1DXO3WzktbOU1idpSlt9E1MCjGSm1hcVsPCbwgazwVe51pYaeDV_3tN-eaFsdun2laz1_Vx5nryHm3pdK1FjJtXRrFwQu2lRmJR33cew
stack@controller:~/devstack$ TOKEN='gAAAAABe9LHutvUf7-HnnewthBIdqg58Ra5VVkAcRKA8wfyjz-cDzocbktW7SO8dUkwygu2u_J0fecf1DXO3WzktbOU1idpSlt9E1MCjGSm1hcVsPCbwgazwVe51pYaeDV_3tN-eaFsdun2laz1_Vx5nryHm3pdK1FjJtXRrFwQu2lRmJR33cew'
stack@controller:~/devstack$ curl http://192.168.101.11/image/v2/images -H "x-auth-token: $TOKEN" -X GET
{"images": [{"hw_rng_model": "virtio", "owner_specified.openstack.md5": "", "owner_specified.openstack.sha256": "", "owner_specified.openstack.object": "images/amphora-x64-haproxy", "hw_architecture": "x86_64", "name": "amphora-x64-haproxy", "disk_format": "qcow2", "container_format": "bare", "visibility": "public", "size": 329206784, "virtual_size": null, "status": "active", "checksum": "2e0880d1540b939d59b00e98756ccc5c", "protected": false, "min_ram": 0, "min_disk": 0, "owner": "19e61e26bddc4dd9a942c7f7b936cff2", "os_hidden": false, "os_hash_algo": "sha512", "os_hash_value": "a67d0e98046a28b5571ee89d0ee51600f5276ef654c7a6dd0ee726e08b35e7dd22166c85d9818ea6a52ac1572e99a8ecbbd85d0ab63ff7ec0bbf07eb1c09d755", "id": "fc8eecbe-9f86-4f64-b753-397a0f4104b6", "created_at": "2020-06-15T15:44:29Z", "updated_at": "2020-06-15T15:44:33Z", "tags": ["amphora"], "self": "/v2/images/fc8eecbe-9f86-4f64-b753-397a0f4104b6", "file": "/v2/images/fc8eecbe-9f86-4f64-b753-397a0f4104b6/file", "schema": "/v2/schemas/image"}, {"hw_rng_model": "virtio", "owner_specified.openstack.md5": "", "owner_specified.openstack.sha256": "", "owner_specified.openstack.object": "images/cirros-0.4.0-x86_64-disk", "name": "cirros-0.4.0-x86_64-disk", "disk_format": "qcow2", "container_format": "bare", "visibility": "public", "size": 12716032, "virtual_size": null, "status": "active", "checksum": "443b7623e27ecf03dc9e01ee93f67afe", "protected": false, "min_ram": 0, "min_disk": 0, "owner": "19e61e26bddc4dd9a942c7f7b936cff2", "os_hidden": false, "os_hash_algo": "sha512", "os_hash_value": "6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78", "id": "cc3ce379-33e0-4e51-876a-57f2d80f88f0", "created_at": "2020-06-15T15:42:35Z", "updated_at": "2020-06-15T15:42:35Z", "tags": [], "self": "/v2/images/cc3ce379-33e0-4e51-876a-57f2d80f88f0", "file": "/v2/images/cc3ce379-33e0-4e51-876a-57f2d80f88f0/file", "schema": "/v2/schemas/image"}], "first": "/v2/images", "schema": "/v2/schemas/images"}
本文深入探讨了OpenStack中的Glance镜像服务,详细介绍了glance-api和glance-registry的功能,以及它们如何处理镜像查询、存储和元数据管理。文章还展示了镜像的存储位置、缓存机制和数据库配置,以及如何通过API访问和管理镜像。
1529

被折叠的 条评论
为什么被折叠?



