rabbitmq-server fails to start (or loses its data) after the hostname changed
rabbitmq-server.service fails to start after the hostname was changedShort 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.
Fix it fast
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)"2Match what you see, then jump to its fix
- 1
getent prints nothing for the hostname, and the node fails during bootThe new hostname does not resolveFix - 2
The 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
The 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
- 1
What does the error look like?
rabbitmq-server.service fails to start after the hostname was changedqueues, 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-server3Verify
The service is active and the node answers.
systemctl is-active rabbitmq-server
sudo rabbitmq-diagnostics statusConfirmed by rabbitmq.com
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/mnesia2Fix
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-hostname3Verify
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 statusConfirmed by rabbitmq.com
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
hostname2Fix
Restart the node so its name matches the current hostname.
sudo systemctl restart rabbitmq-server3Verify
The CLI reaches the node by default.
sudo rabbitmq-diagnostics statusConfirmed by rabbitmq.com
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 fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix