Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

rabbitmq-server fails to start (or loses its data) after the hostname changed

Errorrabbitmq-server.service fails to start after the hostname was changed

Short answer

RabbitMQ builds its node name, rabbit@hostname, and its data directory from the machine's hostname. After a rename the node resolves a new name, may not be able to resolve it at all, and starts with an empty database. Make the hostname resolvable, or pin the old node name in rabbitmq-env.conf.

  • Applies to RabbitMQ 3.13 and 4.x, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare the hostname, the name data directory that already exists, and whether the name resolves.

    hostname
    ls /var/lib/rabbitmq/mnesia
    getent hosts "$(hostname)"
  2. 2Match what you see, then jump to its fix

    1. 1getent prints nothing for the hostname, and the node fails during bootThe new hostname does not resolveFix
    2. 2The node starts, but queues, users and virtual hosts are missing, and mnesia contains a folder named after the old hostThe data directory belongs to the old node nameFix
    3. 3The CLI cannot reach the node: it targets rabbit@new-hostname but the running node has the old nameRabbitMQ was not restarted after the hostname changedFix

What does the error look like?

  • rabbitmq-server.service fails to start after the hostname was changed
  • queues, users and virtual hosts are gone after the hostname change

Cause 1 of 3

The new hostname does not resolve

1Check

Nodes resolve their hostname early at startup, so resolution must work. DNS or the local hosts file can provide it.

getent hosts "$(hostname)"

2Fix

Add the new hostname to /etc/hosts so it points at this machine, then restart the service.

# /etc/hosts
127.0.1.1  new-hostname
sudo systemctl restart rabbitmq-server

3Verify

The service is active and the node answers.

systemctl is-active rabbitmq-server
sudo rabbitmq-diagnostics status

Confirmed by rabbitmq.com

Did this fix it?

Cause 2 of 3

The data directory belongs to the old node name

1Check

By default the database directory is named after the node name, under /var/lib/rabbitmq/mnesia on Debian packages. A different hostname means a different directory, so a new empty database is created.

ls /var/lib/rabbitmq/mnesia

2Fix

Pin the old node name in /etc/rabbitmq/rabbitmq-env.conf (the file uses the variable names without the RABBITMQ_ prefix), make that host part resolve here, and restart.

# /etc/rabbitmq/rabbitmq-env.conf
NODENAME=rabbit@old-hostname

# /etc/hosts
127.0.1.1  old-hostname

3Verify

Restart; the node name in the status output is the old one, and the data directory is the old folder.

sudo systemctl restart rabbitmq-server
sudo rabbitmq-diagnostics status

Confirmed by rabbitmq.com

Did this fix it?

Cause 3 of 3

RabbitMQ was not restarted after the hostname changed

1Check

CLI tools assume the target is rabbit@ plus the local hostname. A node started under the old name no longer matches it.

ps aux | grep [b]eam | grep -o 'rabbit@[^ ]*' | head -n 1
hostname

2Fix

Restart the node so its name matches the current hostname.

sudo systemctl restart rabbitmq-server

3Verify

The CLI reaches the node by default.

sudo rabbitmq-diagnostics status

Confirmed by rabbitmq.com

Did this fix it?

How do I stop it coming back?

  • Set a fixed, resolvable hostname before the first RabbitMQ start, and do not change it afterwards.
  • Pin NODENAME in rabbitmq-env.conf on single-node servers that may be renamed.
  • Read the RabbitMQ clustering guide before renaming a node that is part of a cluster.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.