RabbitMQ配置文件及环境变量

本文详细介绍了RabbitMQ的配置文件,包括新旧格式的rabbitmq.config和新格式的rabbitmq.conf,以及如何通过环境变量RABBITMQ_CONFIG_FILE和RABBITMQ_ADVANCED_CONFIG_FILE进行配置文件位置的覆盖。还提到了advanced.config文件用于处理复杂配置,以及rabbitmq-env.conf用于设置环境变量。最后,讨论了RabbitMQ环境变量的设置规则和配置加密的重要性。
摘要由CSDN通过智能技术生成

http://www.rabbitmq.com/configure.html

MechanismDescription
Configuration File(s)defines server and plugin settings for and so on.
Environment Variablesdefine node name, file and directory locations, runtime flags (taken from the shell, or set in the environment configuration file, rabbitmq-env.conf/rabbitmq-env-conf.bat)
rabbitmqctlWhen internal authentication/authorization backend is used, rabbitmqctl is the tool that manages virtual hosts, users and permissions.
rabbitmq-pluginsrabbitmq-plugins is the tool that manages enabled plugins.
Runtime Parameters and Policiesdefines cluster-wide settings which can change at run time as well as settings that are convenient to configure for groups of queues (exchanges, etc) such as including optional queue arguments.

验证配置:

可以通过rabbitmqctl environment命令输出当前节点上正在运行的rabbitmq、plugins和libraries已应用的有效配置。应当将配置文件的内容和有效配置结合起来分析,从而更有效地解决问题。

新旧配置文件格式:

在RabbitMQ 3.7.0之前,RabbitMQ配置文件名为rabbitmq.config并使用了Erlang术语配置格式。 新版仍然支持该格式以实现向后兼容性。 建议运行3.7.0或更高版本的用户考虑新的sysctl格式。

新版本更易于生成部署自动化工具,

新版本格式

 

旧版本配置文件格式

新格式的配置文件易于用户编辑,也方便自动化生成。与RabbitMQ 3.7.0之前使用的经典配置格式相比,新格式也相对有限。 例如,在配置LDAP支持时,可能需要使用深层嵌套的数据结构来表达所需的配置。 为了满足这种需求,RabbitMQ仍然支持经典的rabbitmq.config配置文件以及同时使用这两种格式的能力(advanced.config)。新版配置文件语法可简要概括为:

  • 单个设置的所有信息都位于同一行
  • 每行的结构为key = value
  • 以#开头的行为注释

一个简单的配置文件示例如下:

listeners.tcp.default = 5673

该配置等同于传统配置文件中的

[
  {rabbit, [
      {tcp_listeners, [5673]}
    ]
  }
].

注意不要将此配置文件和环境变量配置文件rabbitmq-env.conf混淆。要覆盖主RabbitMQ配置文件位置,请使用RABBITMQ_CONFIG_FILE环境变量。 使用.conf作为新样式配置格式的文件扩展名。 

 advanced.config文件

新版中某些配置设置不可用或难以使用sysctl格式进行配置。 因此,可以使用Erlang术语格式的其他配置文件(与rabbitmq.config相同)。 该文件通常名为advanced.config。 它将与rabbitmq.conf中提供的配置合并。

RabbitMQ服务器源存储库包含名为advanced.config.example的advanced.config示例文件。 它侧重于通常使用高级配置设置的选项。要覆盖高级配置文件位置,请使用RABBITMQ_ADVANCED_CONFIG_FILE环境变量。

rabbitmq.config文件(传统格式)

RabbitMQ 3.7.0及更高版本仍支持经典配置文件格式,称为rabbitmq.config。 要使用它,请导出RABBITMQ_CONFIG_FILE以指向扩展名为.config的文件,以指示RabbitMQ应将其视为经典配置格式。

要覆盖RabbitMQ配置文件位置,请使用RABBITMQ_CONFIG_FILE环境变量。 使用.config作为经典配置格式的文件扩展名。

rabbitmq.conf和rabbitmq-env.conf文件位置

默认情况下,它们没有被创建。如果需要创建这些文件,请在以下指定位置创建:

  • Generic UNIX - $RABBITMQ_HOME/etc/rabbitmq/
  • Debian - /etc/rabbitmq/
  • RPM - /etc/rabbitmq/
  • Mac OSX (Homebrew) - ${install_prefix}/etc/rabbitmq/, the Homebrew prefix is usually /usr/local
  • Windows - %APPDATA%\RabbitMQ\

如果rabbitmq-env.conf不存在,则可以在由RABBITMQ_CONF_ENV_FILE变量指定的位置手动创建。 在Windows系统上,它名为rabbitmq-env.bat。

