Installing and Configuring RabbitMQ
1. Installing via Package Manager
Install RabbitMQ using your system's package manager. The following examples show installation via apt (Debian/Ubuntu) and yum (RHEL/CentOS).
Example: Install RabbitMQ on Ubuntu/Debian
# Add RabbitMQ repository
curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/3.12.0/rabbitmq-release-signing-key.asc | gpg --dearmor > /usr/share/keyrings/rabbitmq-archive-keyring.gpg
# Add repository to sources list
echo "deb [signed-by=/usr/share/keyrings/rabbitmq-archive-keyring.gpg] https://packages.rabbitmq.com/3.12.0/ubuntu focal main" > /etc/apt/sources.list.d/rabbitmq.list
# Update package list and install
apt-get update
apt-get install rabbitmq-server
Example: Install RabbitMQ on RHEL/CentOS
# Add RabbitMQ repository
yum install epel-release
yum install https://github.com/rabbitmq/signing-keys/releases/download/3.12.0/rabbitmq-release-signing-key.asc
# Install RabbitMQ
yum install rabbitmq-server
| Step | Description | Notes |
|---|---|---|
| Add GPG Key | gpg --dearmor |
Ensures package integrity and authenticity |
| Repository Setup | sources.list.d/rabbitmq.list |
Configures package manager to fetch from RabbitMQ repo |
| Install Command | apt-get install rabbitmq-server |
Installs the RabbitMQ server and dependencies |
Note: Ensure that the
rabbitmq-server service is started and enabled after installation.
2. Installing via Docker
Example: Run RabbitMQ with Docker
docker run -d --name my-rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
| Option | Values | Notes |
|---|---|---|
| docker run | -d |
Run container in detached mode |
| docker run | --name my-rabbitmq |
Assign a name to the container |
| docker run | -p 5672:5672 |
Map host port 5672 to container port 5672 (AMQP) |
| docker run | -p 15672:15672 |
Map host port 15672 to container port 15672 (Management UI) |
| docker run | rabbitmq:3-management |
Use the official RabbitMQ image with management plugin |
Note: The management plugin is included in the
rabbitmq:3-management image, providing a web-based interface for monitoring and managing RabbitMQ.Warning: Ensure that the ports 5672 and 15672 are not already in use on your host machine.
3. Installing on Windows
| Step | Description | Notes |
|---|---|---|
| 1 | Download the RabbitMQ Windows installer from the official website. | Ensure you download the correct version (64-bit recommended). |
| 2 | Run the installer as an administrator. | Some features require elevated permissions to install correctly. |
| 3 | Accept the default installation path or customize it. | Default is C:\Program Files\RabbitMQ. |
| 4 | Start the RabbitMQ service after installation. | Use sc start RabbitMQ in Command Prompt or PowerShell. |
Note: Make sure to enable the Management Plugin for web-based monitoring.
Warning: Ensure that port 5672 (AMQP) and 15672 (Management) are not blocked by firewall rules.
4. Installing via Kubernetes
Example: Deploying RabbitMQ on Kubernetes
apiVersion: v1
kind: Service
metadata:
name: rabbitmq-service
spec:
selector:
app: rabbitmq
ports:
- protocol: TCP
port: 5672
targetPort: 5672
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rabbitmq-deployment
spec:
replicas: 1
selector:
matchLabels:
app: rabbitmq
template:
metadata:
labels:
app: rabbitmq
spec:
containers:
- name: rabbitmq
image: rabbitmq:3.12-management
ports:
- containerPort: 5672
- containerPort: 15672
env:
- name: RABBITMQ_DEFAULT_USER
value: "admin"
- name: RABBITMQ_DEFAULT_PASS
value: "password"
| Configuration | Description | Default Value | Notes |
|---|---|---|---|
| image | rabbitmq:3.12-management |
Latest stable version | Includes management plugin |
| RABBITMQ_DEFAULT_USER | Username for default user | guest |
Can be overridden |
| RABBITMQ_DEFAULT_PASS | Password for default user | guest |
Must be changed in production |
Note: The default user
guest has full access and should not be used in production environments.
Warning: Ensure persistent storage is configured for RabbitMQ to prevent data loss during pod restarts.
Installation Steps
- Create a Kubernetes Service to expose RabbitMQ
- Deploy RabbitMQ using a Deployment with management plugin
- Set environment variables for default user credentials
- Configure persistent storage for data persistence
5. Starting and Stopping Service
| Command | Description | Notes |
|---|---|---|
| sudo systemctl start rabbitmq-server | Start the RabbitMQ service | Service name may vary based on OS |
| sudo systemctl stop rabbitmq-server | Stop the RabbitMQ service | Gracefully shuts down the broker |
| sudo systemctl restart rabbitmq-server | Restart the RabbitMQ service | Reboots the broker with new config |
| sudo systemctl status rabbitmq-server | Check the status of RabbitMQ service | Shows if service is running or not |
Example: Managing RabbitMQ Service
# Start RabbitMQ
sudo systemctl start rabbitmq-server
# Check status
sudo systemctl status rabbitmq-server
# Stop RabbitMQ
sudo systemctl stop rabbitmq-server
Note: On some systems, the service name might be
rabbitmq instead of rabbitmq-server.6. Verifying Installation
| Command | Description | Expected Output |
|---|---|---|
| systemctl status rabbitmq-server | Check if RabbitMQ service is running | active (running) |
| rabbitmqctl status | Display RabbitMQ node status | Node is running and connected to the cluster |
Note: Ensure the service is active and listening on port 5672.
7. Configuring rabbitmq.conf
Example: Basic RabbitMQ Configuration
% rabbitmq.conf
default_user = guest
default_pass = guest
default_vhost = /
management.tcp.port = 15672
vm_memory_high_watermark = 0.4
disk_free_limit = 50MB
loopback_users.guest = false
| Configuration Option | Description | Default Value | Notes |
|---|---|---|---|
| default_user | User for default access | guest | Used for initial login if no credentials provided |
| default_pass | Password for default user | guest | Must be changed in production environments |
| default_vhost | Default virtual host to connect to | / | Can be changed to isolate environments |
| management.tcp.port | Port for management plugin | 15672 | Used to access web UI for monitoring |
| vm_memory_high_watermark | Memory usage threshold to start disk writes | 0.4 (40%) | Adjust based on available RAM |
| disk_free_limit | Minimum free disk space before stopping writes | 1GB | Set to prevent disk exhaustion |
| loopback_users.guest | Allow guest user access from remote hosts | true | Set to false in production for security |
Note: The
rabbitmq.conf file is located in /etc/rabbitmq/ on most systems. Changes require a service restart to take effect.Warning: Never use default credentials in production. Always change
default_user and default_pass.Configuration Best Practices
- Disable loopback users in production environments
- Set appropriate memory and disk limits to prevent crashes
- Use a dedicated virtual host for each application or environment
- Enable management plugin to monitor queue and connection status
8. Configuring advanced.config
Example: Basic advanced.config structure
{rabbit, [
{default_user, <<"guest">>},
{default_pass, <<"guest">>},
{default_vhost, <<"/">>},
{default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
{management, [
{assets_dir, <<"/path/to/assets">>},
{listener, [
{port, 15672},
{ip, <<"::">>}
]}
]},
{tcp_listeners, [
{port, 5672},
{ip, <<"::">>}
]}
]}.
| Configuration Option | Description | Default Value | Notes |
|---|---|---|---|
| default_user | Username for default user | guest |
Used for initial access and management |
| default_pass | Password for default user | guest |
Should be changed in production |
| default_vhost | Default virtual host to use | / |
Isolation of resources |
| default_permissions | Default permissions for new users | [".*", ".*", ".*"] |
Permissions in format [configure, write, read] |
| management.assets_dir | Directory containing management UI assets | /usr/lib/rabbitmq/lib/rabbitmq_server-3.12.0/priv/www |
Customize for UI customization or local assets |
| management.listener.port | Port for management plugin HTTP listener | 15672 |
Can be changed to avoid port conflicts |
| tcp_listeners.ip | IP address to bind TCP listeners to | :: |
Use 0.0.0.0 for IPv4 or :: for IPv6 |
| tcp_listeners.port | Port for AMQP protocol listener | 5672 |
Standard AMQP port; can be changed for custom setups |
Note: The
advanced.config file is an Erlang term file and must be valid Erlang syntax. It's loaded before the RabbitMQ application starts.
Warning: Changes to
advanced.config require a RabbitMQ node restart to take effect.
Key Points for Configuration
- Use
{rabbit, [...]}to define RabbitMQ-specific settings - Use
{management, [...]}to configure the web-based management interface - Use
{tcp_listeners, [...]}to define AMQP protocol listeners - Ensure proper Erlang syntax in
advanced.config - Restart the RabbitMQ node after making changes to
advanced.config
9. Setting Environment Variables
Example: RabbitMQ Environment Variables
# Set the RabbitMQ data directory
export RABBITMQ_MNESIA_BASE=/var/lib/rabbitmq/mnesia
# Set the log directory
export RABBITMQ_LOGS=/var/log/rabbitmq
# Set the configuration file location
export RABBITMQ_CONFIG_FILE=/etc/rabbitmq/rabbitmq
# Set the node name
export RABBITMQ_NODENAME=rabbit@localhost
# Set the port for the AMQP protocol
export RABBITMQ_PORT=5672
# Set the port for the management plugin
export RABBITMQ_MANAGEMENT_PORT=15672
| Variable | Description | Default Value | Notes |
|---|---|---|---|
| RABBITMQ_MNESIA_BASE | Directory for storing Mnesia database files | /var/lib/rabbitmq/mnesia |
Must be writable by the RabbitMQ user |
| RABBITMQ_LOGS | Directory for log files | /var/log/rabbitmq |
Must be writable by the RabbitMQ user |
| RABBITMQ_CONFIG_FILE | Path to the configuration file | /etc/rabbitmq/rabbitmq |
Can be overridden to point to a custom config file |
| RABBITMQ_NODENAME | Name of the RabbitMQ node | rabbit@hostname |
Must be unique across nodes in a cluster |
| RABBITMQ_PORT | Port for AMQP protocol | 5672 |
Can be changed to avoid conflicts with other services |
| RABBITMQ_MANAGEMENT_PORT | Port for the management plugin | 15672 |
Used for web-based management interface |
Note: Environment variables are loaded before the RabbitMQ configuration files, so they can override any settings in the config files.
10. Setting Node Name
When RabbitMQ runs, it identifies itself with a node name. By default, the node name is derived from the hostname of the machine it's running on.
| Configuration Option | Default Value | Description |
|---|---|---|
| RABBITMQ_NODENAME | rabbit@hostname |
The name of the RabbitMQ node. It must be unique within the cluster. |
Note: The node name must be unique within the RabbitMQ cluster. If two nodes attempt to use the same name, one will fail to start.
11. Configuring Data Directory
| Configuration Option | Default Value | Description |
|---|---|---|
| default_db_dir | /var/lib/rabbitmq/mnesia |
Directory where RabbitMQ stores its database files and message queues |
| mnesia_dir | $default_db_dir |
Alias for the database directory; can be overridden to a custom path |
Example: Setting Custom Data Directory
# Set custom directory in rabbitmq.conf
echo 'mnesia.dir = /opt/rabbitmq/data' >> /etc/rabbitmq/rabbitmq.conf
Note: Ensure the directory exists and RabbitMQ has read/write permissions.
12. Configuring Log Levels
| Log Level | Description | Usage |
|---|---|---|
| debug | Most verbose level, includes all internal operations and messages. | Use for troubleshooting detailed internal behavior. |
| info | General operational messages, including startup and shutdown. | Default level for production systems to monitor operations. |
| warning | Non-critical issues that might need attention. | Monitor for potential problems without system failure. |
| error | Errors that affect functionality or system stability. | Essential for tracking failures and exceptions in the system. |
| fatal | Severe errors that cause system termination. | Used for critical failures requiring immediate attention. |
Example: Setting Log Level via Configuration File
log level: info file: /var/log/rabbitmq/rabbit.log
Note: Log levels can also be adjusted at runtime using the
rabbitmqctl command or via the management plugin.
13. Enabling Management Plugin
The RabbitMQ Management Plugin provides a web-based interface for monitoring and managing your RabbitMQ instance.
| Configuration | Description | Default Value |
|---|---|---|
| management.enabled | Enables or disables the management plugin | true |
| management.port | Port on which the management interface will run | 15672 |
| management.listener.ip | IP address to bind the management listener to | 0.0.0.0 |
Example: Enabling Management Plugin via Configuration File
management:
enabled: true
port: 15672
listener:
ip: 0.0.0.0
Note: After enabling the plugin, you must restart RabbitMQ for changes to take effect.
Warning: The management plugin is intended for development and testing environments. For production, ensure proper access controls are in place.