高可用块存储 API

Cinder 提供适合对性能敏感场景的块存储即服务,例如数据库、可扩展文件系统或为服务器提供对原始块级别存储的访问。

持久块存储可以在实例终止后幸存,并且也可以像任何外部存储设备一样在实例之间移动。Cinder 还具有卷快照功能,用于备份卷。

以主动/被动模式使块存储 API 服务高可用涉及

理论上,您可以将块存储服务作为主动/主动运行。但是,由于存在足够的顾虑,我们建议仅以主动/被动模式运行卷组件。

您可以在 Red Hat Bugzilla 上了解更多关于这些顾虑的信息,并且有一个 伪路线图 用于上游解决它们。

将块存储 API 资源添加到 Pacemaker

在基于 RHEL 的系统上,为 cinder 的 systemd 代理创建资源,并创建约束以强制执行启动/关闭顺序

pcs resource create openstack-cinder-api systemd:openstack-cinder-api --clone interleave=true
pcs resource create openstack-cinder-scheduler systemd:openstack-cinder-scheduler --clone interleave=true
pcs resource create openstack-cinder-volume systemd:openstack-cinder-volume

pcs constraint order start openstack-cinder-api-clone then openstack-cinder-scheduler-clone
pcs constraint colocation add openstack-cinder-scheduler-clone with openstack-cinder-api-clone
pcs constraint order start openstack-cinder-scheduler-clone then openstack-cinder-volume
pcs constraint colocation add openstack-cinder-volume with openstack-cinder-scheduler-clone

如果块存储服务与其它服务运行在同一节点上,那么建议也包含

pcs constraint order start openstack-keystone-clone then openstack-cinder-api-clone

或者,您可以下载并安装 OCF 资源代理,而不是使用 systemd 代理

# cd /usr/lib/ocf/resource.d/openstack
# wget https://opendev.org/x/openstack-resource-agents/raw/branch/2025.2/ocf/cinder-api
# chmod a+rx *

现在,您可以添加块存储 API 资源的 Pacemaker 配置。使用 crm configure 命令连接到 Pacemaker 集群,并添加以下集群资源

primitive p_cinder-api ocf:openstack:cinder-api \
   params config="/etc/cinder/cinder.conf" \
   os_password="secretsecret" \
   os_username="admin" \
   os_tenant_name="admin" \
   keystone_get_token_url="http://10.0.0.11:5000/v2.0/tokens" \
   op monitor interval="30s" timeout="30s"

此配置创建了 p_cinder-api,一个用于管理块存储 API 服务的资源。

crm configure 命令支持批量输入,将上述行复制并粘贴到您的实时 Pacemaker 配置中,然后根据需要进行更改。例如,您可以从 crm configure 菜单中输入 edit p_ip_cinder-api 并编辑资源以匹配您首选的虚拟 IP 地址。

完成之后,通过从 crm configure 菜单中输入 commit 来提交您的配置更改。然后,Pacemaker 会在您的节点之一上启动块存储 API 服务及其依赖资源。

配置块存储 API 服务

编辑 /etc/cinder/cinder.conf 文件。例如,在基于 RHEL 的系统上

 1[DEFAULT]
 2# This is the name which we should advertise ourselves as and for
 3# A/P installations it should be the same everywhere
 4host = cinder-cluster-1
 5
 6# Listen on the Block Storage VIP
 7osapi_volume_listen = 10.0.0.11
 8
 9auth_strategy = keystone
10control_exchange = cinder
11
12volume_driver = cinder.volume.drivers.nfs.NfsDriver
13nfs_shares_config = /etc/cinder/nfs_exports
14nfs_sparsed_volumes = true
15nfs_mount_options = v3
16
17[database]
18connection = mysql+pymysql://cinder:CINDER_DBPASS@10.0.0.11/cinder
19max_retries = -1
20
21[keystone_authtoken]
22# 10.0.0.11 is the Keystone VIP
23identity_uri = http://10.0.0.11:35357/
24www_authenticate_uri = http://10.0.0.11:5000/
25admin_tenant_name = service
26admin_user = cinder
27admin_password = CINDER_PASS
28
29[oslo_messaging_rabbit]
30# Explicitly list the rabbit hosts as it doesn't play well with HAProxy
31rabbit_hosts = 10.0.0.12,10.0.0.13,10.0.0.14
32# As a consequence, we also need HA queues
33rabbit_ha_queues = True
34heartbeat_timeout_threshold = 60
35heartbeat_rate = 2

CINDER_DBPASS 替换为您为块存储数据库选择的密码。将 CINDER_PASS 替换为您为 Identity 服务中的 cinder 用户选择的密码。

此示例假定您正在使用 NFS 作为物理存储,这在生产环境中几乎永远不会为真。

如果您正在使用块存储服务 OCF 代理,某些设置将为您填写,从而导致更短的配置文件

 1# We have to use MySQL connection to store data:
 2connection = mysql+pymysql://cinder:CINDER_DBPASS@10.0.0.11/cinder
 3# Alternatively, you can switch to pymysql,
 4# a new Python 3 compatible library and use
 5# sql_connection = mysql+pymysql://cinder:CINDER_DBPASS@10.0.0.11/cinder
 6# and be ready when everything moves to Python 3.
 7# Ref: https://wiki.openstack.org/wiki/PyMySQL_evaluation
 8
 9# We bind Block Storage API to the VIP:
10osapi_volume_listen = 10.0.0.11
11
12# We send notifications to High Available RabbitMQ:
13notifier_strategy = rabbit
14rabbit_host = 10.0.0.11

CINDER_DBPASS 替换为您为块存储数据库选择的密码。

配置 OpenStack 服务以使用高可用的块存储 API

您的 OpenStack 服务现在必须将块存储 API 配置指向高可用的虚拟集群 IP 地址,而不是像非 HA 环境那样指向块存储 API 服务器的物理 IP 地址。

使用此 IP 创建块存储 API 端点。

如果您同时使用私有和公共 IP 地址,请创建两个虚拟 IP 并定义您的端点。例如

$ openstack endpoint create --region $KEYSTONE_REGION \
  volumev2 public http://PUBLIC_VIP:8776/v2/%\(project_id\)s
$ openstack endpoint create --region $KEYSTONE_REGION \
  volumev2 admin http://10.0.0.11:8776/v2/%\(project_id\)s
$ openstack endpoint create --region $KEYSTONE_REGION \
  volumev2 internal http://10.0.0.11:8776/v2/%\(project_id\)s

使用 Cinder 卷备份和恢复服务

Cinder 提供备份和恢复卷和快照的功能。卷的首次备份必须处理为完全备份。后续备份可以是自上次完全备份以来的完全备份或增量备份。请参阅 Cinder 块存储管理指南的备份和恢复卷和快照部分