Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2

Hi, when configur replica set, while adding second member get this error: Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2. I have two machines in vmware configured, communication between them is configured. this is 1 node config:

[root@mongo01 ~]# cat /etc/mongod.conf
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,10.10.24.17 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
this is 2 node config:
[root@mongo03 ~]# cat /etc/mongod.conf
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,10.10.24.18  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:
#
##replication:
replication:
  replSetName: "replicaset01"

1 node /etc/host output:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.24.18 mongo03.qarva.info mongo03
10.10.24.17 mongo01.qarva.info mongo01
2 node /etc/host output:
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.24.18 mongo03.qarva.info mongo03
10.10.24.17 mongo01.qarva.info mongo01.

i am trying to add second node by this command:

rs.add("mongo03")
rs.add("mongo03:27017")
rs.add({host: "mongo03.darva.info:27017"})

none above is working , what can i do?

The error message tells you what to do. You got Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2. You cannot have localhost and non-localhost in same replica set.

1 Like

Hi @Nanuka_Zedginidze,

  • Check first service is running on both servers. and accessible from each other node.
  • Second, I didn’t find replication settings on mongo1 node. Could you please check and confirm.
  • Then you need to initialize replication by below command.

rs.initiate( {
_id : “replicaset01”,
members: [
{ _id: 0, host: “mongo01.qarva.info:27017” },
{ _id: 1, host: “mongo03.qarva.info:27017” }
]
})

ROHIT_KHURANA
If you scroll down you can see replication parameter in that config file

I suspect default configuration binding to localhost or some hostname/IP resolution issues

Nanuka_Zedginidze

Can you show rs.conf() output
Did your try with IP?

1 Like

Hi @Ramachandra_Tummala,

Replication parameter is showing for mongo03(10.10.24.18) I didn’t find in first host mongo01 as output is of cat command.

So just want to make sure that @Nanuka_Zedginidze added these settings on both nodes

1 Like

Hi, I have removed 127.0.0.1 and instead i have added just ip’s on both side like that:
1 node: cat/etc/mongod.conf

network interfaces

net:
port: 27017
bindIp: 10.10.24.17 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
cat/etc/hosts output:
##127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.24.17mongo01.qarva.info mongo01
10.10.24.18 mongo02.qarva.info mongo02
and the problem solved. by the way when connecting to mongo, corect is to connect mongo shell with
$mongo 10.10.24.17

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.