Discussion:
[mongodb-user] connection attempt failed : connect@src/mongo/shell/mongo.js:251:13 @(connect):1:6 exception: connect failed
Monika Shah
2018-02-26 04:50:57 UTC
Permalink
I am using mongoshard.bat file to start mongodb shard server. It was
working yesterday, but giving connection error for last few attempt

Getting connection error while executing following batch file.

Error message
============
"Error: couldn't connect to serve*r 127.0.0.1:37017
<http://127.0.0.1:37017>,* connection attempt failed :
c****@src/mongo/shell/mongo.js:251:13 @(connect):1:6* exception: connect
failed"


mongoshard.bat file
================
set mongo_home_path=C:/Program Files/MongoDB/Server/3.6.2/bin
set root_path=e:/mongodb
set data_path=d:/MongoDB/shard

echo Start 3 mongod for replicatSet #
start /b "s1-a" "%mongo_home_path%/mongod" --replSet s1 --logappend
--logpath "%data_path%/s1/a/s1_a.log" --dbpath "%data_path%/s1/a" --port
37017 --oplogSize 200 --shardsvr
start /b "s1-b" "%mongo_home_path%/mongod" --replSet s1 --logappend
--logpath "%data_path%/s1/b/s1_b.log" --dbpath "%data_path%/s1/b" --port
37018 --oplogSize 200 --shardsvr
start /b "s1-c" "%mongo_home_path%/mongod" --replSet s1 --logappend
--logpath "%data_path%/s1/c/s1_c.log" --dbpath "%data_path%/s1/c" --port
37019 --oplogSize 200 --shardsvr
timeout /t 5

echo Start 3 mongod for replicatSet #
start /b "s2-a" "%mongo_home_path%/mongod" --replSet s2 --logappend
--logpath "%data_path%/s2/a/s2_a.log" --dbpath "%data_path%/s2/a" --port
47017 --oplogSize 200 --shardsvr
start /b "s2-b" "%mongo_home_path%/mongod" --replSet s2 --logappend
--logpath "%data_path%/s2/b/s2_b.log" --dbpath "%data_path%/s2/b" --port
47018 --oplogSize 200 --shardsvr
start /b "s2-c" "%mongo_home_path%/mongod" --replSet s2 --logappend
--logpath "%data_path%/s2/c/s2_c.log" --dbpath "%data_path%/s2/c" --port
47019 --oplogSize 200 --shardsvr
timeout /t 5

echo Start 3 config servers
start /b "cfg-a" "%mongo_home_path%/mongod" --logappend --logpath
"%data_path%/cfg-a/cfg_a.log" --dbpath "%data_path%/cfg-a" --replSet conf
--port 57017 --configsvr
start /b "cfg-b" "%mongo_home_path%/mongod" --logappend --logpath
"%data_path%/cfg-b/cfg_b.log" --dbpath "%data_path%/cfg-b" --replSet conf
--port 57018 --configsvr
start /b "cfg-c" "%mongo_home_path%/mongod" --logappend --logpath
"%data_path%/cfg-c/cfg_c.log" --dbpath "%data_path%/cfg-c" --replSet conf
--port 57019 --configsvr
timeout /t 20

echo Configure shard #1
start /b "configure S1" "%mongo_home_path%/mongo" --port 37017
"%root_path%/configS1.js"

echo Configure shard #2
start /b "configure S2" "%mongo_home_path%/mongo" --port 47017
"%root_path%/configS2.js"

start /b "configure shard" "%mongo_home_path%/mongo" --port 57017
"%root_path%/configS.js"

start /b "mongos" "%mongo_home_path%/mongos" --port 61017 --logappend
--logpath "%data_path%/mongos.log" --configdb "conf/localhost:57017,
localhost:57018,localhost:57019"
start /b "configure shard" "%mongo_home_path%/mongo" --shell --port 61017
"%root_path%/configShard_alt.js"
===================================================================



