How to install RabbitMQ message broker

Install RabbitMQ message broker to queue and exchange messages.

Default RabbitMQ ports

By default RabbitMQ will use the following TCP ports: 5672 for AMQP protocol, 15672 for management interface and 25672 for clustering.

Prerequisites

Install gnupg2, apt-transport-https and curl.

$ sudo apt install gnupg2 apt-transport-https curl

Installation

Import repository key.

$ curl https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc | sudo apt-key add -

Define RabbitMQ and Erlang repositories.

$ echo "deb https://dl.bintray.com/rabbitmq/debian $(lsb_release -c -s) main"               | sudo tee    /etc/apt/sources.list.d/rabbitmq.list
$ echo "deb https://dl.bintray.com/rabbitmq-erlang/debian $(lsb_release -c -s) erlang-22.x" | sudo tee -a /etc/apt/sources.list.d/rabbitmq.list 
$ cat /etc/apt/sources.list.d/rabbitmq.list 
deb https://dl.bintray.com/rabbitmq/debian buster main
deb https://dl.bintray.com/rabbitmq-erlang/debian buster erlang-22.x

Update package index.

$ sudo apt update

Install RabbitMQ server.

$ sudo apt-get install rabbitmq-server

Open Files Limit

Ensure that Open Files Limit is increased.

$ systemctl cat rabbitmq-server
# /lib/systemd/system/rabbitmq-server.service
[Unit]
Description=RabbitMQ Messaging Server
After=network.target [email protected]
Wants=network.target [email protected]

[Service]
Type=notify
User=rabbitmq
Group=rabbitmq
UMask=0027
NotifyAccess=all
TimeoutStartSec=3600
LimitNOFILE=65536
SyslogIdentifier=rabbitmq
Restart=on-failure
RestartSec=10
WorkingDirectory=/var/lib/rabbitmq
ExecStart=/usr/sbin/rabbitmq-server
ExecStop=/usr/sbin/rabbitmqctl stop

[Install]
WantedBy=multi-user.target

Edit and restart service if you need to increase Open Files Limit.

$ sudo systemctl edit --full rabbitmq-server 
$ sudo systemctl restart rabbitmq-server

Management plugin

Display available plugins.

$ sudo rabbitmq-plugins list
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on [email protected]
 |/
[  ] rabbitmq_amqp1_0                  3.7.8
[  ] rabbitmq_auth_backend_cache       3.7.8
[  ] rabbitmq_auth_backend_http        3.7.8
[  ] rabbitmq_auth_backend_ldap        3.7.8
[  ] rabbitmq_auth_mechanism_ssl       3.7.8
[  ] rabbitmq_consistent_hash_exchange 3.7.8
[  ] rabbitmq_event_exchange           3.7.8
[  ] rabbitmq_federation               3.7.8
[  ] rabbitmq_federation_management    3.7.8
[  ] rabbitmq_jms_topic_exchange       3.7.8
[  ] rabbitmq_management               3.7.8
[  ] rabbitmq_management_agent         3.7.8
[  ] rabbitmq_mqtt                     3.7.8
[  ] rabbitmq_peer_discovery_aws       3.7.8
[  ] rabbitmq_peer_discovery_common    3.7.8
[  ] rabbitmq_peer_discovery_consul    3.7.8
[  ] rabbitmq_peer_discovery_etcd      3.7.8
[  ] rabbitmq_peer_discovery_k8s       3.7.8
[  ] rabbitmq_random_exchange          3.7.8
[  ] rabbitmq_recent_history_exchange  3.7.8
[  ] rabbitmq_sharding                 3.7.8
[  ] rabbitmq_shovel                   3.7.8
[  ] rabbitmq_shovel_management        3.7.8
[  ] rabbitmq_stomp                    3.7.8
[  ] rabbitmq_top                      3.7.8
[  ] rabbitmq_tracing                  3.7.8
[  ] rabbitmq_trust_store              3.7.8
[  ] rabbitmq_web_dispatch             3.7.8
[  ] rabbitmq_web_mqtt                 3.7.8
[  ] rabbitmq_web_mqtt_examples        3.7.8
[  ] rabbitmq_web_stomp                3.7.8
[  ] rabbitmq_web_stomp_examples       3.7.8

