Today we want to talk about one of the relational applications, the RabbitMQ message broker, which plays an important role in providing reliable and stable communication. The task of these programs is to store received requests in a queue and provide them one by one to receive services. So, make your services more scalable by decoupling them. Let’s figure out how to install RabbitMQ server on Ubuntu.
Ubuntu is a well-known Linux-based distribution. It is free and open-source and can be widely used on a computer and system or virtual private server (VPS). One of the significant features of Ubuntu is the use of Gnome, which is a graphical user interface. The Ubuntu Canonical maintenance center is a community of developers. It is updated every six months and its support is two years. This operating system contains most of the applications like LibreOffice, Thunderbird, and some other simple games.
If you want to add additional applications, you can install them using the APT package management system or Ubuntu software. This package is the default app store for Ubuntu.
Here are the requirements before you start the installation:
– A Linux VPS with the Ubuntu operating system
– A user account with sudo privileges
– Python 3 with pip package installed
Now you can start the installation steps of RabbitMQ on Ubuntu. The first step is to install the related prerequisites:
apt-get install curl gnupg apt-transport-https -y
The next step is to add a repository that is not available by default, so add signing keys and a related repository:
curl -1sLf "https://keys.openpgp.org/vks/v1/by-fingerprint/0A9AF2115F4687BD29803A206B73A36E6026DFCA" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/com.rabbitmq.team.gpg > /dev/null
curl -1sLf "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xf77f1eda57ebb1cc" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/net.launchpad.ppa.rabbitmq.erlang.gpg > /dev/null
curl -1sLf "https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey" | sudo gpg --dearmor | sudo tee /usr/share/keyrings/io.packagecloud.rabbitmq.gpg > /dev/null
Tip: Make a new file at /etc/apt/sources.list.d/rabbitmq.list directory and add the repositories for ErLang and RabbitMQ that are proper for Ubuntu 22.04 jammy release:
deb [signed-by=/usr/share/keyrings/net.launchpad.ppa.rabbitmq.erlang.gpg] http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu jammy main
deb-src [signed-by=/usr/share/keyrings/net.launchpad.ppa.rabbitmq.erlang.gpg] http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu jammy main
deb [signed-by=/usr/share/keyrings/io.packagecloud.rabbitmq.gpg] https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ jammy main
deb-src [signed-by=/usr/share/keyrings/io.packagecloud.rabbitmq.gpg] https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ jammy main
Now update the package list for the second time after saving the file:
apt-get update -y
Go on installing ErLang packages:
apt-get install -y erlang-base \
As the final part, you can install the RabbitMQ server and other dependencies:
apt-get install rabbitmq-server -y --fix-missing
As you passed all of the levels well, you can see the RabbitMQ server process is working correctly:
systemctl status rabbitmq-server
That’s it. You finished the installation part.
A Management Console plugin has been implemented in RabbitMQ that allows you to perform various management and monitoring tasks through a web-based interface. So if you need to check the list of all RabbitMQ plugins, run the following command:
rabbitmq-plugins list
You will see that all the plugins are disabled. Use the command below to enable them:
rabbitmq-plugins enable rabbitmq_management
Now it is time to setup and manage RbbitMQ on your system.
The first step is connecting to the RabbitMQ web interface. You should open the web browser and type the related URL which is http://your-server-ip:15672:
Install RabbitMQ Server on Ubuntu
The default username and password are guest, but you are allowed to choose any other user. If you forget or don’t know your IP address, type the following command:
hostname -I
The next step is to setup an administrative user. It would be beneficial if you create a new user and assign administrative permissions to it as you want to setup a RabbitMQ server. Choose a unique username and set a reliable password:
Tip: Our preferred administrator username is Thewhiterabbit.
rabbitmqctl add_user thewhiterabbit MyS3cur3Passwor_d
Now use the command below to set a tag for your user:
rabbitmqctl set_user_tags rabbitadmin administrator
It is good to delete the default user because of security reasons:
rabbitmqctl delete_user guest
To check the list of users, you can also this command:
rabbitmqctl list_users
In the next part, you should create RabbitMQ virtual host. A virtual host is suitable for providing logical grouping and separating different resources. These resources include connections, exchanges, user permissions, and other objects. So run the command below to add a new virtual host:
rabbitmqctl add_vhost neuronvm_broker
You can do many configuration settings on a virtual host. These settings can be the maximum number of queues or the maximum number of concurrent client connections. Run the command below to list the available virtual hosts:
rabbitmqctl list_vhosts
It is good to delete the default virtual host:
rabbitmqctl delete_vhost /
To assign user permissions on your virtual host, you should adjust specific user permissions for the administrative user on the virtual host. Use the following command:
sudo rabbitmqctl set_permissions -p <virtual_host> <user_name> <permissions>
Then to have full permissions execute the following command:
sudo rabbitmqctl set_permissions -p cherry_broker thebigrabbit ".*" ".*" ".*"
To see the permissions go through this way:
sudo rabbitmqctl list_permissions -p neuronvm_broker
After all these instructions, it is time to setup RabbitMQ by web management console. To connect to the management console and insert your newly created username and password:
Install RabbitMQ Server on Ubuntu
After the authentication process, you can see the dashboard:
Install RabbitMQ Server on Ubuntu
If you want to add messaging functionality to your system, the best way is to integrate RabbitMQ with other applications in Ubuntu. This allows different programs to communicate with each other in a scalable and flexible way. Note that to make this action possible you need a library that supports AMQP and the most common one is Pika for Python applications. So to install Pika go through this command:
You have to be sure that you have the appropriate package manager:
sudo apt-get install python-pip git-core
Now install Pika:
pip install pika
You should find the appropriate library or client for the other programming languages.
When you decide to install the RabbitMQ server, you may encounter some problems. In this section, we will mention some of them for you:
– Connection Problems:
If you have any trouble connecting to RabbitMQ from clients, you should ensure that the client application uses the correct credentials, port, hostname, and virtual host settings.
By checking the listener configuration in the RabbitMQ configuration file, note that the RabbitMQ server is listening on the correct interface and port.
– Your plugins are not loading:
Use sudo rabbitmq-plugins enable <plugin_name>. to verify that you have enabled the plugins correctly.
If you have problems with plugin loading, Check the RabbitMQ Logs.
Here are the best practices to ensure optimized performance, reliability, and security:
– Regularly back up your RabbitMQ data, including configurations and message data, to facilitate recovery in case of data loss or system failure.
– Configure the firewall to allow only necessary ports to be accessible from external sources. By default, RabbitMQ listens on port 5672 for AMQP and 15672 for the management interface. Restrict access to these ports as needed.
– Always keep your Ubuntu system up to date with the latest security patches and updates. Run sudo apt update followed by sudo apt upgrade to update all packages, including RabbitMQ.
– For high availability and fault tolerance, consider setting up RabbitMQ clustering with multiple nodes. This way, if one node goes down, the others can continue to handle messages.
– Instead of using the Ubuntu default repositories, use the official RabbitMQ repository for the latest stable versions. This ensures you get the most recent updates and features.
– Change default credentials for the RabbitMQ management interface. Create a new administrative user with a strong password and configure RabbitMQ to use it. Remove or disable the default guest user to minimize security risks.
– RabbitMQ can be resource-intensive, especially when handling large amounts of data. Ensure your server has enough CPU, memory, and disk space to handle the expected workload.
– Configure resource and connection limits in RabbitMQ configuration files to prevent resource exhaustion and potential denial-of-service attacks.
– Implement monitoring tools to keep track of RabbitMQ performance and identify potential issues proactively. Enable logging to record important events for troubleshooting purposes
This tutorial presented to introduces RabbitMQ and presents a comprehensive guide about this message broker and the installation process, configuration, and management of RabbitMQ on the Ubuntu operating system. Also, you learned what can be useful practices to optimize the performance of this tool. For any additional information, you can refer to the RabbitMQ official page.
Yes, it is recommended to change the administrator’s name and choose a unique one.
Yes, you can create a new RabbitMQ user and set permissions for that. So open the browser and use the http://localhost:15672/ URL.
How useful was this post?
Click on a star to rate it!
Average rating 0 / 5. Vote count: 0
No votes so far! Be the first to rate this post.
MongoDB is a popular open-source NoSQL database that offers high performance, scalability, and flexi...
PGP is used to encrypt and decrypt data. Methods such as hashing, public key encryption, and data co...
What is your opinion about this Blog?