Where, configS1.js contains
===========================
configS1 = {
"_id" : "s1",
"members" : [
{
"_id" : 1,
"host" : "localhost:37017"
},
{
"_id" : 2,
"host" : "localhost:37018"
},
{
"_id" : 3,
"host" : "localhost:37019"
}
]
};
rs.initiate(configS1);
===========================
configS.js
======================
rs.initiate(
{
_id: "conf",
configsvr: true,
members: [
{ _id : 0, host : "localhost:57017" },
{ _id : 1, host : "localhost:57018" },
{ _id : 2, host : "localhost:57019" }
]
}
)
==================================
--
Monika Shah
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CAOYegx7NUQHTO9KKK9%3DwUA0UqhvK7Qz%3DfxHqMsbZP4RP3aoUWw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
'Kevin Adistambha' via mongodb-user
2018-03-02 05:28:07 UTC
Permalink
Hi

If you’re looking to automate starting up a MongoDB deployment for testing
purposes (i.e. all mongod runs on localhost), then I would encourage you to
take a look at mtools <https://github.com/rueckstiess/mtools>, especially
the tool mlaunch <https://github.com/rueckstiess/mtools/wiki/mlaunch>.

From my understanding, the deployment you posted could be started by mlaunch
using the following command:

mlaunch init --sharded 2 --replicaset --config 3

That is, initialize a sharded cluster with 2 shards, where each shard
contains a 3-node replica set, and use a 3-node config server.

The sh.status() output of the result is:

mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5a98de77fc15b1d0705111b5")
}
shards:
{ "_id" : "shard01", "host" : "shard01/localhost:27018,localhost:27019,localhost:27020", "state" : 1 }
{ "_id" : "shard02", "host" : "shard02/localhost:27021,localhost:27022,localhost:27023", "state" : 1 }
active mongoses:
"3.4.9" : 1
autosplit:
Currently enabled: yes
balancer:
Currently enabled: yes
Currently running: no
Balancer lock taken at Thu Mar 01 2018 21:17:45 GMT-0800 (Pacific Standard Time) by ConfigServer:Balancer
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:

Please refer to the installation instruction
<https://github.com/rueckstiess/mtools/blob/develop/INSTALL.md> to install
mtools and the mlaunch manual
<https://github.com/rueckstiess/mtools/wiki/mlaunch> for operating mlaunch.

Best regards
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/6147bde8-b0e2-4704-a52d-b9f17a9a9c04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Monika Shah
2018-03-29 17:41:48 UTC
Permalink
Thank you
Post by 'Kevin Adistambha' via mongodb-user
Hi
If you’re looking to automate starting up a MongoDB deployment for testing
purposes (i.e. all mongod runs on localhost), then I would encourage you
to take a look at mtools <https://github.com/rueckstiess/mtools>,
especially the tool mlaunch
<https://github.com/rueckstiess/mtools/wiki/mlaunch>.
From my understanding, the deployment you posted could be started by
mlaunch init --sharded 2 --replicaset --config 3
That is, initialize a sharded cluster with 2 shards, where each shard
contains a 3-node replica set, and use a 3-node config server.
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5a98de77fc15b1d0705111b5")
}
{ "_id" : "shard01", "host" : "shard01/localhost:27018,localhost:27019,localhost:27020", "state" : 1 }
{ "_id" : "shard02", "host" : "shard02/localhost:27021,localhost:27022,localhost:27023", "state" : 1 }
"3.4.9" : 1
Currently enabled: yes
Currently enabled: yes
Currently running: no
Balancer lock taken at Thu Mar 01 2018 21:17:45 GMT-0800 (Pacific Standard Time) by ConfigServer:Balancer
Failed balancer rounds in last 5 attempts: 0
No recent migrations
Please refer to the installation instruction
<https://github.com/rueckstiess/mtools/blob/develop/INSTALL.md> to
install mtools and the mlaunch manual
<https://github.com/rueckstiess/mtools/wiki/mlaunch> for operating mlaunch
.
Best regards
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d279ddf4-26e5-48c5-9ac4-5099b64c7fd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Monika Shah
2018-04-05 17:08:50 UTC
Permalink
Thank you, but can you help me to find solution of this error
Post by 'Kevin Adistambha' via mongodb-user
Hi
If you’re looking to automate starting up a MongoDB deployment for testing
purposes (i.e. all mongod runs on localhost), then I would encourage you
to take a look at mtools <https://github.com/rueckstiess/mtools>,
especially the tool mlaunch
<https://github.com/rueckstiess/mtools/wiki/mlaunch>.
From my understanding, the deployment you posted could be started by
mlaunch init --sharded 2 --replicaset --config 3
That is, initialize a sharded cluster with 2 shards, where each shard
contains a 3-node replica set, and use a 3-node config server.
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5a98de77fc15b1d0705111b5")
}
{ "_id" : "shard01", "host" : "shard01/localhost:27018,localhost:27019,localhost:27020", "state" : 1 }
{ "_id" : "shard02", "host" : "shard02/localhost:27021,localhost:27022,localhost:27023", "state" : 1 }
"3.4.9" : 1
Currently enabled: yes
Currently enabled: yes
Currently running: no
Balancer lock taken at Thu Mar 01 2018 21:17:45 GMT-0800 (Pacific Standard Time) by ConfigServer:Balancer
Failed balancer rounds in last 5 attempts: 0
No recent migrations
Please refer to the installation instruction
<https://github.com/rueckstiess/mtools/blob/develop/INSTALL.md> to
install mtools and the mlaunch manual
<https://github.com/rueckstiess/mtools/wiki/mlaunch> for operating mlaunch
.
Best regards
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/855d77a6-7098-42e5-8513-1575bea46c8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Monika Shah
2018-04-05 17:36:40 UTC
Permalink
It was working fine for few days. suddenly it started giving this error.
mongos log shows message
"Unable to reach primary for set" conf