Enable management plugin.

$ sudo rabbitmq-plugins enable rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to [email protected]
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.
$ sudo rabbitmq-plugins -q list --enabled
 Configured: E = explicitly enabled; e = implicitly enabled
 | Status: * = running on [email protected]
 |/
[E*] rabbitmq_management 3.7.8

Management user

Create admin with password.

Alter these settings, do not use default password.
$ sudo rabbitmqctl add_user admin password
Adding user "admin" ...

Set admin as an administrator.

$ sudo rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...

Set permissions for default virtual host.

$ sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

Delete guest user.

$ sudo rabbitmqctl delete_user guest
Deleting user "guest" ..

Status

Check service status.

$ sudo rabbitmqctl status
Status of node [email protected] ...
[{pid,29114},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.7.8"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.7.8"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.7.8"},
      {rabbit,"RabbitMQ","3.7.8"},
      {amqp_client,"RabbitMQ AMQP Client","3.7.8"},
      {rabbit_common,
          "Modules shared by rabbitmq-server and rabbitmq-erlang-client",
          "3.7.8"},
      {inets,"INETS  CXC 138 49","7.0.9"},
      {cowboy,"Small, fast, modern HTTP server.","2.2.2"},
      {ranch_proxy_protocol,"Ranch Proxy Protocol Transport","1.5.0"},
      {ranch,"Socket acceptor pool for TCP protocols.","1.5.0"},
      {ssl,"Erlang/OTP SSL application","9.3.5"},
      {public_key,"Public key infrastructure","1.6.7"},
      {asn1,"The Erlang ASN1 compiler version 5.0.9","5.0.9"},
      {os_mon,"CPO  CXC 138 46","2.5"},
      {xmerl,"XML parser","1.3.21"},
      {recon,"Diagnostic tools for production use","2.3.2"},
      {mnesia,"MNESIA  CXC 138 12","4.16"},
      {jsx,"a streaming, evented json parsing toolkit","2.8.2"},
      {cowlib,"Support library for manipulating Web protocols.","2.1.0"},
      {crypto,"CRYPTO","4.5.1"},
      {lager,"Erlang logging framework","3.6.3"},
      {goldrush,"Erlang event stream processor","0.1.9"},
      {compiler,"ERTS  CXC 138 10","7.4.4"},
      {syntax_tools,"Syntax tools","2.2"},
      {syslog,"An RFC 3164 and RFC 5424 compliant logging framework.","3.4.3"},
      {sasl,"SASL  CXC 138 11","3.4"},
      {stdlib,"ERTS  CXC 138 10","3.9.2"},
      {kernel,"ERTS  CXC 138 10","6.4.1"}]},
 {os,{unix,linux}},
 {erlang_version,
     "Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:64]\n"},
 {memory,
     [{connection_readers,0},
      {connection_writers,0},
      {connection_channels,0},
      {connection_other,2732},
      {queue_procs,0},
      {queue_slave_procs,0},
      {plugins,1455092},
      {other_proc,27694500},
      {metrics,195700},
      {mgmt_db,179272},
      {mnesia,76112},
      {other_ets,2767160},
      {binary,211528},
      {msg_index,29776},
      {code,26855842},
      {atom,1180881},
      {other_system,10929565},
      {allocated_unused,13401552},
      {reserved_unallocated,0},
      {strategy,rss},
      {total,[{erlang,71578160},{rss,79216640},{allocated,84979712}]}]},
 {alarms,[]},
 {listeners,[{clustering,25672,"::"},{amqp,5672,"::"},{http,15672,"::"}]},
 {vm_memory_calculation_strategy,rss},
 {vm_memory_high_watermark,0.4},
 {vm_memory_limit,149830041},
 {disk_free_limit,50000000},
 {disk_free,7488921600},
 {file_descriptors,
     [{total_limit,65431},
      {total_used,2},
      {sockets_limit,58885},
      {sockets_used,0}]},
 {processes,[{limit,1048576},{used,383}]},
 {run_queue,1},
 {uptime,16396},
 {kernel,{net_ticktime,60}}]

References

Installing on Debian and Ubuntu