如果rabbitmq.conf不存在,可以手动创建。 如果更改位置,请设置RABBITMQ_CONFIG_FILE环境变量。 RabbitMQ自动将.conf扩展名附加到此变量的值。

更改后重新启动服务器。 添加或删除配置文件后,Windows服务用户需要重新安装该服务。

rabbitmq.conf示例文件

示例文件包括

rabbitmq.conf.example

advanced.config.example

这些文件包含您可能希望设置的大多数配置项的示例(省略了一些非常模糊的配置项),以及这些设置的文档。在这个示例中,所有配置项都被注释掉了,因此您可以取消对所需内容的注释。请注意,示例文件是作为示例使用的,不应将其视为一般建议。

 在大多数发行版中,我们将这个示例文件放置在与实际文件应该放置的位置相同的位置(参见上面)。但是,对于Debian和RPM发行版,策略禁止这样做;相反,您可以分别在/usr/share/doc/rabbitmq-server/或/usr/share/doc/rabbitmq-server-3.7.10/中找到它。

以下内容适用于3.6.X版本

Rabbitmq环境变量

RabbitMQ环境变量名的前缀是RABBITMQ_。一个典型的变量RABBITMQ_var_name的设置如下:

  • 如果定义了shell环境变量RABBITMQ_var_name,则RabbitMQ会使用该环境变量;(优先级最高)
  • 否则,如果在rabbitmq-env.conf中设置了一个名为var_name的变量,则该变量会生效;(优先级次之)
  • 否则,会使用系统的默认配置。(优先级最低)

您不太可能需要设置这些环境变量中的任何一个。如果您有非标准需求,那么RabbitMQ环境变量包括但不限于:

NameDefaultDescription
RABBITMQ_NODE_IP_ADDRESSthe empty string - meaning bind to all network interfaces.Change this if you only want to bind to one network interface. To bind to two or more interfaces, use the tcp_listeners key in rabbitmq.config.
RABBITMQ_NODE_PORT5672 
RABBITMQ_DIST_PORTRABBITMQ_NODE_PORT + 20000Port used for inter-node and CLI tool communition. Ignored if your config file sets kernel.inet_dist_listen_min or kernel.inet_dist_listen_max keys. See Networking for details.
RABBITMQ_NODENAME
  • Unix*: rabbit@$HOSTNAME
  • Windows: rabbit@%COMPUTERNAME%
The node name should be unique per erlang-node-and-machine combination. To run multiple nodes, see the clustering guide.
RABBITMQ_CONF_ENV_FILE
  • Generic UNIX - $RABBITMQ_HOME/etc/rabbitmq/rabbitmq-env.conf
  • Debian - /etc/rabbitmq/rabbitmq-env.conf
  • RPM - /etc/rabbitmq/rabbitmq-env.conf
  • Mac OS X (Homebrew) - ${install_prefix}/etc/rabbitmq/rabbitmq-env.conf, the Homebrew prefix is usually /usr/local
  • Windows - %APPDATA%\RabbitMQ\rabbitmq-env-conf.bat
Location of the file that contains environment variable definitions (without the RABBITMQ_ prefix). Note that the file name on Windows is different from other operating systems.
RABBITMQ_USE_LONGNAME When set to true this will cause RabbitMQ to use fully qualified names to identify nodes. This may prove useful on EC2. Note that it is not possible to switch between using short and long names without resetting the node.
RABBITMQ_SERVICENAMEWindows Service: RabbitMQThe name of the installed service. This will appear in services.msc.
RABBITMQ_CONSOLE_LOGWindows Service:Set this variable to new or reuse to redirect console output from the server to a file named %RABBITMQ_SERVICENAME%.debug in the default RABBITMQ_BASE directory.
  • If not set, console output from the server will be discarded (default).
  • new A new file will be created each time the service starts.
  • reuse The file will be overwritten each time the service starts.
RABBITMQ_CTL_ERL_ARGSNoneParameters for the erl command used when invoking rabbitmqctl. This should be overridden for debugging purposes only.调用rabbitmqctl时使用的erl命令的参数。只有在调试时才应该覆盖它。
RABBITMQ_SERVER_ERL_ARGS
  • Unix*: +P 1048576 +t 5000000 +stbt db +zdbbl 32000
  • Windows: None
Standard parameters for the erl command used when invoking the RabbitMQ Server. This should be overridden for debugging purposes only. Overriding this variable replaces the default value.调用RabbitMQ服务器时使用的erl命令的标准参数。只有在调试时才应该覆盖它。覆盖此变量将替换默认值。https://blog.csdn.net/u011973222/article/details/86620490
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS
  • Unix*: None
  • Windows: None

Additional parameters for the erl command used when invoking the RabbitMQ Server. The value of this variable is appended the default list of arguments (RABBITMQ_SERVER_ERL_ARGS). This is the environment variable to use if +K true needs to be overwritten.

调用RabbitMQ服务器时使用的erl命令的其他参数。这个变量的值附加了默认参数列表(RABBITMQ_SERVER_ERL_ARGS)。如果+K true需要重写,则使用此环境变量。

RABBITMQ_SERVER_START_ARGSNone

Extra parameters for the erl command used when invoking the RabbitMQ Server. This will not override RABBITMQ_SERVER_ERL_ARGS.

调用RabbitMQ服务器时使用的erl命令的额外参数。这不会覆盖RABBITMQ_SERVER_ERL_ARGS。

* Unix, Linux, MacOSX

此外,还有几个环境变量告诉RabbitMQ在何处定位其数据库、日志文件、插件、配置等。File and Directory Locations

RabbitMQ依赖的其他变量有:

NameDefaultDescription
HOSTNAME
  • Unix, Linux: env hostname
  • MacOSX: env hostname -s
The name of the current machine
COMPUTERNAMEWindows: localhostThe name of the current machine
ERLANG_SERVICE_MANAGER_PATHWindows Service: %ERLANG_HOME%\erts-x.x.x\binThis path is the location of erlsrv.exe, the Erlang service wrapper script.

rabbitmq.config文件

The configuration file rabbitmq.config allows the RabbitMQ core application, Erlang services and RabbitMQ plugins to be configured. It is a standard Erlang configuration file, documented on the Erlang Config Man Page.

KeyDocumentation
tcp_listenersPorts or hostname/pair on which to listen for AMQP connections (without TLS). See the Networking guide for more details and examples.

Default: [5672]

num_tcp_acceptorsNumber of Erlang processes that will accept connections for the TCP listeners.

Default: 10

handshake_timeoutMaximum time for AMQP 0-8/0-9/0-9-1 handshake (after socket connection and SSL handshake), in milliseconds.

Default: 10000

ssl_listenersAs above, for SSL connections.

Default: []

num_ssl_acceptorsNumber of Erlang processes that will accept connections for the SSL listeners.

Default: 1

ssl_optionsSSL configuration. See the SSL documentation.

Default: []

ssl_handshake_timeoutSSL handshake timeout, in milliseconds.

Default: 5000

vm_memory_high_watermarkMemory threshold at which the flow control is triggered. See the memory-based flow control documentation.

Default: 0.4

vm_memory_calculation_strategyStrategy for memory usage reporting. Can be one of the following:
  • allocated: uses Erlang memory allocator statistics
  • rss: uses operating system RSS memory reporting. This uses OS-specific means and may start short lived child processes.
  • legacy: uses legacy memory reporting (how much memory is considered to be used by the runtime). This strategy is fairly inaccurate.
  • erlang: same as legacy, preserved for backwards compatibility

Default: allocated

vm_memory_high_watermark_paging_ratioFraction of the high watermark limit at which queues start to page messages out to disc to free up memory. See the memory-based flow control documentation.

Default: 0.5

total_memory_available_override_valueMakes it possible to override the total amount of memory available, as opposed to inferring it from the environment using OS-specific means. This should only be used when actual maximum amount of RAM available to the node doesn't match the value that will be inferred by the node, e.g. due to containerization or similar constraints the node cannot be aware of. The value may be set to an integer number of bytes or, alternatively, in information units (e.g "8GB"). For example, when the value is set to 4 GB, the node will believe it is running on a machine with 4 GB of RAM.

Default: undefined (not used)

使重写可用内存总量成为可能,而不是使用特定于os的方法从环境中推断可用内存总量。只有当节点可用RAM的实际最大数量与节点推断出的值不匹配时,才应该使用这种方法,例如,由于容器化或节点不知道的类似约束。该值可以设置为整数字节数,也可以设置为信息单元(e.g "8GB")。例如,当该值设置为4GB时,节点将认为它运行在一台具有4GB RAM的机器上。

disk_free_limitDisk free space limit of the partition on which RabbitMQ is storing data. When available disk space falls below this limit, flow control is triggered. The value may be set relative to the total amount of RAM (e.g. {mem_relative, 1.0}). The value may also be set to an integer number of bytes. Or, alternatively, in information units (e.g "50MB"). By default free disk space must exceed 50MB. See the Disk Alarms documentation.

Default: 50000000

log_levelsControls the granularity(粒度) of logging. The value is a list of log event category and log level pairs.

