0

Added 3 EC2 instances in in AWS cloud. Installed 3 MongoDB instances in 3 different instances and all are running fine.

I am adding replication for the same DBs.

below are the steps i followed:

  1. sudo service mongod start --sslPEMKeyFile "/etc/ssl/mongodb.pem" --sslMode "requireSSL" --replSet "myReplSet" ( in all 3 mongo instances)

  2. config = {_id : "myReplSet" , members: [{_id: 0, host:"ip-10-0-0-68:27017"},{_id: 1, host:"ip-10-0-0-247:27017"},{_id: 2, host:"ip-10-0-0-148:27017"}]}

  3. rs.initiate(config)

Error as below:

   MongoDB Enterprise > rs.initiate(config)
   {
    "ok" : 0,
    "errmsg" : "This node was not started with the replSet option",
    "code" : 76,
    "codeName" : "NoReplicationEnabled"
  }

EDIT

I added same security groups and Elastic IP for all 3 instances. All 3 are new DBs. Now I am getting error as:

   {
"ok" : 0,
"errmsg" : "'ip-10-0-0-148:27017' has data already, cannot initiate set.",
"code" : 110,
"codeName" : "CannotInitializeNodeWithData"
   }

EDIT-2

Config file for one the servers:

    # 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:
    #  mmapv1:
    #  wiredTiger:

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

    # network interfaces
    net:
    port: 27017
    #  bindIp: 127.0.0.1,13.58.225.174,13.58.180.226  # Listen to local   interface only, comment to listen on all interfaces.


    #security:

    #operationProfiling:

    replication:
      replSetName: rs0
Chowdappa
  • 1,580
  • 1
  • 15
  • 31

2 Answers2

1

The service start command does not accept parameters. So

sudo service mongod start --sslPEMKeyFile "/etc/ssl/mongodb.pem" --sslMode "requireSSL" --replSet "myReplSet"

Is equivalent to

sudo service mongod start

If you want to add those settings to the mongod configuration, you will need to edit /etc/mongod.conf to add them in. Since the names of some options vary between the command line and the configuration file, you should take a look at the Configuration File Options documentation to ensure you use the correct settings.

EDIT

Based on your edits and the error message, it appears the mongod process (ip-10-0-0-148:27017) already has data on it. You cannot add a mongod process that already has data to a replica set. You can, however, initiate the replica set on a mongod process that already has data. You should connect to that mongod process and run the rs.initiate() there. Then you run rs.add() to add the remaining, empty, mongod processes to the replica set.

Note: MongoDB does offer MongoDB Cloud Manager and MongoDB Atlas which can do some or all of this for you. However, they are not free, so its up to you if you want to use them.

Pete Garafano
  • 4,863
  • 1
  • 23
  • 40
1

This way it works fine.

  1. rs.initialize()
  2. rs.add()
  3. rs.add()

i reffed here: https://devops.profitbricks.com/tutorials/configure-mongodb-replica-set/

Chowdappa
  • 1,580
  • 1
  • 15
  • 31