Mongo sharding without shutdown the existing mongo instance - mongodb

I need to do sharding without shutdown or restart the existing mongo instance in the port 27017 .
I tried the following, (while the default port is running and mongo instance)
mongod --shardsvr --dbpath /var/lib/mongodb/dba --port 10001 > /var/log/mongodb/shardlog/sharda.log &
mongod --shardsvr --dbpath /var/lib/mongodb/dbb --port 10002 > /var/log/mongodb/shardlog/shardb.log &
mongod --configsvr --dbpath /var/lib/mongodb/config --port 20000 > /var/log/mongodb/shardlog/configdb.log &
mongos --configdb localhost:20000 > /var/log/mongodb/shardlog/mongos.log &
Then mongos log giving an error,
Thu Aug 23 14:44:36 [mongosMain] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Thu Aug 23 14:44:36 [mongosMain] ERROR: addr already in use
mongos is running on port 20000 but why It's trying to connect the default 27017 port?
Can I start mongos with several shards without disturbing the existing mongo instance on port 27017 ?

From the the list of commands you have given, it looks like you have not told the mongos to start on a different port than default.
You would need to supply the --port argument for mongos to start on a different port.
Try: mongos --configdb localhost:20000 --port 10003
Note: mongos is not running on port 20000 as you have said above. You have the config server running on that port

Related

Unable to start MongoDB shell for mongos daemon

I am trying to setup a sharded mongodb cluster using 4 solaris-11 servers which are on the same rack. The following sharded config is being attempted:
Server A : Replica set 1(rs1)
Server B : Replica Set 2(rs2)
Server C : Configuration Server
Server D : Sharding Router
#
On Server A, rs1 has been set up as follows:
mongod --port 27017 --replSet rs1 --dbpath "/mongo/datadb"
Now the rs1 configuration in mongo shell:
config =
{
_id:"rs1",
members:
[
{ _id:0, host:"Server A IP:27017" },
]
}
rs.initiate( config )
rs.conf()
rs.status()
On Server B , rs2 has been similarly configured.
#
On Server C, the config server has been configured as follows:
mongod --configsvr --port 37017 --dbpath "/rpool/mongo/datadb"
#
Now on Server D, I am running mongos using the following :
mongos --port 27017 --configdb rs1/'Server C IP':37017
When I am trying to open mongo Shell on server D to add the shards using the mongos port and connect to mongos, I am unable to do so. The following error is thrown :
**./mongo --port 27017 --host 'Server C '
MongoDB shell version v3.4.1
connecting to: mongodb://'Server C ip':27017/
2017-11-09T11:21:51.666+0000 W NETWORK [main] Failed to connect to :27017, in(checking socket for error after poll), reason: Connection refused
2017-11-09T11:21:51.686+0000 E QUERY [main] Error: couldn't connect to server 'Server C ip':27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:234:13
#(connect):1:6
exception: connect failed**
When I tried to debug, I found the port 27017 on Server C to be in 'BOUND' state:
netstat -an |grep 27017
*.27017 . 0 0 128000 0 BOUND
'Server ip' stream-ord server ip' 0000000000000000 /tmp/mongodb-27017.sock
Shouldn't mongos occupy this port in Listening mode? Can someone help me in solving this?
Is there any issue with the configuration?

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

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/

Mongo Sharding got trouble when using vmware

Mongo worked fine when i'm using the local machine.But when i add the shard(established on vmware),i can't do insert operation anymore.
error message:
caused by :: Location28563 cannot send batch write operation to server 192.168.153.132:3000 (192.168.153.132)'. (Response was { "err" : "write results unavailable from 192.168.153.132:3000 :: caused by :: Location28563 cannot send batch write operation to server
config server setup command:
mongod --dbpath=config --port 2222 --bind_ip 0.0.0.0
route server setup command:
mongos --port 3333 --configdb=192.168.153.1:2222 --bind_ip 0.0.0.0
shard server setup command:
mongod --dbpath=Shard1 --port 4444 --bind_ip 0.0.0.0
And i'd done addShard command on the route server.

MongoDB: can't shard on localhost because of shard socket exception

I'm trying the MongoDB's shard tutorial, for some simple testing (proof-of-concept project).
I want to try sharding on a single machine. Is this possible and/or does it make any sense?
When I follow the guide steps, it does not work.
First, I start the mongod configsrv database instances on my machine:
bin/mongod --configsvr --dbpath $BASEDIR/data/configdb --port 27019 &
bin/mongod --configsvr --dbpath $BASEDIR/data/configdb1 --port 27020 &
bin/mongod --configsvr --dbpath $BASEDIR/data/configdb2 --port 27021 &
Then, I start the mongos instances so that they "bind" to the config servers:
HOST=$(uname -n) # my machine's name
# starts on default poort 27017
bin/mongos --configdb $HOST:27019,$HOST:27020,$HOST:27021
Until here, everything looks good.
Now I want to add a Shard to the cluster:
bin/mongo --host $(uname -n)
It enters the MongoDB shell.
connecting to: my.machine.name:27017/test
But when I try to add a new shard, I have the following error:
mongos> sh.addShard( "rs1/my.machine.name:27017" )
{
"ok" : 0,
"errmsg" : "couldn't connect to new shard socket exception [CONNECT_ERROR] for rs1/my.machine.name:27017"
}
I have tried with ip, machine's alias, localhost ... nothing seems to work.
Anyone could help me on this? Maybe I'm missing a point.
Thanks in advance
I had the same problem, you have to run
mongod &
on your each of your shards
and then you can call
sh.addShard( "rs1/my.machine.name:27017" )
Its possible, follow below sequence.
lets say we want to create a cluster with 3 shards each with 1 replica on same machine.
Start first mongod server (shard 1 with replica 1)with a replica set named s1
Start second mongod server (shard 2 with replica 1)with a replica set named s2
Start third mongod server (shard 3 with replica 1)with a replica set named s3
mkdir -p /data/shard0/rs0 /data/shard0/rs1 /data/shard0/rs2
/bin/mongod --replSet Sv1 --logpath "Sv1-r0.log" --dbpath /data/shard0/rs0 --port 37017
/bin/mongod --replSet Sv2 --logpath "Sv2-r0.log" --dbpath /data/shard0/rs1 --port 47017
/bin/mongod --replSet Sv3 --logpath "Sv3-r0.log" --dbpath /data/shard0/rs2 --port 57017
This will start 3 mongod servers/shards with one replica for each shard
/bin/mongo --port 37017 << 'EOF'
config = { _id: "Sv1", members:[
{ _id : 0, host : "<ip>:37017" }]};
rs.initiate(config)
EOF
This will add replicas to replica set Sv1. This should be done for each shard i.e. on each port 47017 and 57017
Now we have cluster ready with shards and replicas but no one knows other shards and replicas, thus we need config server
/bin/mongod --logpath "cfg-a.log" --dbpath /data/config/config-a --port 57040 --fork --configsvr
Then start mongos for admin access,
/bin/mongos --logpath "mongos-1.log" --configdb 10.88.66.218:57040
Now add shards to our cluster,
/bin/mongo <<'EOF'
db.adminCommand( { addShard : "Sv1/"+"<ip>:37017" } );
db.adminCommand( { addShard : "Sv2/"+"<ip>:47017" } );
db.adminCommand( { addShard : "Sv3/"+"<ip>:57017" } );
use db
db.createCollection("col1")
db.adminCommand({enableSharding:"db"}) db.adminCommand({shardCollection: "db.col1", key: {_id:"hashed"}});
EOF
And that's it.... Cluster should be up with 3 shards. You can check with sh.status() command on mongos.