The level can be one of 'none' (no events are logged), 'error' (only errors are logged), 'warning' (only errors and warning are logged), 'info' (errors, warnings and informational messages are logged), or 'debug' (errors, warnings, informational messages and debugging messages are logged).

At present there are four categories defined. Other, currently uncategorised, events are always logged.

The categories are:

  • channel - for all events relating to AMQP channels
  • connection - for all events relating to network connections
  • federation - for all events relating to federation
  • mirroring - for all events relating to mirrored queues

Default: [{connection, info}]

frame_maxMaximum permissible size of a frame (in bytes) to negotiate with clients. Setting to 0 means "unlimited" but will trigger a bug in some QPid clients. Setting a larger value may improve throughput; setting a smaller value may improve latency.

Default: 131072

channel_maxMaximum permissible number of channels to negotiate with clients. Setting to 0 means "unlimited". Using more channels increases memory footprint of the broker.

Default: 0

channel_operation_timeoutChannel operation timeout in milliseconds (used internally, not directly exposed to clients due to messaging protocol differences and limitations).

Default: 15000

heartbeatValue representing the heartbeat delay, in seconds, that the server sends in the connection.tune frame. If set to 0, heartbeats are disabled. Clients might not follow the server suggestion, see the AMQP reference for more details. Disabling heartbeats might improve performance in situations with a great number of connections, but might lead to connections dropping in the presence of network devices that close inactive connections.

Default: 60 (580 prior to release 3.5.5)

default_vhostVirtual host to create when RabbitMQ creates a new database from scratch. The exchange amq.rabbitmq.log will exist in this virtual host.

Default: <<"/">>

default_userUser name to create when RabbitMQ creates a new database from scratch.

Default: <<"guest">>

default_passPassword for the default user.

Default: <<"guest">>

default_user_tagsTags for the default user.

Default: [administrator]

default_permissionsPermissions to assign to the default user when creating it.

Default: [<<".*">>, <<".*">>, <<".*">>]

loopback_usersList of users which are only permitted to connect to the broker via a loopback interface (i.e. localhost).

If you wish to allow the default guest user to connect remotely, you need to change this to [].

Default: [<<"guest">>]

cluster_nodesSet this to cause clustering to happen automatically when a node starts for the very first time. The first element of the tuple is the nodes that the node will try to cluster to. The second element is either disc or ram and determines the node type.

Default: {[], disc}

server_propertiesList of key-value pairs to announce to clients on connection.

Default: []

collect_statisticsStatistics collection mode. Primarily relevant for the management plugin. Options are:
  • none (do not emit statistics events)
  • coarse (emit per-queue / per-channel / per-connection statistics)
  • fine (also emit per-message statistics)
You probably don't want to change this yourself.

Default: none

collect_statistics_intervalStatistics collection interval in milliseconds. Primarily relevant for the management plugin.

Default: 5000

management_db_cache_multiplierAffects the amount of time the management plugin will cache expensive management queries such as queue listings. The cache will multiply the elapsed time of the last query by this value and cache the result for this amount of time.

Default: 5

auth_mechanismsSASL authentication mechanisms to offer to clients.向客户端提供的SASL身份验证机制。

Default: ['PLAIN', 'AMQPLAIN']

auth_backends

List of authentication and authorisation backends to use.要使用的身份验证和授权后端列表。

Other databases than rabbit_auth_backend_internal are available through plugins. rabbit_auth_backend_internal之外的其他数据库可以通过插件获得。

Default: [rabbit_auth_backend_internal]

reverse_dns_lookups

Set to true to have RabbitMQ perform a reverse DNS lookup on client connections, and present that information through rabbitmqctl and the management plugin.

设置为true,使RabbitMQ对客户端连接执行反向DNS查询,并通过rabbitmqctl和管理插件显示该信息。

Default: false

delegate_countNumber of delegate processes to use for intra-cluster communication. On a machine which has a very large number of cores and is also part of a cluster, you may wish to increase this value.

Default: 16

trace_vhostsUsed internally by the tracer. You shouldn't change this.

Default: []

tcp_listen_optionsDefault socket options. You probably don't want to change this.

Default:

[{backlog,       128},
 {nodelay,       true},
 {linger,        {true,0}},
 {exit_on_close, false}]
                

 

hipe_compileSet to true to precompile parts of RabbitMQ with HiPE, a just-in-time compiler for Erlang. This will increase server throughput at the cost of increased startup time.

You might see 20-50% better performance at the cost of a few minutes delay at startup. These figures are highly workload- and hardware-dependent.