I am surprised to see such uncertain behavior. It works fine sometime , and
give error sometime.
What is cause and solution of this error?
Post by 'Kevin Adistambha' via mongodb-user
Hi
If you’re looking to automate starting up a MongoDB deployment for testing
purposes (i.e. all mongod runs on localhost), then I would encourage you
to take a look at mtools <https://github.com/rueckstiess/mtools>,
especially the tool mlaunch
<https://github.com/rueckstiess/mtools/wiki/mlaunch>.
From my understanding, the deployment you posted could be started by
mlaunch init --sharded 2 --replicaset --config 3
That is, initialize a sharded cluster with 2 shards, where each shard
contains a 3-node replica set, and use a 3-node config server.
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5a98de77fc15b1d0705111b5")
}
{ "_id" : "shard01", "host" : "shard01/localhost:27018,localhost:27019,localhost:27020", "state" : 1 }
{ "_id" : "shard02", "host" : "shard02/localhost:27021,localhost:27022,localhost:27023", "state" : 1 }
"3.4.9" : 1
Currently enabled: yes
Currently enabled: yes
Currently running: no
Balancer lock taken at Thu Mar 01 2018 21:17:45 GMT-0800 (Pacific Standard Time) by ConfigServer:Balancer
Failed balancer rounds in last 5 attempts: 0
No recent migrations
Please refer to the installation instruction
<https://github.com/rueckstiess/mtools/blob/develop/INSTALL.md> to
install mtools and the mlaunch manual
<https://github.com/rueckstiess/mtools/wiki/mlaunch> for operating mlaunch
.
Best regards
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/975630cb-de0a-4933-88be-cc5820b548b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Kevin Adistambha' via mongodb-user
2018-04-17 05:18:15 UTC
Permalink
Hi

“Unable to reach primary for set” conf

This means that the mongos process cannot connect to the primary of the
shard replica set.

The full message in your mongos log generally look like this:

2018-04-17T15:13:41.328+1000 W NETWORK [conn6] Unable to reach primary for set shard01
2018-04-17T15:13:41.831+1000 W NETWORK [conn6] Failed to connect to 127.0.0.1:27018, in(checking socket for error after poll), reason: Connection refused

In the example above, the message Connection refused was due to the mongod
process of the shard server is not running. Your actual message might be
different, and would provide a hint of why mongos cannot connect to the
relevant server.

Typically there are two possible causes:

1. The primary node of the shard is actually offline
2. The machine running the mongos process cannot reach the shard due to
some network issues

Could you confirm that all the mongod process (shard servers, config
servers) are up and running, and there is no network connectivity issues
between the nodes in your cluster?

Best regards
Kevin
​
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.

For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/31d35aaf-28c6-492b-9afb-41b7b76254d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...