RabbitMQ Configuration 部分

来源:互联网 发布:淘宝网能买到处方药吗 编辑:程序博客网 时间:2024/06/11 13:43

概述

RabbitMQ 默认配置就可以保证有效的运行效率,如果运行状态良好的话,是没有自己修改配置的必要的.

RabbitMQ 提供三种个性化配置的方法:

使用环境变量
设置端口,文件位置,文件名(可以在shell中或者配置文件中配置) (配置文件是 rabbitmq-env.conf/rabbitmq-env-conf.bat)
使用配置文件
定义服务的设置信息 如 permissions, limits and clusters, and also plugin settings.
运行时参数和配置
defines cluster-wide settings which can change at run time
绝大多数的配置都使用前两种,下面着重介绍一下.

定义文件位置

不同操作系统的默认文件位置也是不同的。

验证配置 (如何找到文件位置)

当前的配置文件可以在RabbitMQ log 文件中找到. 如果定义了配置文件,日志如下记录:

node           : rabbit@examplehome dir       : /var/lib/rabbitmqconfig file(s) : /etc/rabbitmq/rabbitmq.config
In case log file cannot be found or read by RabbitMQ, log entry will say so:
node           : rabbit@examplehome dir       : /var/lib/rabbitmqconfig file(s) : /var/lib/rabbitmq/hare.config (not found)

自定义 RabbitMQ 环境

一些服务配置可以通过环境变量来配置: node name, RabbitMQ configuration file location, AMQP 0-9-1 and inter-node communication ports, and so on.

Unix (general)

On Unix-based systems (including Linux, MacOSX) you can create/edit rabbitmq-env.conf to define environment variables. Its location is configurable using theRABBITMQ_CONF_ENV_FILE environment variable.

Use the standard environment variable names (but drop the RABBITMQ_ prefix) e.g.

#example rabbitmq-env.conf file entries#Rename the nodeNODENAME=bunny@myhost#Config file location and new filename bunnies.configCONFIG_FILE=/etc/rabbitmq/testdir/bunnies
More info on using rabbitmq-env.conf

Windows

如果你需要定制names, ports, locations, 只简单的修改环境变量就可以: Start > Settings > Control Panel > System > Advanced > Environment Variables. 创建并编辑系统的环境变量.

另外一个可选的方式, 创建并编辑 rabbitmq-env-conf.bat ,在其中定义环境变量. 这个文件的位置由RABBITMQ_CONF_ENV_FILE系统环境变量来确定.

在window系统下,修改环境之后,需要重新安装服务才能生效。

  • 开启一个命令行窗口
  • cd ..\RabbitMQ Server\rabbitmq_server-3.6.9\sbin
  • Run rabbitmq-service.bat remove
  • 定义系统环境变量
  • RABBITMQ_BASE=c:\Data\RabbitMQ
  • Run rabbitmq-service.bat install

RabbitMQ 环境比那里

RabbitMQ environment variable names have the prefix RABBITMQ_. A typical variable called RABBITMQ_var_name is set as follows:

  • a shell environment variable called RABBITMQ_var_name is used if this is defined;
  • otherwise, a variable called var_name is used if this is set in the rabbitmq-env.conffile;
  • otherwise, a system-specified default value is used.

In this way, variables set in the shell environment take priority over variables set in rabbitmq-env.conf, which in turn over-ride RabbitMQ built-in defaults.

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:

NameDefaultDescriptionRABBITMQ_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_minorkernel.inet_dist_listen_maxkeys. 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 theRABBITMQ_ 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 inservices.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_BASEdirectory.
  • 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 invokingrabbitmqctl. This should be overridden for debugging purposes only.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. Overriding this variablereplaces the default value.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 appendedthe default list of arguments (RABBITMQ_SERVER_ERL_ARGS).RABBITMQ_SERVER_START_ARGSNoneExtra parameters for the erlcommand used when invoking the RabbitMQ Server. This will not overrideRABBITMQ_SERVER_ERL_ARGS.* Unix, Linux, MacOSX

In addition, there are several environment variables which tell RabbitMQ where to locate its database, log files, plugins, configuration etc.

Other variables upon which RabbitMQ depends are:

NameDefaultDescriptionHOSTNAME
  • Unix, Linux: `env hostname`
  • MacOSX: `env hostname -s`
The name of the current machineCOMPUTERNAMEWindows: localhostThe name of the current machineERLANG_SERVICE_MANAGER_PATHWindows Service: %ERLANG_HOME%\erts-x.x.x\binThis path is the location of erlsrv.exe, the Erlang service wrapper script.

Configuration File

The rabbitmq.config File

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.

An minimalistic example configuration file follows:

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

This example will alter the port RabbitMQ listens on for AMQP 0-9-1 client connections from 5672 to 5673.

To override main RabbitMQ config file location, use the RABBITMQ_CONFIG_FILE environment variable.

Note that this configuration file is not the same as the environment configuration file, rabbitmq-env.conf, which can be used to set environment variables on non-Windows systems.

Location of rabbitmq.config and 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:

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

If rabbitmq-env.conf doesn't exist, it can be created manually in the location, specified by the RABBITMQ_CONF_ENV_FILE variable. On Windows systems, it is named rabbitmq-env.bat.

If rabbitmq.config doesn't exist, it can be created manually. Set theRABBITMQ_CONFIG_FILE environment variable if you change the location. The Erlang runtime automatically appends the .config extension to the value of this variable.

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 server source repository contains an example configuration file 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. Note that the example file is meant to be used as, well, example, and should not be treated as a general recommendation.

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.6.9/ respectively.

Variables Configurable in 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.

KeyDocumentationtcp_listenersList 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 one or more interfaces.

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 controldocumentation.

Default: 0.4

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

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 Alarmsdocumentation.

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 referencefor 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.logwill 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 automaticallywhen 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 discor 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.

Default: ['PLAIN', 'AMQPLAIN']

auth_backends

List of authentication / authorisation backends 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.

In the 2-tuple case, ModZ can be replaced by a list,all the elements of which must confirm each authorisation query, e.g. {ModN, [ModZ1, ModZ2]}. This allows authorisation plugins to mix-in and provide additional security constraints.

Other databases than rabbit_auth_backend_internalare available through plugins.

Default: [rabbit_auth_backend_internal]

reverse_dns_lookupsSet 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_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 persister 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

mnesia_table_loading_timeoutTimeout used when waiting 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">>

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

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:

  • rabbitmq_management
  • rabbitmq_management_agent
  • rabbitmq_web_dispatch
  • rabbitmq_stomp
  • rabbitmq_shovel
  • rabbitmq_auth_backend_ldap

Configuration entry encryption

Sensitive configuration entries (e.g. password, URL containing credentials) can be encrypted in the RabbitMQ configuration file. The broker decrypts encrypted entries on start.

Note that encrypted configuration entries don't make the system meaningfully more secure. Nevertheless, they allow deployments of RabbitMQ to conform to regulations in various countries requiring that no sensitive data should appear in plain text in configuration files.

Encrypted values must be inside an Erlang encrypted tuple: {encrypted, ...}. Here is an example of a configuration file with an encrypted password for the default user:

[  {rabbit, [      {default_user, <<"guest">>},      {default_pass,        {encrypted,         <<"cPAymwqmMnbPXXRVqVzpxJdrS8mHEKuo2V+3vt1u/fymexD9oztQ2G/oJ4PAaSb2c5N/hRJ2aqP/X0VAfx8xOQ==">>        }      },      {config_entry_decoder, [             {passphrase, <<"mypassphrase">>}         ]}    ]}].            
Note the config_entry_decoder key with the passphrase that RabbitMQ will use to decrypt encrypted values.

The passphrase doesn't have to be hardcoded in the configuration file, it can be in a separate file:

[  {rabbit, [      ...      {config_entry_decoder, [             {passphrase, {file, "/path/to/passphrase/file"}}         ]}    ]}].            
RabbitMQ can also request an operator to enter the passphrase when it starts by using {passphrase, prompt}.

Use rabbitmqctl and the encode command to encrypt values:

rabbitmqctl encode '<<"guest">>' mypassphrase{encrypted,<<"... long encrypted value...">>}rabbitmqctl encode '"amqp://fred:secret@host1.domain/my_vhost"' mypassphrase{encrypted,<<"... long encrypted value...">>}            
Add the --decode option if you want to decrypt values:
rabbitmqctl encode --decode '{encrypted, <<"...">>}' mypassphrase<<"guest">>rabbitmqctl encode --decode '{encrypted, <<"...">>}' mypassphrase"amqp://fred:secret@host1.domain/my_vhost"            

Values of different types can be encoded. The example above encodes both binaries (<<"guest">>) and strings ("amqp://fred:secret@host1.domain/my_vhost").

The encryption mechanism uses PBKDF2 to produce a derived key from the passphrase. The default hash function is SHA512 and the default number of iterations is 1000. The default cipher is AES 256 CBC.

You can change these defaults in the configuration file:

[  {rabbit, [      ...      {config_entry_decoder, [             {passphrase, "mypassphrase"},             {cipher, blowfish_cfb64},             {hash, sha256},             {iterations, 10000}         ]}    ]}].          
On the command line:
rabbitmqctl encode --cipher blowfish_cfb64 --hash sha256 --iterations 10000 \                     '<<"guest">>' mypassphrase
0 0
原创粉丝点击