RabbitMQ Deployment (Ubuntu)
RabbitMQ Deployment (Ubuntu) - Setup RabbitMQ on Ubuntu with 1 node
Install RabbitMQ Server (Ubuntu 3.12.10)
Install RabbitMQ packages on all servers:
Cloudsmith Quick Start Script.
Run the below script file to install RabbitMQ on Ubuntu.
For more installing details please refer: Installing on Debian and Ubuntu — RabbitMQ
NOTE:
In the above script file, we have used the Distribution as “focal” like below, since our Ubuntu version is 20.04.
deb [signed … /ubuntu focal main
deb-src [signed-by…ubuntu focal main
etc…
Please replace “focal” and use the appropriate Distribution name in your script file from the below table.
jammy
for Ubuntu 23.04jammy
for Ubuntu 22.04focal
for Ubuntu 20.04bionic
for Ubuntu 18.04buster
for Debian Buster, Bullseye, and SidOnce the RabbitMQ server package is installed, start and enable the RabbitMQ service with the following command:
sudo systemctl start rabbitmq-server sudo systemctl enable rabbitmq-server
Lastly, run the following command to verify the
rabbitmq-server
service’s status.sudo systemctl status rabbitmq-server
You can also verify the version of RabbitMQ on your system using the following command.
sudo rabbitmq-diagnostics server_version
Setting up an Admin User for RabbitMQ
The RabbitMQ admin user has permission to configure, read, and write any entity available on the RabbitMQ cluster.
Run the
rabbitmqctl
command below to create a new user with userId and password.sudo rabbitmqctl add_user [user_id] [password]
Run the following command to set (
set_user_tags
) the new user (user_id
) asadministrator
for the RabbitMQ cluster.sudo rabbitmqctl set_user_tags [user_id] administrator
Run the command to
set_permissions
to the new user with the following:Allows (
-p/
)[user_id]
user to access all vhosts on the RabbitMQ cluster.First
".*"
- Allows the user to configure permission for every entity and vhosts.Second
".*"
- Enables write-permission for the user to every entity and vhosts.Third
".*"
- Enables read-permission for the user to every entity and vhosts.sudo rabbitmqctl set_permissions -p / [user_id] ".*" ".*" ".*"
To delete the user, use the below command:
sudo rabbitmqctl delete_user [user_id]
Run the below command to list all available users
(list-users)
on the RabbitMQ cluster.sudo rabbitmqctl list_users
c
Note
Once RabbitMQ UI is up you can log in by using the above username and password.
Enabling the RabbitMQ Management Plugin
The RabbitMQ Management Plugin provides a web-based management UI running on default port 15672
and the command-line management tool [rabbitmqadmin]
.
Run the rabbitmq-plugins
command below on all servers to enable the rabbitmq_management
plugin. This command automatically enables other necessary plugins, such as rabbitmq_management_agent
and rabbitmq_web_dispatch
.
sudo rabbitmq-plugins enable rabbitmq management #For restart sudo systemctl restart rabbitmq-server
At this point, the RabbitMQ management plugin is enabled and listens on port 15672. You can check it with the following command:
ss -antpl | grep 15672
RabbitMQ - Cluster Deployment (Ubuntu)
Setup RabbitMQ Cluster on Ubuntu with 3 nodes
Setup Hostname Resolution
Before setting up the RabbitMQ cluster, you will need to set up hostname resolution on all servers. So, each server can communicate with each other by hostname.
To do so, edit the /etc/hosts file on all cluster servers:
nano /etc/hosts
Add the following lines with your cluster IP address:
172.x.x.x1 RabbitMQ-Cluster-Node-1 172.x.x.x2 RabbitMQ-Cluster-Node-2 172.x.x.x3 RabbitMQ-Cluster-Node-3
Make sure to provide the same hostname shown in your terminal, in the /etc/hosts
file.
Now run the ping
command command below to verify each hostname resolves to the correct IP address of the server. Each -c 3
option makes ping
requests three times, then terminates the requests.
ping -c 3 RabbitMQ-Cluster-Node-1 ping -c 3 RabbitMQ-Cluster-Node-2 ping -c 3 RabbitMQ-Cluster-Node-3
Install RabbitMQ Server (Ubuntu 3.12.10)
Install RabbitMQ packages on all servers:
Cloudsmith Quick Start Script.
Run the below script file to install RabbitMQ on Ubuntu.
For more installing details please refer: Installing on Debian and Ubuntu — RabbitMQ
NOTE:
In the above script file, we have used the Distribution as “focal” like below, since our Ubuntu version is 20.04.
deb [signed … /ubuntu focal main
deb-src [signed-by…ubuntu focal main
etc...
Please replace “focal” and use the appropriate distribution name in your script file from the below table.
jammy
for Ubuntu 23.04jammy
for Ubuntu 22.04focal
for Ubuntu 20.04bionic
for Ubuntu 18.04buster
for Debian Buster, Bullseye, and SidOnce the RabbitMQ server package is installed, start and enable the RabbitMQ service with the following command:
sudo systemctl start rabbitmq-server sudo systemctl enable rabbitmq-server
Lastly, run the following command to verify the
rabbitmq-server
service’s status.sudo systemctl status rabbitmq-server
You can also verify the version of RabbitMQ on your system using the following command.
sudo rabbitmq-diagnostics server_version
Configure RabbitMQ Cluster
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 you’ll set up a .erlang.cookie file in each server with the same content and must be owned by the rabbitmq
user and group.
On server 1, execute the following command to check available files on the RabbitMQ data directory (
/var/lib/rabbitmq
). The command then prints the content of the.erlang.cookie
file.Copy the output (KZLPEPHVOZNLSARUVIOO) to your note because you’ll add this output to the s in server 2 and server 3 in the following steps. Mind you that you may get a different output of the
.erlang.cookie
file than what’s shown below.Next, move to server 2 and server 3, and run the following command to
stop
therabbitmq
service.sudo systemctl stop rabbitmq-server
Edit the
/var/lib/rabbitmq/.erlang.cookie
file n your preferred text editor. Replace the original content with the one you noted in step one, save the changes and exit the editor.# content of .erlang.cookie from server 1 KZLPEPHVOZNLSARUVIOO
Now, run the below command to start the
rabbitmqserver
service.sudo systemctl start rabbitmq-server
Run the following:
rabbitmqctl
commands on server 2 and server 3 to add them to the RabbitMQ cluster (server 1).# Stop RabbitMQ application sudo rabbitmqctl stop_app # Reset RabbitMQ application sudo rabbitmqctl reset # Join the RabbitMQ server 1 sudo rabbitmqctl join_cluster rabbit@RabbitMQ-Cluster-Node-1 # 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.sudo rabbitmqctl cluster_status
Setting up an Admin User for RabbitMQ
The RabbitMQ admin user has permission to configure, read, and write any entity available on the RabbitMQ cluster.
Switch to server 1 and run the
rabbitmqctl
command below to create a new user with userId and password.sudo rabbitmqctl add_user [user_id] [password]
Run the following command to set (
set_user_tags
) the new user (user_id
) asadministrator
for the RabbitMQ cluster.sudo rabbitmqctl set_user_tags [user_id] administrator
Run the command to
set_permissions
to the new user with the following:Allows (
-p/
)[user_id]
user to access all vhosts on the RabbitMQ cluster.First
".*"
- Allows the user to configure permission for every entity and vhosts.Second
".*"
- Enables write-permission for the user to every entity and vhosts.Third
".*"
- Enables read-permission for the user to every entity and vhosts.sudo rabbitmqctl set_permissions -p / [user_id] ".*" ".*" ".*"
To delete the user use below command:
sudo rabbitmqctl delete_user [user_id]
Run the below command to list all available users
(list-users)
on the RabbitMQ cluster.sudo rabbitmqctl list_users
Note
Once RabbitMQ UI is up you can log in by using the above username and password.
Enabling the RabbitMQ Management Plugin
The RabbitMQ Management Plugin provides a web-based management UI running on default port 15672
and the command-line management tool [rabbitmqadmin]
.
Run the rabbitmq-plugins
command below on all servers to enable the rabbitmq_management
plugin. This command automatically enables other necessary plugins, such as rabbitmq_management_agent
and rabbitmq_web_dispatch
.
sudo rabbitmq-plugins enable rabbitmq_management #For restart sudo systemctl restart rabbitmq-server
At this point, the RabbitMQ management plugin is enabled and listens on port 15672. You can check it with the following command:
ss -antpl | grep 15672
Once everything is done, the three RabbitMQ clusters should be up in RabbitMQ UI: