rabbitmq-server fails to start after hostname has changed for first time

UbuntuRabbitmqDjango Celery

Ubuntu Problem Overview


I am using django-celery for my django project. Last day I have changed my computer's hostname (I am using Ubuntu 12.04, edited file '/etc/hostname'), and after next restart django-celery was failing with error

Consumer: Connection Error: [Errno 111] Connection refused. Trying again in 4 seconds...

After some research on this error I could find that, changing my host name caused this error from here. My rabbitmq startup log shows

file: /var/log/rabbitmq/startup_log

Activating RabbitMQ plugins ...

********************************************************************************
********************************************************************************

0 plugins activated:

ERROR: epmd error for host "jinesh": nxdomain (non-existing domain)

My startup_err file is empty.

when I run

root@jinesh:/home/jinesh# rabbitmqctl list_users
Listing users ...
Error: unable to connect to node rabbit@jinesh: nodedown

DIAGNOSTICS
===========

nodes in question: [rabbit@jinesh]

hosts, their running nodes and ports:
- unable to connect to epmd on jinesh: nxdomain

current node details:
- node name: rabbitmqctl4956@jinesh
- home dir: /var/lib/rabbitmq
- cookie hash: RGhmB2JR1LbZ57j7xWWTxg==

I hope changing the nodename may fix this issue. But I couldn't found a way to do this. Anyone have idea about how solve this issue?

update

while changing hostname you have to change both /etc/hostname and /etc/hosts files.

I reinstalled rabbitmq and solved this issue, Will answer this question.

Ubuntu Solutions


Solution 1 - Ubuntu

Remove the old installation of RabbitMQ to fix this problem. Here are steps to reinstall RabbitMQ. These commands are run as the root user:

  1. Stop RabbitMQ: rabbitmqctl stop

  2. Change /etc/hosts

  3. Change /etc/hostname

  4. Uninstall old RabbitMQ: dpkg -P rabbitmq-server

  5. Remove RabbitMQ’s database: rm -rf /var/lib/rabbitmq

  6. Find erlang’s process that is running rabbit: ps ax | grep rabbit

  7. Kill the listed process

  8. Reinstall RabbitMQ: apt-get install rabbitmq-server

I wrote about these steps on my blog.

REVISION

I moved my blog to a new website.

Solution 2 - Ubuntu

Thanks to Richard H Fung.

> His steps helped me to solve this issue.

> But I did not have to re-install the rabbitmq.

When I opened my /etc/hosts file I found that IP assigned to my hostname is different than the actual ip(192.168.1.200 [static]).

#/etc/hosts  
127.0.0.1       localhost  
192.168.1.115   HOSTNAME

so I just changed IP address to 192.168.1.200 in my /etc/hosts file and it worked fine.

Solution 3 - Ubuntu

Richard's answer is good, but you might lose some information in the rabbitmq queues. The following is a possible way to preserve the previous setup of rabbitmq with the new host name.

A Short Answer:

If you want to keep the new host name change, then you can create a rabbitmq-env.conf files in /etc/rabbitmq that references the old host name and all should be good. The following is what should be in the rabbitmq-env.conf file:

NODENAME=rabbit@OLDHOSTNAME

After adding the config file, restart the rabbitmq server then you should be good. (e.g. service rabbitmq-server restart (might need a sudo with ubuntu))

For more details you can read from the rabbitmq website: https://www.rabbitmq.com/man/rabbitmq-env.conf.5.man.html

More Details About the Answer:

I had a similar hostname issues using CentOS... The root issue was when rabbit installs, it references the current host name at the time of install. Since this is a rabbitmq thing, the solution should work for other linux flavors. If you want to see the full answer, you can see it at: https://stackoverflow.com/questions/29501234/rabbtimqadmin-could-not-connect-errno-2-name-or-service-not-known/29502570#29502570

Solution 4 - Ubuntu

You could solve this problem by either deleting the erlang mnesia database associated with rabbitmq or reinstalling rabbitmq.

I got hint for first solution from rabbitmq mailing list. Excerpt from answer, The Erlang Mnesia database is host specific (because it is a distributed DB). The simplest way to get you fixed is to clear out the database dir.

The second method is the easiest way (not recommend though). To uninstall do

dpkg -P rabbitmq-server

You can refer this link if you would like to know more about installing/removing debian packages.

Solution 5 - Ubuntu

On Windows, the issue I was facing was due to the McAfee firewall. The exact error was:

> epmd error for host "<HOSTNAME>": address (cannot connect to host/port)

It started working as soon as I disabled the firewall

Solution 6 - Ubuntu

Remove RabbitMQ database: rm -rf /var/lib/rabbitmq/*

This action solves the problem. I believe somewhere in dumps stored a record with correspondence of nodes host names and ips. This fact causes contradiction if some hosts changed unexpectedly.

Solution 7 - Ubuntu

My solution was to check and correct the $HOSTNAME and /etc/hostname. It turned out that my router was a little confused and gave me a wrong hostname domain. After restarting this one, I called export HOSTNAME=the.correct.hostname and my rabbit runs without restarting the server os.

Solution 8 - Ubuntu

In my case I did not have a following entry in /etc/hosts:

127.0.0.1 <hostname>

where <hostname> is the hostname of my machine (as given by the hostname command). After adding that line, RabbitMQ started successfully. I did not have any earlier installations of RabbitMQ.

Solution 9 - Ubuntu

To solve this problem, I changed my /etc/hostname file with the new hostname then restarted the machine. After that, I ran rm -rf /var/lib/rabbitmq/mnesia/*

Then restarted the service : sudo service rabbitmq-server restart

At this point, it worked for me. If it still don't work, modify the file /etc/rabbitmq/rabbitmq-env.conf by adding those informations :

NODENAME=rabbit@YOUR_NEW_HOSTNAME
NODE_IP_ADDRESS=127.0.0.1
NODE_PORT=5672

Then restart the service : sudo service rabbitmq-server restart

Hope it helps.

Solution 10 - Ubuntu

When on Windows (sorry about that - I understand the topic is for Ubuntu) just reinstall the RabbitMQ service:

rabbitmq-service.bat remove
rabbitmq-service.bat install

The script is located at C:\Program Files\RabbitMQ Server\rabbitmq_server-<version>\sbin folder.

Or may be just changing the value of HKEY_LOCAL_MACHINE\SOFTWARE\Ericsson\Erlang\ErlSrv\1.1\RabbitMQ\@SName is enough.

Clues: https://github.com/rabbitmq/rabbitmq-server/issues/620

Solution 11 - Ubuntu

I had the same problem and doing the steps Richard H Fung provided didn't helped me. I also had to uninstall these packages: erlang erlang-epmd rabbitmq-server

zypper remove erlang erlang-epmd rabbitmq-server
rm -rf /var/lib/rabbitmq/*
zypper install erlang erlang-epmd rabbitmq-server
systemctl enable rabbitmq-server.service
systemctl start rabbitmq-server.service

If you have another OS than openSUSE just use your package manager to remove these packages (e.g. apt-get)

Solution 12 - Ubuntu

The only solution which work for me: install erlang & rabbitmq from deb, so:

First remove:

apt-get purge rabbitmq-server
apt-get purge erlang
apt-get autoremove
reboot

After install wget:

sudo apt-get -y install socat logrotate init-system-helpers adduser
sudo apt-get -y install wget

Install erlang:

wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update
sudo apt-get install erlang

Install rabbitmq:

sudo apt-get update
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.17/rabbitmq-server_3.7.17-1_all.deb
sudo dpkg -i rabbitmq-server_3.7.17-1_all.deb
rm rabbitmq-server_3.7.17-1_all.deb

Solution 13 - Ubuntu

Check qpidd daemon, it could be also already hogging the port that rabbitmq needs.

sudo netstat -lnp

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJineshView Question on Stackoverflow
Solution 1 - UbuntuRichard H FungView Answer on Stackoverflow
Solution 2 - UbuntuKishor PawarView Answer on Stackoverflow
Solution 3 - UbuntuJames OravecView Answer on Stackoverflow
Solution 4 - UbuntuJineshView Answer on Stackoverflow
Solution 5 - UbuntuGautamView Answer on Stackoverflow
Solution 6 - UbuntuI159View Answer on Stackoverflow
Solution 7 - UbuntubertView Answer on Stackoverflow
Solution 8 - UbuntuAdam MichalikView Answer on Stackoverflow
Solution 9 - UbuntuSébastien CrettazView Answer on Stackoverflow
Solution 10 - UbuntuVertigoView Answer on Stackoverflow
Solution 11 - UbuntuPeterView Answer on Stackoverflow
Solution 12 - UbuntuZeroProcessView Answer on Stackoverflow
Solution 13 - Ubuntuash zakView Answer on Stackoverflow