ReplicaSetId conflict while adding node MongoDB - mongodb

When I try to add a new node to my replicate set I get this message:
{
"ok" : 0,
"errmsg" : "Our replica set ID of 5890ad86c92c6c88e8573df0 did not match that of 10.0.253.3:27017, which is 5890a6b137e1380d1e697f2a",
"code" : 103,
"codeName" : "NewReplicaSetConfigurationIncompatible"
}

I had the same error and impossible to find out why ... I come back on the post to send the solution if others pass here.
Simply do not initialize the replicate on both servers:
I have two separate X and Y servers without mongodb, X and Y are IP addresses or domains.
Install mongodb on both servers
Edit the sudo nano /etc/mongod.conf configuration files on both servers
[in file] Replace bindIp: 127.0.0.1 with bindIp: 127.0.0.1,X on the X server
[in file] Replace bindIp: 127.0.0.1 with bindIp: 127.0.0.1,Y on the Y server
[in file] Replace #replication: with replication: on both servers
[in file] Add replSetName: "​​myReplicatName" line under replication: on both servers
Launch mongo with the configuration file on both servers
Only on server X run mongo and type commands
Mongo commands:
rs.initiate ({
_id: "rs0",
members: [{
_id: 1,
host: "X:27017"
}]
});
rs.add("Y:YPORT");

Related

Data not moving to new shard servers mongodb

I have added a shard server to my mongodb cluster. After adding the new shard server, I am getting this error on primary node.
DBException thrown :: caused by ::
CannotImplicitlyCreateCollection{ ns: "config.system.sessions" }:
request doesn't allow collection to be created implicitly
The new shard server is new and did not have any data earlier.
How did I add the shard server?
I create a file /etc/mongod.conf (just like my other shard servers)
sharding:
clusterRole: shardsvr
replication:
replSetName: shardReplicaSet10
storage:
dbPath: /mnt/mongodb
systemLog:
traceAllExceptions: true
path: /mnt/log/mongodb/out.log
logAppend: true
logRotate: rename
destination: file
processManagement:
fork: true
net:
bindIp: localhost,172.6.7.5
Then I have another member in this replicaSet with same config file, just the bindIp is changed.
I connected to my mongos node and add the replicaSet
sh.addShard("shardReplicaSet10/172.6.7.5:27018,172.6.7.6:27018")
I can confirm that I have initiated the replicaset using rs.initiate()
It turns out that whenever we add a new shard replicaSet, We need to give it a identity manually. I tried the steps given in this answer
https://dba.stackexchange.com/a/227877
and It worked. On primary of shard replicaSet, simply do this :
use admin
and add identity
db.system.version.insert({
"_id" : "shardIdentity",
"clusterId" : ObjectId("5f098ac1077eb0e078fd5c1e"),
"shardName" : "NameOfYourShardReplicaSet",
"configsvrConnectionString" : "configReplicaSet/ipofconfigserver:27019,ipofotherconfigserver:27019"
})
you can get cluster Id by using
sh.status()
on any of the mongos cluster.

MongoDB: Always receiving 127.0.0.1 when initializing primary node

No matter how I try to initialize my primary node, it always gets the name "name" : "127.0.0.1:27017", therefore any remote node additions in the replica set, fail with this message:
"errmsg" : "Either all host names in a replica set configuration must
be localhost references, or none must be; found 1 out of 2"
Here is my .conf
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: mongodb.primary, 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
How should I properly initialize my primary so that it does not bind to 127.0.0.1 only?
The mongodb.primary above is resolvable among all machines;
Here is the full error:
rs0:PRIMARY> rs.add('mongodb.secondary1:27017')
{
"operationTime" : Timestamp(1552552019, 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(1552552019, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
The problem is clearly stated: the first replica set member is bound to localhost
To bind to all IPs (Not recommended to use this without authentication it's ok for testing though)
net:
bindIp: 0.0.0.0
See this document here
For you case the chances are that the MongoDB instances at DO are bound to localhost by default. However, you might need to bind them to a different IP address using the net.bindIp configuration option. Please be advised, this wille expose the MongoDB instance being accessible given they connect to the chosen port. Recommended to enable authentication if a MongoDB instance is bound to a different IP than localhost.

MongoDB add replica-set to external server by ip

I have created 3 Digitalocean droplet. By default, I choose Ubuntu 18.06 and MongoDB 4.
Here I have 3 droplets by default MongoDB config and all are up. I have access to "mongo" shell for all of them.
Now I want to run a replica-set setting by this code:
rs.initiate(
{_id : "rs0",
members: [
{ _id: 0, host: "20.30.40.50:27017" },
{ _id: 1, host: "20.30.40.51:27017" },
{ _id: 2, host: "20.30.40.52:27017" }
]
})
In this config, I just told MongoDB that rune the replica set and it retrieves me the error
no replies config has been received
I did not add any bindIp yet also when I added bindIp, I could not start MongoDB again. I put in mongo.conf like this:
bindIp: 127.0.0.1,20.30.40.51,20.30.40.52
Also, There is a private network between these 3 droplets by IP example: 10.10.1.1 Can I take advantage of this private IP to make it easier and safer?

errmsg" : "No host described in new configuration 1 for replica set rs0 maps to this node", Why I am getting this message?

I am getting this message every time I do rs.initiate() :
No host described in new configuration 1 for replica set rs0 maps to this node
This is how my /etc/hosts/ file looks on both the replica set servers.
Server 1 and server 2 "hosts" file
127.0.0.1 localhost
aa.bb.cc.dd DataMongo1
ee.ff.gg.hh DataMongo2
Server 1-mongod.conf file
bind-ip aa.bb.cc.dd
Server 2 -mongod.conf file
bind-ip ee.ff.gg.hh
changed server1 hostname to DataMongo1 and server2 to DataMongo2
$hostname DataMongo1
Port 27071 is uncommented on both servers
ReplicaSet config file:
cfg= {
_id:"rs0",
members:[{_id:0,host:"DataMongo1:27071"},{_id:1,host:"DataMongo2:27071"}]}
Please help me with this issue.
I just ran into this issue, and in my case the symptoms were that everything worked correctly, until I rebooted the server.
Then I would get the following error: NodeNotFound: No host described in new configuration $id for replica set $name maps to this node
Just restarting the mongodb daemon fixed it, so it couldn't be a replica set configuration issue.
After checking the logs a bit more in detail, I noticed the following error message: NETWORK [replexec-0] getaddrinfo("$name.emilburzo.com") failed: Temporary failure in name resolution -> bingo
It was trying to query the hostname before the network was fully up, and thus the replica set member didn't know it's own identity
Adding the server's FQDN hostname to /etc/hosts fixed it, e.g.:
127.0.1.1 shortname shortname.fqdn.com
Looks like the port is wrong. The default port of MongoDB is 27017, not 27071.
if you are using mongo.conf file then initially comment "replication" section like below,
...
#operationProfiling:
# replication:
# replSetName: rs0-here
#sharding:
...
Now run mongod and configure replica set on mongo terminal like below,
rs.initiate({_id: "rs0-here", version: 1, members: [{ _id: 0, host : "your_host:27017" }]})
You can also create users and databases here and then exit out of it. Uncomment the following section in mongo.conf,
replication:
replSetName: rs0-here
run mongod again and then this issue should go away.

How to convert a MongoDB replica set to a stand alone server

Consider, I have 4 replicate sets and the config is as follows:
{
"_id": "rs_0",
"version": 5,
"members" : [
{"_id": 1, "host": "127.0.0.1:27001"},
{"_id": 2, "host": "127.0.0.1:27002"},
{"_id": 3, "host": "127.0.0.1:27003"},
{"_id": 4, "host": "127.0.0.1:27004"}
]
}
I am able to connect to all sets using
mongo --port <port>
There are documents for getting information on Convert a Standalone to a Replica Set, but can anyone tell me how to convert back to standalone from replica set?
Remove all secondary hosts from replica set (rs.remove('host:port')), restart the mongo deamon without replSet parameter (editing /etc/mongo.conf) and the secondary hosts starts in standalone mode again.
The Primary host is tricky one, because you can't remove it from the replica set with rs.remove.
Once you have only the primary node in the replica set, you should exit mongo shell and stop mongo. Then you edit the /etc/mongo.conf and remove the replSet parameter and start mongo again.
Once you start mongo you are already in standalone mode, but the mongo shell will prompt a message like:
2015-07-31T12:02:51.112+0100 [initandlisten] ** WARNING: mongod started without --replSet yet 1 documents are present in local.system.replset
to remove the warning you can do 2 procedures:
1) Droping the local db and restarting mongo:
use local
db.dropDatabase();
/etc/init.d/mongod restart
2)Or if you don't want to be so radical, you can do:
use local
db.system.replset.find()
and it will prompt a message like:
{ "_id" : "replicaSetName", "version" : 1, "members" : [ { "_id" : 0, "host" : "hostprimary:mongoport" } ] }
then you will erase it using:
db.system.replset.remove({ "_id" : "replicaSetName", "version" : 1, "members" : [ { "_id" : 0, "host" : "hostprimary:mongoport" } ] })
and it will probably prompt:
WriteResult({ "nRemoved" : 1 })
Now, you can restart the mongo and the warning should be gone, and you will have your mongo in standalone mode without warnings
Just remove a host from replica set (rs.remove('host:port')), relaunch it without replSet parameter and it's standalone again.
On an Ubuntu Machine
Stop your mongo server
open /etc/mongod.conf
Comment the replication and replSetName line
#replication:
#replSetName: rs0
Start your mongo server and go to mongo shell
drop local database
use local
db.dropDatabase()
Restart mongo
The MongoDB Documentation suggests the following to perform maintenance on a replica set member, which brings the the replica set member into standalone mode for further operations. With little modification it can be made standalone:
If node in concern is the only node in a shard, drain the chunks to other shards as per MongoDB documentation here, or else the sharded database will break, i.e.
Make sure balancer is enabled by connecting to mongos and run sh.startBalancer(timeout, interval)
For the shard in concern, go to admin database and db.adminCommand( { removeShard: "mongodb0" } )
Check draining status by repeating above removeShard command, wait for draining to complete
If node in concern is primary, do rs.stepDown(300)
Stop the node by running db.shutdownServer()
Change the yaml config by:
commenting out replication.replSetName (--replSetName in command line)
commenting out sharding.clusterRole for shard or config server (--shardsvc and --configsvr in command line)
commenting out net.port, then change it to a different port (--port in command line)
Start the mongod instance
If change is permanent, go to other mongod instance and run rs.remove("host:port")
After this, the node in concern should be up and running in standalone mode.
Follow below steps :
Go to mongo shell on Secondary servers
Stop the secondary servers by using below command :
use admin
db.shutdownServer()
Go to Linux shell- on secondary servers and type below command :
sudo service mongod stop
Starting the MongoDB replication -
Go to Linux shell - on secondary servers and type below command :
sudo service mongod start
Starting the MongoDB replication -
Go to primary and type below commands to start the replication :
a] rs.initiate()
b] rs.add("Secondar -1:port no")
c] rs.add("Secondary-2:port no")
d] rs.add({ "_id" : 3, "host" : "Hidden_member:port no", "priority" : 0,
"hidden" : true })
e] rs.status()