configure
========= 我是分割线 =========
Configuration
配置方式
RabbitMQ comes with default built-in settings which will most likely be sufficient for running your RabbitMQ server effectively. If it runs fine, then you probably don't need any configuration at all.
RabbitMQ 自身带有默认的、内建配置,能够满足绝大多数使用 RabbitMQ 的场景。若是这样,那么你可能根本不需要进行任何配置。
If you have other constraints, RabbitMQ provides three general ways to customise the server:
如果你需要进行某些方面的约束设置,RabbitMQ 为你提供了三种通用方式来定制服务器设置:
environment variables
环境变量
define ports, file locations and names (taken from the shell, or set in the rabbitmq-env.conf file)
定义 port、文件位置和文件名字(或者在 shell 上进行设置,或者在 rabbitmq-env.conf 文件中设置)
a configuration file
配置文件
defines server component settings for permissions, limits and clusters, and also plugin settings.
用于设置各种服务器组件的约束,如权限、范围限定和集群等,另外还可以对 plugin 进行设置。
runtime parameters and policies
运行时变更参数和策略
defines cluster-wide settings which can change at run time
用于设置对集群范围有效的相关设置,这类设置可以在运行时改变。
Verify Configuration
验证配置是否生效
The active configuration can be verified in the broker log, e.g. the active configuration file:
配置(文件)是否生效可以通过查看 broker 的日志进行确认,例如,出现下面的信息则表明配置文件生效了:
config file(s) : /etc/rabbitmq/rabbitmq.config
will show up in the
log file
.
上述内容会出现在日志文件中。
Customise RabbitMQ Environment
定制 RabbitMQ 环境
Unix (general)
On Unix-based systems (including Linux, MacOSX) you can create/edit rabbitmq-env.conf to define environment variables. Its location is not configurable (unlike rabbitmq.config).
在 Unix-based 系 统(包括 Linux、Ma cOSX)中,你可以创建/编辑 rabbitmq-env.conf 文件来定义环境变量,但该文件的位置不允许改变(这 一点和 rabbitmq.config 文件不同)
Use the standard environment variable names (but drop the RABBITMQ_ prefix) e.g.
使用标准的环境变量名字(但是需要去掉 RABBITMQ_ 前缀),例如
#example rabbitmq-env.conf file entries
#Rename the node
NODENAME=bunny@myhost
#Config file location and new filename bunnies.config
CONFIG_FILE=/etc/rabbitmq/testdir/bunnies
More info on using
rabbitmq-env.conf
。
Windows
If you need to customise names, ports, locations, it is easiest to configure environment variables in the Windows dialogue: Start > Settings > Control Panel > System > Advanced > Environment Variables.
Create or edit the system variable name and value. For environment changes to take effect the service must be re-installed.
RabbitMQ Environment Variables
RabbitMQ 环境变量
RabbitMQ environment variable names have the prefix RABBITMQ_. A typical variable called RABBITMQ_var_name is set as follows:
RabbitMQ 所有环境变量名句具有 RABBITMQ_ 前缀。典型的变量命名 RABBITMQ_var_name 按如下方式规约:
- a shell environment variable called RABBITMQ_var_name is used if this is defined;
若在 shell 中定义了名为 RABBITMQ_var_name 的环境变量则优先使用该变量的值; - otherwise, a variable called var_name is used if this is set in the rabbitmq-env.conf file;
否则,若在 rabbitmq-env.conf 文件中定义了名为 var_name 的变量则使用该变量的值; - otherwise, a system-specified default value is used.
否则,使用系统指定的默认值。
按照上述的方式,变量设置优先级关系为:
shell 中设置的环境变量 > rabbitmq-env.conf 中设置的环境变量 > RabbitMQ 内置的默认值
It is unlikely you will need to set any of these environment variables. If you have non-standard requirements, then RabbitMQ environment variables include, but are not limited to:
大多数情况你不需要对环境变量进行设置,如果你有非标准使用的要求,那么如下的环境变量可供设置(实际上还有更多):
Name | Default | Description |
RABBITMQ_NODE_IP_ADDRESS | the empty string - meaning bind to all network interfaces. 空字符串 -- 表明绑定所有网络接口 | Change this if you only want to bind to one network interface. 如果你只想要绑定唯一一个网络接口则可以使用该配置进行设置。 |
RABBITMQ_NODE_PORT | 5672 | |
RABBITMQ_DIST_PORT | RABBITMQ_NODE_PORT + 20000 | Port to use for clustering. Ignored if your config file sets inet_dist_listen_min or inet_dist_listen_max 用于集群的端口。如果你在配置文件中设置了 inet_dist_listen_min 或 inet_dist_listen_max 则该配置被忽略 |
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. 节点名需要在 erlang-node-and-machine 级别上做到唯一。若想要运行多个 node,请参考集群配置。 |
RABBITMQ_SERVICENAME | Windows Service: RabbitMQ | The name of the installed service. This will appear in services.msc. |
RABBITMQ_CONSOLE_LOG | Windows 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_ARGS | None | Parameters for the erl command used when invoking rabbitmqctl. This should be overridden for debugging purposes only. 用于给 rabbtimqctl 提供定制参数。仅在调试目的下使用。 |
RABBITMQ_SERVER_ERL_ARGS | Unix*: "+K true +A30 +P 1048576 -kernel inet_default_connect_options [{nodelay,true}]" Windows: None | Standard parameters for the erl command used when invoking the RabbitMQ Server. This should be overridden for debugging purposes only. 在通过 erl 命令启动 RabbitMQ 服务器时使用的标准参数。仅在调试目的下使用。 |
RABBITMQ_SERVER_START_ARGS | None | Extra parameters for the erl command used when invoking the RabbitMQ Server. This will not override RABBITMQ_SERVER_ERL_ARGS. 在通过 erl 命令启动 RabbitMQ 服务器时可使用的额外参数。该参数不会覆盖掉 RABBITMQ_SERVER_ERL_ARGS 的内容。 |
In addition, there are several env ironment variables which tell RabbitMQ where to locate its database, log files, plugins, configuration etc.
此外,还有一些环境变量用于告之 RabbitMQ 在何处定位其数据库、日志文件和配置文件等内容。
Other variables upon which RabbitMQ depends are:
其他 RabbitMQ 依赖的变量:
Name | Default | Description |
HOSTNAME | Unix, Linux: `env hostname` MacOSX: `env hostname -s` | The name of the current machine |
COMPUTERNAME | Windows: localhost | The name of the current machine |
ERLANG_SERVICE_MANAGER_PATH | Windows Service: %ERLANG_HOME%\erts-x.x.x\bin | This path is the location of erlsrv.exe, the Erlang service wrapper script. |
Configuration File
配置文件
The rabbitmq.config File
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 .
配置文件 rabbitmq.config 用于针对 RabbitMQ 核心应用、Erlang 服务,以及 RabbitMQ 插件进行配置。该文件是标准的 Erlang 配置文件,在 Erlang 官网上有文件进行描述。
An example configuration file follows:
配置文件示例如下
[
{mnesia, [{dump_log_write_threshold, 1000}]},
{rabbit, [{tcp_listeners, [5673]}]}
].
This example will alter the dump_log_write_threshold for mnesia (increasing from the default of 100), and alter the port RabbitMQ listens on from 5672 to 5673.
该示例将改变 mnesia 的 dump_log_write_threshold 值(从默认值 100 增大到了 1000),同时改变了 RabbitMQ 的监听端口(从默认值 5672 改变成 5673)。
This configuration file is not the same as rabbitmq-env.conf, which can be used to set environment variables on non-windows systems.
该配置文件和 rabbitmq-env.conf 是不同的,因为前者可以用于非 windows 系统上环境变量的设置。
Location of rabbitmq.config and rabbitmq-env.conf
配置文件 rabbitmq.config 和 rabbitmq-env.conf 的位置
The location of these files is distribution-specific. By default, they are not created, but expect to be located in the following places on each platform:
上述文件的位置是和具体的 OS 发行版相关的。默认情况下,这两个文件都不会被创建,而一旦创建,一般会存在与下述位置:
- Generic UNIX - $RABBITMQ_HOME/etc/rabbitmq/
- Debian - /etc/rabbitmq/
- RPM - /etc/rabbitmq/
- Mac OS X (Macports) - ${install_prefix}/etc/rabbitmq/, the Macports prefix is usually /opt/local
- Windows - %APPDATA%\RabbitMQ\
如果 rabbitmq-env.conf 文件不存在,其可以人工自行创建,但只能放于其默认位置。并且该文件在 windows 系统上不能使用。
If rabbitmq.config doesn't exist, it can be created manually. Set the RABBITMQ_CONFIG_FILE environment variable if you change the location. The Erlang runtime automatically appends the .config extension to the value of this variable.
如果 rabbitmq.config 文件不存在,其可以人工自行创建。如果你打算将其放于非默认位置,则需要设置 RABBITMQ_CONFIG_FILE 环境变量的值。Erlang 运行时会自动将 .config 扩展名添加到该变量值的后面。
Restart the server after changes. Windows service users will need to re-install the service after adding or removing a configuration file.
在配置变更后需要重新启动服务器。
Example rabbitmq.config file
rabbitmq.config 文件示例
We ship an example configuration file with the RabbitMQ server, named rabbitmq.config.example. This example file contains an example of most of the configuration items you might want to set (with some very obscure ones omitted) along with documentation for those settings. All configuration items are commented out in the example, so you can uncomment what you need.
我们在 RabbitMQ 服务器发布包中提供了 rabbitmq.config 的示例配置文件,名字为 rabbitmq.config.example 。该示例文件包含了绝大多数你可能会去配置的条目(省略了一些非常晦涩的配置条目),并提供了相应条目的说明文档。该文件中的所有配置条目均以被注释掉的形式的给出,你可以根据自己的需要放开相应条目。
In most distributions we place this example file in the same location as the real file should be placed (see above). However, for the Debian and RPM distributions policy forbids doing so; instead you can find it in /usr/share/doc/rabbitmq-server/ or /usr/share/doc/rabbitmq-server-3.3.1/ respectively.
在大多数发行版中,我们已经将该示例文件放到了 rabbitmq.config 真正应该存在的位置上(后者的位置参考上面)。然后,对 Debian 和 RPM 发行版而言,这么做会被阻止;取而代之,你可以在 /usr/share/doc/rabbitmq-server/ 或 /usr/share/doc/rabbitmq-server-x.x.x/ 位置上找到相应的文件。
Variables Configurable in rabbitmq.config
rabbitmq.config 中可配置的变量
Many users of RabbitMQ never need to change any of these values, and some are fairly obscure. However, for completeness they are all listed here.
大多数 RabbitMQ 的用户从不需要改变任何下面的值,并且有一些配置项是相当晦涩难懂的。然而,为了展示配置的完整性,所有的可配置项均列在了下面。
Key | Documentation |
tcp_listeners | List of ports on which to listen for AMQP connections (without SSL). Can contain integers (meaning "listen on all interfaces") or tuples such as {"127.0.0.1", 5672} to listen on a single interface. Default: [5672] |
ssl_listeners | As above, for SSL connections. Default: [] |
ssl_options | SSL configuration. See the SSL documentation. Default: [] |
vm_memory_high_watermark | Memory threshold at which the flow control is triggered. See the memory-based flow control documentation. Default: 0.4 |
vm_memory_high_watermark_paging_ratio | Fraction 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 |
disk_free_limit | Disk 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. By default free disk space must exceed 50MB. See the memory-based flow control documentation. Default: 50000000 |
log_levels | Controls 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), or 'info' (errors, warnings and informational messages are logged). At present there are three categories defined. Other, currently uncategorised, events are always logged. The categories are:
|
frame_max | Maximum 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_max | Maximum permissible number of channels to negotiate with clients. Setting to 0 means "unlimited". Using more channels increases memory footprint of the broker. Default: 0 |
heartbeat | Value 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: 580 |
default_vhost | Virtual host to create when RabbitMQ creates a new database from scratch. The exchange amq.rabbitmq.log will exist in this virtual host. Default: <<"/">> |
default_user | User name to create when RabbitMQ creates a new database from scratch. Default: <<"guest">> |
default_pass | Password for the default user. Default: <<"guest">> |
default_user_tags | Tags for the default user. Default: [administrator] |
default_permissions | Permissions to assign to the default user when creating it. Default: [<<".*">>, <<".*">>, <<".*">>] |
loopback_users | List 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_nodes | Set 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_properties | List of key-value pairs to announce to clients on connection. Default: [] |
collect_statistics | Statistics collection mode. Primarily relevant for the management plugin. Options are:
Default: none |
collect_statistics_interval | Statistics collection interval in milliseconds. Primarily relevant for the management plugin. Default: 5000 |
auth_mechanisms | SASL authentication mechanisms to offer to clients. Default: ['PLAIN', 'AMQPLAIN'] |
auth_backends | List of authentication / authorisation databases to use. This list can contain names of modules (in which case the same module is used for both authentication and authorisation), or 2-tuples like {ModN, ModZ} in which case ModN is used for authentication and ModZ is used for authorisation. Other databases than rabbit_auth_backend_internal are available through plugins. 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. Default: false |
delegate_count | Number 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_vhosts | Used internally by the tracer. You shouldn't change this. Default: [] |
tcp_listen_options | Default socket options. You probably don't want to change this. Default: [binary, {packet, raw}, {reuseaddr, true}, {backlog, 128}, {nodelay, true}, {exit_on_close, false}] |
hipe_compile | Set to true to precompile parts of RabbitMQ with the High Performance Erlang compiler. This will increase the message rate that the server can handle, while also increasing startup time. You might see 20-50% better performance at the cost of approximately 1 minute 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. This option should be considered experimental. If your Erlang VM segfaults, disable this option again. Default: false |
cluster_partition_handling | How to handle network partitions. One of ignore, pause_minority or autoheal. See the documentation on partitions for more information. Default: ignore |
msg_store_index_module | Implementation module for queue indexing. You probably don't want to change this. Default: rabbit_msg_store_ets_index |
backing_queue_module | Implementation module for queue contents. You probably don't want to change this. Default: rabbit_variable_queue |
msg_store_file_size_limit | Tunable value for the persister. You almost certainly should not change this. Default: 16777216 |
queue_index_max_journal_entries | Tunable value for the persister. You almost certainly should not change this. Default: 65536 |
In addition, many plugins can have sections in the configuration file, with names of the form rabbitmq_plugin. Our maintained plugins are documented in the following locations:
另外,许多插件都在该配置文件中拥有自己的配置段(section),配置段名类似于 rabbitmq_plugin。官方维护的插件的相关信息(包括配置)可以在下面的位置找到:
- rabbitmq_management
- rabbitmq_management_agent
- rabbitmq_mochiweb
- rabbitmq_stomp
- rabbitmq_shovel
- rabbitmq_auth_backend_ldap