配额和限制¶
限制是对共享文件系统服务 (manila) 消费者的使用限制。这些限制可以分为两种类型
资源消耗限制(也称为
配额)API 使用限制(也称为
速率限制)
管理员可以在任何时候设置和操作这些限制。用户可以查询他们的速率限制和配额。如果管理员没有显式设置限制,该服务不会施加任何速率限制,但会强制执行默认资源限制(也称为 默认 配额)。
用户可以使用 openstack share limits show --absolute 命令查询他们的绝对限制。
$ openstack share limits show --absolute
+------------------------------+-------+
| Name | Value |
+------------------------------+-------+
| maxTotalShares | 50 |
| maxTotalShareSnapshots | 50 |
| maxTotalShareGigabytes | 1000 |
| maxTotalSnapshotGigabytes | 1000 |
| maxTotalShareNetworks | 10 |
| maxTotalShareGroups | 50 |
| maxTotalShareGroupSnapshots | 50 |
| maxTotalShareReplicas | 100 |
| maxTotalReplicaGigabytes | 1000 |
| maxTotalShareBackups | 10 |
| maxTotalBackupGigabytes | 1000 |
| totalSharesUsed | 2 |
| totalShareSnapshotsUsed | 0 |
| totalShareGigabytesUsed | 2 |
| totalSnapshotGigabytesUsed | 0 |
| totalShareNetworksUsed | 0 |
| totalShareGroupsUsed | 0 |
| totalShareGroupSnapshotsUsed | 0 |
| totalShareReplicasUsed | 0 |
| totalReplicaGigabytesUsed | 0 |
| totalShareBackupsUsed | 0 |
| totalBackupGigabytesUsed | 0 |
+------------------------------+-------+
API 速率限制¶
API 速率限制控制用户可以发出特定 API 请求的频率。管理员可以使用速率限制来控制在特定时间间隔内可以发出的 API 调用类型和数量。例如,速率限制可以控制在 1 分钟期间处理的 GET 请求的数量。
要设置 API 速率限制,请复制并修改 etc/manila/api-paste.ini 文件。编辑 api-paste.ini 文件后,需要重新启动 manila-api 服务。
[filter:ratelimit]
paste.filter_factory = manila.api.v1.limits:RateLimitingMiddleware.factory
limits = (POST, "*/shares", ^/shares, 120, MINUTE);(PUT, "*/shares", .*, 120, MINUTE);(DELETE, "*", .*, 120, MINUTE)
此外,将 ratelimit 添加到 noauth 和 keystone 参数中,位于 [composite:openstack_share_api] 和 [composite:openstack_share_api_v2] 组中。
[composite:openstack_share_api]
use = call:manila.api.middleware.auth:pipeline_factory
noauth = cors faultwrap ssl ratelimit sizelimit noauth api
keystone = cors faultwrap ssl ratelimit sizelimit authtoken keystonecontext api
keystone_nolimit = cors faultwrap ssl sizelimit authtoken keystonecontext api
[composite:openstack_share_api_v2]
use = call:manila.api.middleware.auth:pipeline_factory
noauth = cors faultwrap ssl ratelimit sizelimit noauth apiv2
keystone = cors faultwrap ssl ratelimit sizelimit authtoken keystonecontext apiv2
keystone_nolimit = cors faultwrap ssl sizelimit authtoken keystonecontext apiv2
最后,将 [DEFAULT]/api_rate_limit 参数在 manila.conf 中设置为 True。
[DEFAULT]
api_rate_limit=True
要查看速率限制,请运行
$ openstack share limits show --rate
+--------+----------+------------+-------+-----------+--------+----------------------+
| Verb | Regex | URI | Value | Remaining | Unit | Next Available |
+--------+----------+------------+-------+-----------+--------+----------------------+
| POST | ^/shares | "*/shares" | 120 | 120 | MINUTE | 2025-02-25T02:15:39Z |
| PUT | .* | "*/shares" | 120 | 120 | MINUTE | 2025-02-25T02:15:39Z |
| DELETE | .* | "*" | 120 | 120 | MINUTE | 2025-02-25T02:15:39Z |
+--------+----------+------------+-------+-----------+--------+----------------------+
默认资源配额¶
可以设置 shares、snapshots、share-networks、share_groups(需要 API 版本 2.40)、share_group_snapshots(需要 API 版本 2.40)和 share_replicas(需要 API 版本 2.53)的数量限制。除了限制之外,还可以使用 gigabytes(允许的共享总大小)、snapshot-gigabytes(允许的快照总大小)、replica_gigabytes(需要 API 版本 2.53)或 per_share_gigabytes(需要 API 版本 2.62)设置容量限制。
如果管理员没有设置这些资源配额,则服务中硬编码的默认配额将适用。要查看这些默认配额,管理员可以使用 openstack share quota show –class default 命令
$ openstack share quota show %project_id% --defaults
+-----------------------+----------------------------------+
| Field | Value |
+-----------------------+----------------------------------+
| backup_gigabytes | 1000 |
| backups | 10 |
| gigabytes | 1000 |
| id | a0ce678da60e4ca18010016d44ee6e83 |
| per_share_gigabytes | -1 |
| replica_gigabytes | 1000 |
| share_group_snapshots | 50 |
| share_groups | 50 |
| share_networks | 10 |
| share_replicas | 100 |
| shares | 50 |
| snapshot_gigabytes | 1000 |
| snapshots | 50 |
+-----------------------+----------------------------------+
管理员可以使用 openstack share quota set --class default 命令修改默认配额
openstack share quota set --class default --shares 30 --snapshots 50 --share-groups 15
或者,您也可以通过 manila.conf 指定这些默认值。以下是一个示例
[quota]
shares = 30
share_gigabytes = 10000
share_networks = 50
share_snapshots = 100
重要提示
通过 API 指定的默认配额始终优先于通过 manila.conf 应用的任何默认值。因此,建议在创建或操作默认配额时始终使用 API。
自定义配额¶
管理员可以为特定项目、项目内的特定用户或项目使用的共享类型自定义配额。
要列出项目或用户的配额,请使用 openstack share quota show 命令。如果您指定可选的 --user 参数,您将获得指定项目中此用户的配额。如果您省略此参数,您将获得指定项目的配额。如果没有覆盖,显示的配额将与默认值匹配。
注意
共享文件系统服务不会将用户名和项目名称映射到 ID。仅提供 ID 值才能正确设置配额。通过名称设置配额,您将为不存在的项目/用户设置配额。如果配额未通过项目/用户 ID 显式设置,共享文件系统服务将仅应用默认配额。
$ openstack share quota show %project_id% --user %user_id%
+-----------------------+----------------------------------+
| Field | Value |
+-----------------------+----------------------------------+
| backup_gigabytes | 1000 |
| backups | 10 |
| gigabytes | 1000 |
| id | a0ce678da60e4ca18010016d44ee6e83 |
| per_share_gigabytes | -1 |
| replica_gigabytes | 1000 |
| share_group_snapshots | 50 |
| share_groups | 50 |
| share_networks | 10 |
| share_replicas | 100 |
| shares | 50 |
| snapshot_gigabytes | 1000 |
| snapshots | 50 |
+-----------------------+----------------------------------+
可以使用 openstack share quota set 命令更新这些配额。
$ openstack share quota set %project_id% --user %user_id% --shares 49 --snapshots 49
该服务将阻止将配额设置为低于当前消耗量。但是,如果需要,仍然可以使用 `force` 键进行配额更新。
$ openstack share quota set %project_id% --shares 51 --snapshots 51 --force
管理员还可以更新特定共享类型的配额。共享类型配额不能设置为项目内的单个用户。它们只能应用于特定项目的全部用户。
$ openstack share quota set %project_id% --share-type %share_type_id%
要将配额恢复为项目的默认值或用户的默认值,只需删除已设置的配额
$ openstack share quota delete %project_id% --user %user_id%
共享类型配额可以以相同的方式恢复。但是,共享类型配额不能设置为项目内的单个用户,因此也不能取消设置。
$ openstack share quota delete %project_id% --share-type %share_type_id%