配置文件的格式¶
OpenStack 使用 INI 文件格式进行配置文件。INI 文件是一个简单的文本文件,它将选项指定为 key=value 对,并分组到不同的部分。 DEFAULT 部分包含大多数配置选项。以井号 (#) 开头的行是注释行。例如
[DEFAULT]
# Print debugging output (set logging level to DEBUG instead
# of default WARNING level). (boolean value)
debug = true
[database]
# The SQLAlchemy connection string used to connect to the
# database (string value)
connection = mysql+pymysql://keystone:KEYSTONE_DBPASS@controller/keystone
选项的值可以有不同的类型。示例配置文件中的注释始终会提及这些类型,表格中会将 Opt 值作为第一项提及,例如 (BoolOpt) Toggle...。OpenStack 使用以下类型
- 布尔值 (
BoolOpt) 启用或禁用一个选项。允许的值为
true和false。# Enable the experimental use of database reconnect on # connection lost (boolean value) use_db_reconnect = false
- 浮点数值 (
FloatOpt) 一个浮点数,例如
0.25或1000。# Sleep time in seconds for polling an ongoing async task # (floating point value) task_poll_interval = 0.5
- 整数值 (
IntOpt) 整数是一个没有小数部分的数字,例如
0或42。# The port which the OpenStack Compute service listens on. # (integer value) compute_port = 8774
- IP 地址 (
IPOpt) 一个 IPv4 或 IPv6 地址。
# Address to bind the server. Useful when selecting a particular network # interface. (ip address value) bind_host = 0.0.0.0
- 键值对 (
DictOpt) 键值对,也称为字典。键值对用逗号分隔,冒号用于分隔键和值。示例:
key1:value1,key2:value2。# Parameter for l2_l3 workflow setup. (dict value) l2_l3_setup_params = data_ip_address:192.168.200.99, \ data_ip_mask:255.255.255.0,data_port:1,gateway:192.168.200.1,ha_port:2
- 列表值 (
ListOpt) 表示其他类型的值,用逗号分隔。例如,以下内容将
allowed_rpc_exception_modules设置为包含四个元素的列表oslo.messaging.exceptions、nova.exception、cinder.exception和exceptions# Modules of exceptions that are permitted to be recreated # upon receiving exception data from an rpc call. (list value) allowed_rpc_exception_modules = oslo.messaging.exceptions,nova.exception
- 多值 (
MultiStrOpt) 多值选项是一个字符串值,可以多次给出,所有值都将被使用。
# Driver or drivers to handle sending notifications. (multi valued) notification_driver = nova.openstack.common.notifier.rpc_notifier notification_driver = ceilometer.compute.nova_notifier
- 端口值 (
PortOpt) TCP/IP 端口号。端口范围从 1 到 65535。
# Port to which the UDP socket is bound. (port value) # Minimum value: 1 # Maximum value: 65535 udp_port = 4952
- 字符串值 (
StrOpt) 字符串可以选择用单引号或双引号括起来。
# The format for an instance that is passed with the log message. # (string value) instance_format = "[instance: %(uuid)s] "
章节¶
配置选项按章节分组。大多数配置文件至少支持以下章节
- [DEFAULT]
包含大多数配置选项。如果配置选项的文档没有指定其章节,则假定它出现在此章节中。
- [database]
配置选项,用于存储 OpenStack 服务状态的数据库。
替换¶
配置文件支持变量替换。在设置配置选项后,可以在后续配置值中引用它,只需在前面加上 $,例如 $OPTION。
以下示例使用 rabbit_host 和 rabbit_port 的值来定义 rabbit_hosts 选项的值,在本例中为 controller:5672。
# The RabbitMQ broker address where a single node is used.
# (string value)
rabbit_host = controller
# The RabbitMQ broker port where a single node is used.
# (integer value)
rabbit_port = 5672
# RabbitMQ HA cluster host:port pairs. (list value)
rabbit_hosts = $rabbit_host:$rabbit_port
为了避免替换,使用 $$ 或 \$ 转义 $。例如,如果您的 LDAP DNS 密码是 $xkj432,请按如下方式指定它
ldap_dns_password = $$xkj432
该代码使用 Python 的 string.Template.safe_substitute() 方法来实现变量替换。有关如何解析变量替换的更多详细信息,请参阅 https://docs.pythonlang.cn/2/library/string.html#template-strings 和 PEP 292。
空白¶
要在配置值中包含空格,请使用带引号的字符串。例如
ldap_dns_password='a password with spaces'
定义配置文件的替代位置¶
大多数服务和 *-manage 命令行客户端都会加载配置文件。要定义配置文件的替代位置,请在启动服务或调用 *-manage 命令时传递 --config-file CONFIG_FILE 参数。