Install RabbitMQ Server on Ubuntu
RabbitMQ is an open-source message broker software that enables efficient and reliable communication between different components of an application or between multiple applications. It implements the Advanced Message Queuing Protocol (AMQP), a widely adopted standard for messaging middleware.RabbitMQ allows applications to communicate with each other by sending and receiving messages.
Key features of RabbitMQ include:
- Message Queueing: RabbitMQ enables the queuing of messages between different components or systems. This helps in decoupling the producers of messages from the consumers, allowing for better scalability and flexibility.
- Message Routing: It supports different routing mechanisms, including direct, topic, fanout, and headers exchanges. These mechanisms help in directing messages to specific queues based on criteria such as message content or routing keys.
- Reliability: RabbitMQ provides features like message acknowledgments and persistence to ensure reliable message delivery. Messages can be persisted to disk, and acknowledgment mechanisms ensure that messages are not lost even if a consumer fails during processing.
- Scalability: RabbitMQ is designed to be scalable, allowing you to distribute the message broker across multiple nodes to handle a large volume of messages and ensure high availability.
- Protocol Support: RabbitMQ supports multiple messaging protocols, including Advanced Message Queuing Protocol (AMQP), MQTT (Message Queuing Telemetry Transport), and others. This makes it versatile and compatible with various systems.
- Pluggable Architecture: RabbitMQ’s architecture is extensible through the use of plugins. This allows you to add functionalities and features to meet specific requirements.
- Management Interface: RabbitMQ comes with a management plugin that provides a web-based user interface for monitoring and managing the RabbitMQ server. This interface allows you to view queues, exchanges, connections, and other statistics.
Overall, RabbitMQ is widely used in distributed systems, microservices architectures, and applications where different components need to communicate asynchronously. It helps in building scalable and loosely-coupled systems by providing a reliable messaging infrastructure.
Step 1: Install Erlang
sudo add-apt-repository ppa:rabbitmq/rabbitmq-erlang
sudo apt update
sudo apt install erlang
Remove Erlang and the PPA
To uninstall the Erlang version removed from the PPA and move it back to the version provided by the Ubuntu repositories, use PPA Purge.
sudo apt install ppa-purge
sudo ppa-purge ppa:rabbitmq/rabbitmq-erlang
sudo apt remove erlang
Step 2: Add RabbitMQ Repository to Ubuntu
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bash
Step 3: Install RabbitMQ Server Ubuntu
sudo apt update
Then install rabbitmq-server
package:
sudo apt install rabbitmq-server
After installing RabbitMQ, the RabbitMQ service is initiated and configured to launch automatically on system boot. To verify its current status, execute the following command:
systemctl status rabbitmq-server.service
You can confirm if the service is configured to start on boot using the command:
$ systemctl is-enabled rabbitmq-server.service
If it returns disabled, enable it by running:
sudo systemctl enable rabbitmq-server
Step 4: Enable the RabbitMQ Management Dashboard
sudo rabbitmq-plugins enable rabbitmq_management
The Web service should be listening on TCP port 15672
$ sudo ss -tunelp | grep 15672
tcp LISTEN 0 128 0.0.0.0:15672 0.0.0.0:* users:(("beam.smp",pid=9525,fd=71)) uid:111 ino:39934 sk:9 <->
If you have an active UFW firewall, open both ports 5672 and 15672:
sudo ufw allow proto tcp from any to any port 5672,15672
Access it by opening the URL http://[server IP|Hostname]:15672
for example http://localhost:15672
The default configuration includes a user named “guest,” which is set up to connect exclusively from the localhost. You can log in locally using this user, and the password for authentication is set to “guest.”
To be able to login on the network, create an admin user like below:
sudo rabbitmqctl add_user admin password
sudo rabbitmqctl set_user_tags admin administrator
Login with this admin username and the password will be password .
Default Virtualhost is /
Step 5: Set RabbitMQ Cluster
RabbitMQ User Management Commands
Delete User:
rabbitmqctl delete_user test
Change User Password:
rabbitmqctl change_password test password
Create new Virtualhost:
rabbitmqctl add_vhost /testVhost
List available Virtualhosts:
rabbitmqctl list_vhosts
Delete a virtualhost:
rabbitmqctl delete_vhost /testVhost
Grant user permissions for vhost:
rabbitmqctl set_permissions -p /testVhost user ".*" ".*" ".*"
List vhost permissions:
rabbitmqctl list_permissions -p /testVhost
To list user permissions:
rabbitmqctl list_user_permissions test
Delete user permissions:
rabbitmqctl clear_permissions -p /testVhost test