RabbitMQ cluster setup guide
blog best suited for Ubuntu 22.04. For different linux distributions some commands may vary. Users need to check commands for other linux distribution
Master Setup Steps:-
We are setting up 3 node clusters on Ubuntu 22.04.
Node 1 (master), Node 2 (slave), Node 3 (Slave)
Check for the latest version of RabbitMQ:- on rabbitmq.com
Login into the Node 1 (master) server on which you want to install RabbitMQ and follow the below commands.
First things first, let’s install the prerequisites:-
sudo apt-get install curl gnupg apt-transport-https -y
We are now ready to add repository signing keys for RabbiMQ main, ErLang, and RabbitMQ PackageCloud repositories respectively.
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
Create a new file at /etc/apt/sources.list.d/rabbitmq.list
and add the following repositories for ErLang and RabbitMQ respectively that are suited 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
Save the file and Update the repository:-
sudo apt-get update -y
Continue with installing the required ErLang packages:-
sudo apt-get install -y erlang-base \
erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
erlang-runtime-tools erlang-snmp erlang-ssl \
erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl
Install the RabbitMQ server using the below command:-
sudo apt-get install rabbitmq-server -y --fix-missing
Finally! Check server process is up and running using this command:-
sudo systemctl status rabbitmq-server
Till Here we have successfully installed RabbitMQ on Node 1.
Cluster Setup Steps:-
RabbitMQ is an application written in Erlang and by default, provides a .erlang.cookie file on the RabbitMQ data directory (/var/lib/rabbitmq).
To create a RabbitMQ cluster, we need to set up .erlang.cookie file in each server with the same content which must be owned by the rabbitmq user and group.
Execute the following commands:-
On the Node 1 server, execute the following commands:-
# List files and directories on /var/lib/rabbitmq
ls -lah /var/lib/rabbitmq
# Print content of the file .erlang.cookie
cat /var/lib/rabbitmq/.erlang.cookie
Copy the output because you’ll add this output to the node 2 and node 3 servers.
Install RabbitMQ on node 2 and node 3 just the same as we have done for node 1 in the above steps.
After Installing RabbitMQ in the Node 2 server, execute the following commands:-
sudo systemctl stop rabbitmq-server
Edit the /var/lib/rabbitmq/.erlang.cookie
file in your preferred text editor. Replace the original content with the one you noted in above step, save the changes and exit the editor.
# content of .erlang.cookie from node01
UXPBSDKHLRMGJSOJVEAN
Now, run the below command to start the rabbitmq-server
service.
sudo systemctl start rabbitmq-server
Switch to the Node03 server and repeat the above-highlighted steps to edit the /var/lib/rabbitmq/.erlang.cookie
file.
Run the following rabbitmqctl commands on node02 and node03 servers to add them to the RabbitMQ cluster (node01).
# Stop RabbitMQ application
sudo rabbitmqctl stop_app
# Join the RabbitMQ node01
sudo rabbitmqctl join_cluster rabbit@node01
# Start the RabbitMQ application again
sudo rabbitmqctl start_app
Finally, execute the rabbitmqctl command below to verify the RabbitMQ cluster status. You can run this from any server (node01, node02, or node03).
sudo rabbitmqctl cluster_status
Till Here we have successfully set up RabbitMQ Cluster on Node01, Node02 and Node03.
Setting Up Admin User Steps:-
After setting up the RabbitMQ cluster, you’ll create a new admin user for RabbitMQ and delete the default guest user. The RabbitMQ admin user has permission to configure, read, and write any entity available on the RabbitMQ cluster.
On Node1(Master) execute the following commands:-
# Helps in enabling rabbitmq web portal.
rabbitmq-plugins enable rabbitmq_management
# adding user in the rabbitmqctl.
rabbitmqctl add_user rabbitmq the@big_rabbit
# tagging user for admin role.
rabbitmqctl set_user_tags rabbitmq administrator
# restart rabbitmq server.
systemctl restart rabbitmq-server
# adding vhost in rabbitmq.
rabbitmqctl add_vhost admin_broker
# shows all the list hosts.
rabbitmqctl list_vhosts
# shows all the list users.
sudo rabbitmqctl list_users
# set permission access to user
rabbitmqctl set_permissions -p admin_broker rabbitmq ".*" ".*" ".*"
# to check the version of rabbitmq
sudo rabbitmqctl version
Till Here we have successfully set up Admin User on RabbitMQ Cluster on Node01.
Web portal Access and validating nodes:-
On a web browser use public URL / IP with port 15672 for management portal access:-
Log in with the username and password you created in previous commands.
username :- rabbitmq
password :- the@big_rabbit (note:- just for ref. plz change as per your need)
Here you can see all the 3 nodes attached with Master Node 1 of RabbitMQ.
Conclusion
Hence, RabbitMQ Cluster Setup was completed Successfully. thanks!!
feel free to ask queries related to this topic. I will be happy to help you.
connect with me:- @utkarshsri0701@gmail.com / serv-ar-tistry Studio