skip to Main Content

I’m using Oracle Virtualbox to host 3 VM running CentOS 7.

Vbox network setup is:

primary-db Adapter1: NAT Mode, no forwarding rules in network settings & Adapter2: Bridge Mode, promiscuous mode=Allow all

secondary-db1 Adapter1: NAT Mode, no forwarding rules in network settings & Adapter2: Bridge Mode, promiscuous mode=Allow all

secondary-db2 Adapter1: NAT Mode, no forwarding rules in network settings & Adapter2: Bridge Mode, promiscuous mode=Allow all

  1. I’ve added the 27017 port to the firewall. (I’ve also added 27018 to
    test)
  2. Created /data/db.
  3. I’ve added all the host IPs on each servers’ /etc/hosts file and
    commented the 127.0.0.1 line
  4. I’ve configured all the mongo.conf files like this:
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true

processManagement:
  fork: true  
  pidFilePath: /var/run/mongodb/mongod.pid 
  timeZoneInfo: /usr/share/zoneinfo

net:
  port: 27017
  bindIp: 192.168.1--.---,127.0.0.1

replication:
  replSetName: "replica01"

Problem:

Now when I run the

# mongo -host <secondary-db server/192.168.---.---> -port 27017

In the primary server, I can enter the mongo shell of the secondaries

But when I try to use the

rs.add('secondary-db1')

or

rs.add('secondary-db1:27017') 

I keep getting this:

replica01:PRIMARY> rs.add('secondary-db')
{
        "operationTime" : Timestamp(1581381570, 1),
        "ok" : 0,
        "errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2",
        "code" : 103,
        "codeName" : "NewReplicaSetConfigurationIncompatible",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1581381570, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        }
}
replica01:PRIMARY>

I even tried to comment the bindIP line to test but it gives me the same result. have I over looked something?
Ive used this tutorial as my reference.

2

Answers


  1. just to sanity check:

    each node has a separate/differing port
    each node has a separate/differing dir folder

    it’s not clear from your post…you state only 1 port via the firewall but each node needs its own port, folder – – they’re all separate and in parallel….

    log directly onto 1 node and first do:
    rs.initiate()

    then perform the rs.add for the other 2 nodes

    this will group them into a replica set

    Login or Signup to reply.
  2. if your question is the set up of the nodes – definitely yes – they each must be a separate and different port, and they need to reside in separate dir folders….

    if your question is about firewall/front end: I work more on the data side with queries rather than the front end…but it is a replica set and if the primary goes down your app needs to work to any of the secondary(s) (whichever gets elected Primary is random)….

    Mongo has a free university and course M103 is specifically about spinning up replica sets – you can watch the videos pretty quickly to get up to speed….

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search