How to Install RabbitMQ on FreeBSD 14.0

Updated on October 18, 2024
 How to Install RabbitMQ on FreeBSD 14.0 header image

Introduction

RabbitMQ is an open-source message broker that allows distributed systems to communicate through message queuing. RabbitMQ uses the Advanced Message Queuing Protocol (AMQP) for reliable, asynchronous message delivery. It supports a variety of messaging patterns, including publish/subscribe, request/reply, and point-to-point communication. In addition, RabbitMQ ensures message persistence, security, and fault tolerance, making it ideal for handling high-throughput workloads in modern applications.

This article explains how to install RabbitMQ on FreeBSD 14.0 and manage queues using the web administration console.

Prerequisites

Before you begin:

Install RabbitMQ on FreeBSD 14.0

RabbitMQ is available in the default FreeBSD 14.0 package repositories. You can also install a specific version using the FreeBSD ports collection or a generic binary build. Follow the steps below to install RabbitMQ using the default FreeBSD pkg package manager on your server.

  1. Update the server's package information index.

    console
    $ sudo pkg update
    
  2. Install RabbitMQ.

    console
    $ sudo pkg install -y rabbitmq
    
  3. Enable the RabbitMQ service to automatically start at system boot.

    console
    $ sudo sysrc rabbitmq_enable=YES
    
  4. Start the RabbitMQ service.

    console
    $ sudo service rabbitmq start
    
  5. View the RabbitMQ service status to ensure it's running.

    console
    $ sudo service rabbitmq status
    

    Output:

    Status of node ......
    Runtime
    
    OS PID: 1283
    OS: FreeBSD
    Uptime (seconds): 7
    Is under maintenance?: false
    
    .....
    
    Listeners
    
    Interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
    Interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
    Interface: 0.0.0.0, port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0

    If you're looking for a different setup, you can also check out how to install rabbitmq in ubuntu to enhance your application’s message handling capabilities!

Configure RabbitMQ

RabbitMQ supports command-line (CLI) operations by default, but the web administration console provides an efficient way to manage application nodes and queues. Follow the steps below to enable the web administration console plugin and create a new administrative user account.

  1. Enable the rabbitmq_management plugin.

    console
    $ sudo rabbitmq-plugins enable rabbitmq_management
    

    Output:

    Enabling plugins on node rabbit@vultr:
    rabbitmq_management
    The following plugins have been configured:
    rabbitmq_management
    rabbitmq_management_agent
    rabbitmq_web_dispatch
    Applying plugin configuration to rabbit@vultr...
    The following plugins have been enabled:
    rabbitmq_management
    rabbitmq_management_agent
    rabbitmq_web_dispatch
    
    set 3 plugins.
    Offline change; changes will take effect at broker restart.
  2. Create a new admin user and replace strong_password with a strong password of your choice.

    console
    $ sudo -u rabbitmq rabbitmqctl add_user admin strong_password
    

    Output:

    Adding user "admin" ...
    Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.    
  3. Grant the admin user administative privileges using the RabbitMQ set_user_tags option.

    console
    $ sudo -u rabbitmq rabbitmqctl set_user_tags admin administrator
    

    Output:

    Setting tags for user "admin" to [administrator] ...
  4. Grant the admin user full permission to execute all RabbitMQ operations.

    console
    $ sudo -u rabbitmq rabbitmqctl set_permissions admin ".*" ".*" ".*"
    

    In the above command, ".*" is a regular expression pattern that effectively grants full permissions for each type of RabbitMQ operation, such as configure, write, and read.

  5. Restart the RabbitMQ service to apply the new user changes.

    console
    $ sudo service rabbitmq restart
    

    Output:

    Stopping rabbitmq.
    Starting rabbitmq.

Secure RabbitMQ

RabbitMQ serves the web admin console on port 15672 by default. Set up a reverse proxy to this RabbitMQ port and secure connections to the RabbitMQ interface with SSL encryption. Follow the steps below to install Nginx as a reverse proxy and configure the firewall using IPFW to allow incoming SSH, HTTP, and HTTPS connections on the server.

  1. Delete the default RabbitMQ guest user.

    console
    $ sudo -u rabbitmq rabbitmqctl delete_user guest
    

    Output:

    Deleting user "guest" ...
  2. Install Nginx.

    console
    $ sudo pkg install -y nginx
    
  3. Enable the Nginx service to start at system boot.

    console
    $ sudo sysrc nginx_enable=yes
    
  4. Create a new conf.d directory to store your Nginx virtual host configurations.

    console
    $ sudo mkdir /usr/local/etc/nginx/conf.d
    
  5. Create a new Nginx virtual host configuration in the directory using a text editor such as vi.

    console
    $ sudo vi /usr/local/etc/nginx/conf.d/app.example.com.conf
    
  6. Add the following contents to the file. Replace app.example.com with your actual domain.

    nginx
    server {
        listen 80;
        listen [::]:80;
    
        server_name app.example.com;
    
        location / {
            proxy_pass http://localhost:15672;
            proxy_set_header Host              $host;
            proxy_set_header Upgrade           $http_upgrade;
            proxy_set_header Connection        "upgrade";
            proxy_set_header X-Real-IP         $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Host  $host;
            proxy_set_header X-Forwarded-Port  $server_port;
        }
    }
    

    Save and close the file.

    The above Nginx configuration creates a new virtual host for the app.example.com domain that listens for connection requests on the HTTP port 80 and forwards all requests to the RabbitMQ port 15672.

  7. Open the Nginx configuration file using a text editor such as vi.

    console
    $ sudo vi /usr/local/etc/nginx/nginx.conf
    
  8. Add the following include directive before the closing } symbol at the end of the file.

    nginx
    include conf.d/*;
    

    Save and close the file.

    The above directive instructs Nginx to find and read additional configuration files in the /usr/local/etc/nginx/conf.d directory you created.

  9. Test the Nginx configurations for errors.

    console
    $ sudo nginx -t
    

    Output:

    nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
  10. Restart Nginx to apply the changes.

    console
    $ sudo service nginx restart
    

    Output:

    Performing sanity check on nginx configuration:
    nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
    Starting nginx.
  11. Install the Certbot Let's Encrypt client tool and the Nginx plugin.

    console
    $ sudo pkg install -y security/py-certbot security/py-certbot-nginx
    
  12. Generate a new SSL certificate for your virtual host's domain, such as app.example.com. Replace app.example.com with your actual domain and hello@example.com with your email address.

    console
    $ sudo certbot --nginx -d app.example.com -m hello@example.com --agree-tos
    
  13. Enable Certbot to automatically renew the SSL certificate before expiry.

    console
    $ echo weekly_certbot_enable="YES" | sudo tee -a /etc/periodic.conf
    
  14. Enable the IPFW firewall service to automatically start at system boot.

    console
    $ sudo sysrc firewall_enable="YES"
    

    Output:

    firewall_enable: NO -> YES
  15. Set IPFW to quiet mode to suppress messages when loading firewall rules.

    console
    $ sudo sysrc firewall_quiet="YES"
    

    Output:

    firewall_quiet: NO -> YES
  16. Change the firewall type to workstation to use stateful rules.

    console
    $ sudo sysrc firewall_type="workstation"
    

    Output:

    firewall_type: UNKNOWN -> workstation
  17. Allow the SSH, HTTP, and HTTPS ports through the firewall.

    console
    $ sudo sysrc firewall_myservices="ssh/tcp http/tcp https/tcp"
    

    Output:

    firewall_myservices:  -> ssh/tcp http/tcp https/tcp
  18. Allow any IP address to access the services in the firewall_myservices variable.

    console
    $ sudo sysrc firewall_allowservices="any"
    
  19. Start the IPFW service to activate the firewall rules.

    console
    $ sudo service ipfw start
    

Access the RabbitMQ Console

Follow the steps below to access the RabbitMQ web administration console to manage nodes and queues on your server.

  1. Access your RabbitMQ domain, such as rabbitmq.example.com using a web browser such as Chrome.

    https://your-domain.com

    Verify that the RabbitMQ web admin console displays and enter the RabbitMQ administrative user credentials you set earlier to log in.

    Web admin login page

  2. View and manage RabbitMQ tasks using the web administration console.

    Web admin console page

Conclusion

You have installed RabbitMQ on FreeBSD 14.0 and enabled secure authentication for all users on the server. RabbitMQ is a message broker that integrates with other applications to process queues. For more information and configuration options, please visit the RabbitMQ documentation.