MongoDB server is not running with replset - mongodb

I do a MongoDB homework and follow the steps, but I faced the problem " server is not running with replset"
I do the step is :
`"start mongod --replSet m101 --logpath 1.log --dbpath \data\rs1 --port 27017 --smallfiles --oplogSize 64
start mongod --replSet m101 --logpath 2.log --dbpath \data\rs2 --port 27018 --smallfiles --oplogSize 64
start mongod --replSet m101 --logpath 3.log --dbpath \data\rs3 --port 27019 --smallfiles --oplogSize 64
Now connect to a mongo shell and make sure it comes up.
mongo --port 27017
Now you will create the replica set. Type the following commands into the mongo shell:
config = { _id: "m101", members:[`
{ _id : 0, host : "localhost:27017"},
{ _id : 1, host : "localhost:27018"},
{ _id : 2, host : "localhost:27019"} ]
};
rs.initiate(config);"
I do not know where is the problem, someone said the problem maybe is another mongod is running. But I have not any other mongod running in the same time.
Thank you!

It happened the same to me as well. The problem was that I have runned mongod without any parameters before I started launching the nodes.
First kill all the mongo, mongod and mongos instances to guarantee the environment is clear.
ps -ef | grep -i 'mongo'
sudo service mongod stop
The problem cause is simple. The default port for mongod and mongos is 27017. So, what happened to me was that the first replica node was never created. The following command was connecting me to a default mongod instance:
mongo --port 27017
I hope this solves your problem. ;)

Check what command line options the mongod you are connected to in the shell is running with:
> use admin
switched to db admin
> db.runCommand("getCmdLineOpts")
{
"argv" : [
"mongod",
"--dbpath",
"/data/db",
"--replSet",
"rs0"
],
"parsed" : {
"replication" : {
"replSet" : "rs0"
},
"storage" : {
"dbPath" : "/data/db"
}
},
"ok" : 1
}
Do you see the replSet option?
You can also try a different way of initiating the replica set. Instead of typing in the configuration and passing it to rs.initiate(), just run rs.initiate(). It will set up default config with one member- the server you are connected to in the shell. Then you can add the other two servers. See the tutorial for more information.

For MacOS Homebrew setup & default configuration
Edit default configuration mongodb file nano /opt/homebrew/etc/mongod.conf
Insert the following piece of code
replication:
replSetName: "rs0"
Save and restart the mongodb service brew services restart mongodb-community#6.0
Exec the following command in mongosh shell rs.initiate()
$ mongosh
> use admin
admin> rs.initiate()
success response:
{
info2: 'no configuration specified. Using a default configuration for the set',
me: '127.0.0.1:27017',
ok: 1
}

Related

mongos error "mirrored config server connections are not supported"

Is something wrong with this?
$ sudo mongos --logpath "mongos-1.log" --configdb localhost:57040,localhost:57041,localhost:57042 --fork
FailedToParse: mirrored config server connections are not supported; for config server replica sets be sure to use the replica set connection string
try 'mongos --help' for more information
I had the same problem as you just have to update your --configdb to "repSetConfigName/localhost:57040,localhost:57041,localhost:57042"
here is an example :
this is my configuration of the config server:
mongod --configsvr --dbpath cfg0 --replSet conf --port 27050 --fork --logpath log.cfg0 --logappend
mongod --configsvr --dbpath cfg1 --replSet conf --port 27051 --fork --logpath log.cfg1 --logappend
mongod --configsvr --dbpath cfg2 --replSet conf --port 27052 --fork --logpath log.cfg2 --logappend
then I used
# connect to any of the mongod process on port 27050, 27051, 27052
mongo --port 27050
rs.initiate(
{
_id: "conf",
configsvr: true,
members: [
{ _id : 0, host : "localhost:27050" },
{ _id : 1, host : "localhost:27051" },
{ _id : 2, host : "localhost:27052" }
]
}
)
fianlly
mongos --configdb "conf/localhost:27050,localhost:27051,localhost:27052" --fork --logpath log.mongos0 --port 27200
Just appendix to #sylia-baraka answer... If you are using MongoDB 3.4 or newer you need to use CSRS instead of SCCC, read more here.
In version 3.4, MongoDB removes support for SCCC config servers. Before you can upgrade your sharded clusters to 3.4, you must convert your config servers from SCCC to CSRS. To convert to CSRS, follow the procedure to change your 3.2.x SCCC to 3.2.x CSRS.
configdb should be like this :
"your_replSetName/host:port,host:port,host:port"

Configure a Replica Set in local and on a cloud-server

I'm trying to configure a Replica Set with 2 members in local e 1 member on a cloud-server.
I started the two instance from local in this way:
mongod --port 27117 --dbpath mongodb/rs0-0 --logpath mongodb/rs0-0/mongo.log --replSet rs0 --fork
mongod --port 27118 --dbpath mongodb/rs0-1 --logpath mongodb/rs0-1/mongo.log --replSet rs0 --fork
and then I started the instance on my cloud-server (after opened the port):
mongod --port 27119 --dbpath mongoRS/rs0-2 --logpath mongoRS/rs0-2/mongo.log --replSet rs0 --fork
So, I started the server to configure the Replica Set:
mongo --port 27117
rsconf = {
_id: "rs0",
members: [{
_id: 0,
host: "localhost:27117"
}]
}
rs.initiate( rsconf )
rs.add("localhost:27118")
Until now all was correct. But when I tryed to add the server-instance a error occurred:
rs.add("myServer.it:27119")
"errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 2 out of 3",
So I'm thinking that I cannot set this configuration or what?
While trying to add different member in a replSet, you should avoid using localhost(specially when your servers are located at different environments).
Please try below options:
Remove existing replSet member: rs.remove("localhost:27118")
Try to add the server back with host ip(Local Server IP): rs.add("your_server_IP:27118")
Add the cloud server with Public IP: rs.add("Cloud_server_public_IP:27119")
Also ensure 27117,27118 and 27119 ports are opened from both Localhost and Cloud server.
Thanks,
Deep

Not running with replSet option MongoDB

I am trying to create a small replica set on my computer in Windows.
Here is what I have done so far:
I have made three directories in data by
mkdir \data\rs1 \data\rs2 \data\rs3
Now, I am starting three mongo instances:
start mongod --replSet m101 --logpath 1.log --dbpath \data\rs1 --port 27017 --smallfiles --oplogSize 64
start mongod --replSet m101 --logpath 2.log --dbpath \data\rs2 --port 27018 --smallfiles --oplogSize 64
start mongod --replSet m101 --logpath 3.log --dbpath \data\rs3 --port 27019 --smallfiles --oplogSize 64
Now I am starting mongod.exe by command line and connect to a mongo shell by typing
mongo --port 27017
Here is my replica set:
config = { _id: "m101", members:[
{ _id : 0, host : "localhost:27017"},
{ _id : 1, host : "localhost:27018"},
{ _id : 2, host : "localhost:27019"} ]
};
Now when I type rs.initiate(config); , It shows this node was not started with replSet option.
I also tried to run command line options on admin
use admin
db.runCommand("getCmdLineOpts")
and I don't see any --replSet options in there.
I get
{
"argv" : [ "mongod" ],
"parsed" : {},
"ok" : 1
}
I know many questions related to this problem are available and I tried many of them but none of them worked. I am new to this and learning this from one of the courses of MongoDB University. Please can anyone tell me what am I doing wrong?

MongoDB: replSet can't get local.system.replset config from self or any seed "server is not running with --replSet"

I try to setup a Replica Set on Ubuntu 14.04 x64.
First error I run into when trying
$ sudo mongod --port 27017 --replSet rs0:
replSet can't get local.system.replset config from self or any seed (EMPTYCONFIG)
I read that > rs.initiate() solves that issue, so I do
$ sudo service mongod start
$ mongo
rs.initiate()
which throws:
{ "ok" : 0, "errmsg" : "server is not running with --replSet" }
So if I can't start mongod with --replSet how can I solve the error within rs.initiate() which I need to solve the first error?
It's like a vicious circle!
Solved the problem by using a second command shell:
console1:
$ sudo mongod --port 27017 --replSet rs0
console2:
$ mongo
> rs.initiate()
you can set this replSet in /etc/mongodb.conf file,
# Replication
replication:
replSetName: rs0
#fork
processManagement:
fork: true
Fork for running in background.
Now start mongod,
mongod --config /etc/mongod.conf
To check the process status,
ps aux | grep mongod
Refer : https://docs.mongodb.org/manual/administration/configuration/

mongoDB set name does not match

I have got 3 mongod demo replicates servers running on my machine. I have used following command to create replicated server:
F:\>mongod --replSet test2 --dbpath 2 --port 27112 --oplogSize 50 --logpath log.2 --logappend
all output going to: log.2
Like this I have test1 on 27111 port, test2 on 27112 port and test3 on 27113 port. Yet at configuration I am getting an error:
cfg = {
"_id" : "test1",
"members" : [
{
"_id" : 0,
"host" : "localhost:27111"
},
{
"_id" : 1,
"host" : "localhost:27112"
},
{
"_id" : 2,
"host" : "localhost:27113"
}
]
}
> rs.initiate( cfg )
{
"errmsg" : "couldn't initiate : set name does not match the set name host localhost:27112 expects",
"ok" : 0
}
Now what do I have to do to make it match ?
All the sets I would run should have the same name.
For an instance if I run
mongod --replSet test2 --dbpath 2 --port 27112 --oplogSize 50 --logpath log.2 --logappend
all output going to: log.2
Then the other mongo servers I would intend to be in that set, should have the same name test2
The name or variable used in "cfg" = { "_id":="test1" }
should confirm with the name used in the following for parameter replSet for all the members in that replication set.
Then things will work smoothly for you
"start mongod --replSet "test1" --logpath "1.log" --dbpath C:\Replica\rs01 --port 27017 --oplogSize 64
Good luck
Rao
The steps below worked for me:
mongod --port 27017 --dbpath "C:\MongoDB\data01" --replSet rs0 --bind_ip localhost
mongod --port 27018 --dbpath "C:\MongoDB\data02" --replSet rs0 --bind_ip localhost
These two lines start two different mongo instances in different ports.
On the second instance, I have added replSet=rs0 in mongod.conf.
Then add the secondary in rs0 node by this command:
rs.add("localhost:27018")
Try with the name of your machine or 127.0.0.1. It's a best practice to use the DNS name.
MongoDB replicaset doesn't accept localhost. Try using the actual machine name while adding the node to the replicaset as following:
rs.add("MY_MACHINE_NAME:27017");
When adding the replica sets, the --replset should be same for all three. For example if for primary it was "rs01", it should be same for other two also .