HiPE support may not be compiled into your Erlang installation. If it is not, enabling this option will just cause a warning message to be displayed and startup will proceed as normal. For example, Debian / Ubuntu users will need to install the erlang-base-hipe package.

HiPE is not available at all on some platforms, notably including Windows.

HiPE has known issues in Erlang/OTP versions prior to 17.5. Using a recent Erlang/OTP version is highly recommended for HiPE.

Default: false

cluster_partition_handlingHow to handle network partitions. Available modes are:
  • ignore
  • pause_minority
  • {pause_if_all_down, [nodes], ignore | autoheal} where [nodes] is a list of node names
    (ex: ['rabbit@node1', 'rabbit@node2'])
  • autoheal
See the documentation on partitions for more information.

Default: ignore

cluster_keepalive_intervalHow frequently nodes should send keepalive messages to other nodes (in milliseconds). Note that this is not the same thing as net_ticktime; missed keepalive messages will not cause nodes to be considered down.

Default: 10000

queue_index_embed_msgs_belowSize in bytes of message below which messages will be embedded directly in the queue index. You are advised to read the persisteSet to true to precompile parts of RabbitMQ with HiPE, a just-in-time compiler for Erlang. This will increase server throughput at the cost of increased startup time.

You might see 20-50% better performance at the cost of a few minutes delay at startup. These figures are highly workload- and hardware-dependent.

HiPE support may not be compiled into your Erlang installation. If it is not, enabling this option will just cause a warning message to be displayed and startup will proceed as normal. For example, Debian / Ubuntu users will need to install the erlang-base-hipe package.

HiPE is not available at all on some platforms, notably including Windows.

HiPE has known issues in Erlang/OTP versions prior to 17.5. Using a recent Erlang/OTP version is highly recommended for HiPE.

r tuning documentation before changing this.

Default: 4096

msg_store_index_moduleImplementation module for queue indexing. You are advised to read the persister tuning documentation before changing this.

Default: rabbit_msg_store_ets_index

backing_queue_moduleImplementation module for queue contents. You probably don't want to change this.

Default: rabbit_variable_queue

msg_store_file_size_limitTunable value for the persister. You almost certainly should not change this.

Default: 16777216

msg_store_credit_disc_boundThe credits that a queue process is given by the message store.

By default, a queue process is given 4000 message store credits, and then 800 for every 800 messages that it processes.

Messages which need to be paged out due to memory pressure will also use this credit.

The Message Store is the last component in the credit flow chain. message store是credit flow链中最后一部分。 Learn about credit flow.

This value only takes effect when messages are persisted to the message store. If messages are embedded on the queue index, then modifying this setting has no effect because credit_flow is NOT used when writing to the queue index.此值仅在将消息持久化到message store时生效。如果消息嵌入到队列索引中,则修改此设置没有效果,因为写入队列索引时不使用credit_flow。

Default: {4000, 800}

mnesia_table_loading_retry_limitNumber of times to retry while waiting for Mnesia tables in a cluster to become available.

Default: 10

mnesia_table_loading_retry_timeoutTime to wait per retry for Mnesia tables in a cluster to become available.

Default: 30000

queue_index_max_ journal_entriesTunable value for the persister. You almost certainly should not change this.

Default: 65536

queue_master_locatorQueue master location strategy. Available strategies are:
  • <<"min-masters">>
  • <<"client-local">>
  • <<"random">>
See the documentation on queue master location for more information.

Default: <<"client-local">>

mirroring_sync_batch_sizeBatch size of messages to synchronise between queue mirrors See Batch Synchronization

要在队列镜像之间同步的消息的批处理大小,请参见批处理同步

Default: 4096

lazy_queue_explicit_ gc_run_operation_thresholdTunable value only for lazy queues when under memory pressure. This is the threshold at which the garbage collector and other memory reduction activities are triggered. A low value could reduce performance, and a high one can improve performance, but cause higher memory consumption. You almost certainly should not change this.

Default: 1000

queue_explicit_ gc_run_operation_thresholdTunable value only for normal queues when under memory pressure. This is the threshold at which the garbage collector and other memory reduction activities are triggered. A low value could reduce performance, and a high one can improve performance, but cause higher memory consumption. You almost certainly should not change this.

Default: 1000

 此外,许多插件可以在配置文件中使用表单rabbitmq_plugin的名称部分。我们维护的插件记录在以下位置:

配置加密

可以在RabbitMQ配置文件中加密敏感的配置项(例如密码、包含凭证的URL)。Brokers在开始时解密加密的条目。请注意,加密的配置条目并不能使系统更加安全。尽管如此,它们允许RabbitMQ的部署符合各国的规定,即配置文件中不应出现纯文本形式的敏感数据。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值