MongoDb Sharding on Local Machine - mongodb

I am trying to create a sharding on my local machine. But when I create MongoDB shard server in the bin directory using this command start mongod --shardsvr --port 2005 -logpath C:\data\shard\s0\log\s0.log --dbpath C:\data\shard\s0 nothing happens so I went on to create mongos router mongos --port 2007 --configdb test/localhost:2001. Mongos created successfully and then I add shard to mongos using command sh.addShard("localhost:2005") then this error appears "errmsg" : "failed to run command { isMaster: 1 } when attempting to add shard localhost:2005 :: caused by :: HostUnreachable: Error connecting to localhost:2005 (127.0.0.1:2005) :: caused by :: No connection could be made because the target machine actively refused it.". I don't know how to deal with this error.

Related

MongoDB - couldn't connect to server 127.0.0.1:27017, caused by :Connection refused : connect#src/mongo/shell/mongo.js:374:17

I installed mongodb with homebrew and i use Mac OS Big Sur
when I start mongo db with
$ brew services start mongodb-community
It says that mongodb it successfully started but when i run
$ brew services list
The status of mongodb-community is "error" and if I try to type the command "mongo" in the cmd it gave me the problem explained in the title of this question:
MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
I ran the following in command line to fix the problem.
mongod --dbpath /usr/local/var/mongodb
this was directly after a re-install.
The error message that clued me in was:
{"t":{"$date":"2021-04-22T11:33:48.608-04:00"},"s":"E", "c":"STORAGE", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
more specifically
"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."
if you want to run mongodb type on terminal:
mongod --dbpath /usr/local/var/mongodb
If it not works use only:
mongod
And if you want to make CRUD in your db via SHELL or TERMINAL, run this :
mongo
-Archlinux
Search for [.mongodb / mongosh /]
Give execute permission to config.

MongoDB is not running as service

I have installed Mongo on my OSX
$ brew info mongodb
mongodb: stable 4.0.2 (bottled)
...
I'm starting MongoDB service by this command:
$ brew services start mongodb
I can observe the status of mongodb:
$ brew services list
Name Status User Plist
mongodb started megas /Users/megas/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
...
But when I'm running mongo client it give me an error:
$ mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
2018-09-19T15:18:22.490+0300 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:257:13
#(connect):1:6
exception: connect failed
When I manually start mongod then it works as it should be.
What I'm missing here?
Update:
If I run it manually it throughs message and stops
$ mongod --config /usr/local/etc/mongod.conf
2018-09-19T21:47:51.531+0300 I CONTROL [main] Automatically disabling
TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
$ cat /usr/local/etc/mongod.conf
# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb
# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true
# Only accept local connections
bind_ip = 127.0.0.1

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?

Mongos alway exit unexpectedly

I started one Mongos server by the following command:
nohup mongos --port 57017 --configdb configsvr1:47017,configsvr2:47017,configsvr3:47017 > s.nohup 2>&1 &
configsvr* are configuration servers. my problem is that Mongos instance always exit after a few hour.
The Mongos log I found as following:
W SHARDING [LockPinger] Error encountered while stopping ping on mongos_server:
57017:1472436263:-1365656364 :: caused by :: 17382
Can't use connection pool during shutdown
I SHARDING [signalProcessingThread] dbexit: rc:0

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.