I am trying to install a ReplicaSet with the help of the following manual:
[https://docs.mongodb.com/manual/tutorial/convert-standalone-to-replica-set/]
However, I always get that error:
Replication has not yet been configured
my code in OpenSUSE terminal
sudo mongod --port 27017 --dbpath /var/lib/mongo --replSet rs0 --bind_ip localhost
/etc/mongod.conf does have the following line:
replication:
replSetName: "rs0"
Anyone who could help me here? Would appreciate that!
You have two possibilities to start mongod
sudo mongod --port 27017 --dbpath /var/lib/mongo --replSet rs0 --bind_ip localhost
OR (when all those parameters, port, dbpath, bindIp... Are set in the config-file)
sudo mongod --config /etc/mongod.conf
Now mongod is running and it knows that it should be replica set.
Connect to that RS with 'mongo' command. You get answer like "MongoDB shell version v4.0.19" and prompt '>' where cursor is waiting your next command.
Now you need (only once) to initiate this replica set, give next command:
rs.initiate()
Now your prompt should be changed to
rs0:PRIMARY>
And you can "ask" now your replica set status
rs.status()
Or the configuration
rs.conf()
Related
Trying to set up a local sharded cluster for testing (mongo 3.6). There are a number of scripts online (e.g here, here) all of which seem to fail for me.
running (cribbed mostly from the 2nd example above):
start the config server:
mongod --configsvr --replSet csrs --dbpath /data/db/configdb --port 27018 --fork --logpath log/mongods.log
initiate the replica set on the config:
mongo localhost:27018 << !
rs.initiate({_id: "csrs", configsvr: true, members: [{_id: 0, host: "${local_ip}:27018"}]});
!
start the mongod processes:
mongod --port 27030 --dbpath /data/db/db1-0 --shardsvr --replSet rs --fork --logpath log/mongod1-0.log
mongod --port 27040 --dbpath /data/db/db2-0 --shardsvr --replSet rs --fork --logpath log/mongod2-0.log
mongod --port 27020 --dbpath /data/db/db0-0 --shardsvr --replSet rs --fork --logpath log/mongod0-0.log
initiate the replica set(s)
mongo localhost:27020 << !
rs.initiate({_id: "rs", members: [{_id: 0, host: "${local_ip}:27020"}, {_id: 1, host: "${local_ip}:27030"}, {_id: 1, host: "${local_ip}:27040"}]});
!
(note, initial script had a separate rs for each shard, which caused the same error)
start a mongos and point it to the config server:
mongos --configdb csrs/${local_ip}:27018 --port 27017 --fork --logpath log/mongos.log
log into the mongos and add shards:
e.g. sh.addShard("rs/${local_ip}:27020").
This last step is where this goes wrong, getting the error
"errmsg" : "Could not find host matching read preference { mode: \"primary\" } for set rs",
"code" : 133,
Can anyone provide any pointers on what I'm missing here?
I have done Replication in one single machine with three different port(Say 27018[master],27019,27020). Also I have done Sharding in one single machine with two different port(Say 27021,27022).
Now I have to implement replication for the sharded machine port. I need to implement replication for 27021 and 27022. How can I do this? Please help me to resolve this issue.
Steps followed :
Part 1: Set up 3 port for replication
mongod --replSet rs0
mongod --port 27018 --dbpath F:\Data1 --replSet rs0
mongod --port 27020 --dbpath F:\Data2 --replSet rs0
mongo localhost:27017
rs.initiate()
rs.add("ComputerName:27018")
rs.add("ComputerName:27020")
Part 2: Now set up for sharding
mongod --configsvr --replSet configReplSet
mongod --port 27021 --dbpath F:\Data4 --replSet configReplSet
mongod --port 27025 --dbpath F:\Data5 --replSet configReplSet
mongo 127.0.0.1:27019
rs.initiate({_id:"configReplSet",configsvr:true,members:[{_id: 0,host: "127.0.0.1:27021"},{_id:1,host: "127.0.0.1:27025"}]})
When I run this code I am getting an error:
{
"ok" : 0,
"errmsg" : "No host described in new configuration 1 for replica set configReplSet maps to this node",
"code" : 93
}
So remaining steps I am not able to execute. Any idea how can I overcome this issue?
Got one method to achieve my requirement.
Steps as follows
Config Server and its replication
mongod --configsvr --dbpath F:\Data1\configdb\ --replSet rs2 --port 27017
mongod --configsvr --dbpath F:\Data2\configdb\ --replSet rs2 --port 27018
mongod --configsvr --dbpath F:\Data3\configdb\ --replSet rs2 --port 27019
mongo machineip:27017
config= {_id:"rs2", members :[{ _id:0, host:'10.18.0.225:27017'}, {_id:1, host:'10.18.0.225:27018'}, {_id:2, host:'10.18.0.225:27019'}]}
rs.initiate (config)
rs.status()
Routing Server
mongos -configdb machineip:27017 --port 27020
Shard1 and its replication
mongod --dbpath F:\Data4\db\ --shardsvr --replSet rs0 --port 27021
mongod --dbpath F:\Data5\db\ --shardsvr --replSet rs0 --port 27022
mongod --dbpath F:\Data6\db\ --shardsvr --replSet rs0 --port 27023
Shard2 and its replication
mongod --dbpath F:\Data7\db\ --shardsvr --replSet rs1 --port 27024
mongod --dbpath F:\Data8\db\ --shardsvr --replSet rs1 --port 27025
mongod --dbpath F:\Data9\db\ --shardsvr --replSet rs1 --port 27026
Replication configuration for Shard1
mongo machineip:27021
config= {_id:"rs0", members :[{ _id:0, host:'machineip:27021'},{_id:1,host:'machineip:27022'},{_id:2,host:'machineip:27023'}]}
rs.initiate(config)
rs.status()
Replication configuration for Shard2
mongo machineip:27024
config= {_id:"rs0", members :[{ _id:0, host:'machineip:27024''},{_id:1,host:'machineip:27025''},{_id:2,host:'machineip:27026''}]}
rs.initiate(config)
rs.status()
Sharding Configuration in route server
sh.status()
sh.addShard ("rs0/machineip:27021")
sh.addShard ("rs0/machineip:27024")
sh.status()
sh.enableSharding ("test")
sh.shardCollection ("test.stud", {id: 1})
sh.status()
Hope this will help :-)
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: "myLocalIP:27117"
}]
}
rs.initiate( rsconf )
rs.add("myLocalIP:27118")
rs.add("myServerIP:27119")
So I tried to do Test Connections in both directions:
from my local's shell:
mongo --host myCloudServer --port 27119
I enter in the server but it's not the Replica Set instance
from cloud-server's shell, it fails:
mongo --host myLocalIP --port 27017
where is the error? Thanks
I take it back about test connections.
Both connections from myLocal to remote-myCloud and vice-versa was refused
Got errno:61 Connection refused when I type mongo --port 27003 on mac osx terminal
but simply mongo it's working fine
By default mongod runs on 27017 port.
When you type "mongo" it connects to that port and not 27003.
Try this "mongo --port 27017"
If you want to run mongod on a different port
Open : /etc/mongodb.conf
Change
port: 27003
Restart mongod service
sudo service mongod restart
i am creating replica set on my local system in windows environment
by following step
mkdir -p \srv\mongodb\rs0-0 \srv\mongodb\rs0-1 \srv\mongodb\rs0-2
mongod --port 27017 --dbpath \srv\mongodb\rs0-0 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27018 --dbpath \srv\mongodb\rs0-1 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27019 --dbpath \srv\mongodb\rs0-2 --replSet rs0 --smallfiles --oplogSize 128
and then
mongo shell type mongo --port 27017
rs.initiate()
but i am getttin error
"{ "ok" : 0, "errmsg" : "server is not running with --replSet" }"
thanks in advance
I had the same problem. Thanks to this question and previous answers I solved doing:
I checked all the running mongod processes ps -ef | grep mongo. I had 1 mongo and 2 mongod processes
I killed mongod with sudo sudo killall mongod
and at the end I started with sudo sudo mongod --port 27017 --dbpath \srv\mongodb\rs0-0 --replSet rs0 --smallfiles --oplogSize and it worked