Trouble connecting to Mongo Config Server from mongos - mongodb

Folks,
I am setting up a MongoDB Cluster. The problem is when I am starting up 'mongos' it fails to connect to Mongod Config Server. If I start 'mongos' from localhost with same server as Mongod Config Server it connects & works.
localhost-$ mongos --port 30000 --configdb server-02:20000 [Works]
server-01-$ mongos --port 30000 --configdb server-02:20000 [Does Not Work]
Since from localhost I am able to start mongos by connecting to mongo config server & execute queries, it appears that config server is running fine.
Not able to understand what prevents servers to connect to one of their peers. When I attemped to connect first time from localhost, I got a prompt from OS asking whether process 'mongos' should be allowed to accept incoming connections for which I clicked allow. Perhaps if server fails silently because of this permission issue, with no way to prompt.
Error I recieve:
Sun May 8 01:14:46 ./mongos db version v1.8.1, pdfile version 4.5 starting (--help for usage)
Sun May 8 01:14:46 git version: a429cd4f535b2499cc4130b06ff7c26f41c00f04
Sun May 8 01:14:46 build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
uncaught exception in mongos main:
11002 socket exception [6] server [server-02:20000] mongos connectionpool error: couldn't connect to server server-02:20000
Well I did try clean install yet the problem persisted, so I moved my mongos to a different server with new install & it appears to connect to config server without any issue. Apparently there is some sort of socket contention issue with first server I tried to run mongos.

In all the directories of your mongodb's datas, you have a mongo.lock file. If this file is not empty, it seems to mean that one instance of mongodb executable (config, shard data server) is already running.
Just delete this file in each directory if not empty.

Check your bindip value, which is used by your mongo service. Take out the bindip flag. It works perfectly.

Related

MongoDB Sharding - Unable to reach primary for set c1

I have a huge amount of data, therefore I am going to use sharding on MongoDB. I have exactly followed the same steps mentioned here, but getting the warning Unable to reach primary for set c1 when I execute the command mongos --configdb c1/mongodb-test-config on the front-end machine.
Also, when I execute the next command mentioned in the linked tutorial mongo localhost:27017 on the front-end machine, getting the error couldn't connect to server localhost:27017.
Notes in advance:
I have already configured iptables to allow connections on the port 27017
I have set bindIp to 0.0.0.0 in the mongod.conf file
MongoDB Version: 4.0.2
Ubuntu Version: 16.04.5
All the machines (2 shards, 1 config server, and 1 front-end) are located in the same network, and successfully connect with each other.

Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017'

.> mongo
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
2018-06-26T17:37:13.313+0530 I NETWORK [thread1] Socket recv() An established connection was aborted by the software in your host machine. 127.0.0.1:27017
2018-06-26T17:37:13.313+0530 I NETWORK [thread1] SocketException: remote: (NONE):0 error: SocketException socket exception [RECV_ERROR] server [127.0.0.1:27017]
2018-06-26T17:37:13.313+0530 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
This problem can happen when trying to connect to a database which requires SSL.
This error is usually caused by attempting to connect without SSL to a MongoDB server that requires it. Use the following command to connect:
mongo --ssl --username "$USERNAME" --password "$PASSWORD" --host "$HOST" --port "$PORT"
See Mongod logs to find the root cause. For me it was leaking connections from one of the clients, this is what I found in logs:
NETWORK [listener] connection refused because too many open connections:
(SSL causing the issue)
You can connect with it using this command :
mongo --host 127.0.0.1:27017 --tls --username fake --password fakepassword --authenticationDatabase admin --sslAllowInvalidHostnames
Disables the validation of the hostnames in TLS/SSL certificates.
Allows mongo to connect to MongoDB instances even if the hostname in
their certificates do not match the specified hostname.
Deprecated since version 4.2: Use --tlsAllowInvalidHostnames instead.
WARNING :
Although available, avoid using the --sslAllowInvalidCertificates
option if possible. If the use of --sslAllowInvalidCertificates is
necessary, only use the option on systems where intrusion is not
possible.
If mongosh (and other MongoDB Tools) runs with the
--sslAllowInvalidCertificates option, mongosh (and other MongoDB Tools) will not attempt to validate the server certificates. This
creates a vulnerability to expired mongod and mongos certificates as
well as to foreign processes posing as valid mongod or mongos
instances. If you only need to disable the validation of the hostname
in the TLS/SSL certificates, see --sslAllowInvalidHostnames.
See MongoDB official Doc
just go simply on task manager and click on service
see given image below to copy the link on the URL
find MongoDB and click on open Service.
see given image below to copy the link on the url
then again find MongoDB and start stopped DB to running mode just click on green point button and you MongoDB is again started connecting.
[see given image below to copy the link on the url]
In my case , I was running several applications on other ports. The above solutions did not worked well for me .
Finally I closed all the tabs of code editor and web-app , and restarted it . Now it works fine .
Well! You can just restart the system, that will also work with least hassle.
As stated, this can happen because the server requires TLS in the connection. You will see the reason in server logs.
For someone who ends here without knowing how to fix it (like me) it's worth noting how to connect to those servers:
In command line you can use the --tls option (https://docs.mongodb.com/manual/tutorial/configure-ssl-clients/)
mongo --tls [other params and/or connection string]
If using a connection string alone, you can add tls=true param:
mongo://[user]:[pass]#[host]/[db]?tls=true[&others]
I was getting error in the mongod logs that read
WiredTiger metadata corruption detected
To fix the error I did the following:
As per suggestion here I ran command mongod --dbpath /data/db --repair.
The logs from command above complained that my version of mongod was too recent (I was on 4.2.x) and I had to try on mongod 4.2 or earlier.
Downgraded to mongod 4.2
Ran command mongod --dbpath /data/db --repair again, and this fixed issue.
I do run mongod inside Docker, so I had to take an extra step to find out path of the mongo DB file, docker inspect <id of mongod container>, and grab the path from the HostConfig.Binds[0] property of the resulting JSON, and stick that in the --dbpath option of the repair command mongod --dbpath /data/db --repair
In my case it is net.maxIncomingConnections: 10 in the config file and MongoDB Compass.
All available connection slots the server has, are consumed by other clients and that causes new connection requests to just drop.
I was not aware that Compass would open so many connections. When I closed it, my problem was solved.
The default connection limit is 65536 as stated in config options
I don't know why this happens but sometimes my mongo instance fails to start properly. Just shutting it down and restarting it worked for me.

Unable to connect specific mongo instance port

Today morning i'm able to create 2 different mongo instances on port 27010 and 37010 and i'm able to replicate using mongo-connector. But now after system restart i'm not able to connect to port 37010 using below command.
C:\Program Files\MongoDB 2.6 Standard\bin>mongo --port 37010
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:37010/test
2016-09-12T18:08:14.733-0500 warning: Failed to connect to 127.0.0.1:37010, reason: errno:10061 No connection could be made because the target machine actively refused it.
2016-09-12T18:08:14.756-0500 Error: couldn't connect to server 127.0.0.1:37010 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed
It is working fine if i just give mongo where it is connecting only to default port of 27010. Morning also i faced same problem where i deleted all my mongo windows service and running without mongo windows service. But again i'm facing same problem. Kindly advise.
Below is my config files.
mongo.config.txt
##store data here
dbpath=C:\Program Files\MongoDB 2.6 Standard\data
##all output go here
logpath=C:\Program Files\MongoDB 2.6 Standard\log\mongo.log
logappend=true
#port number
port=27017
##log read and write operations
diaglog=3
#replica set name
replSet=rs1
# only run on localhost for development
bind_ip = 127.0.0.1
mongo2.config.txt
##store data here
dbpath=C:\Program Files\MongoDB 2.6 Standard\data2
##all output go here
logpath=C:\Program Files\MongoDB 2.6 Standard\log2\mongo.log
logappend=true
#port number
port=37017
##log read and write operations
diaglog=3
#replica set name
replSet=rs2
# only run on localhost for development
bind_ip = 127.0.0.1
I got answer to my problem by following the steps mentioned in below blog.
http://zdk.github.io/create-a-three-member-mongodb-replica-set
Somehow it didn't work for me with configuration file. But I resolved my problem by executing commands in command line .

Mongo DB is started, but it doesn't work

I have 2 servers: One Ubuntu Server and a debian Server. I've installed Mongo DB and mongod will start, but when I try the command "mongo", I get the follow message:
MongoDB shell version: 2.4.9
connecting to: test
Tue Jun 28 19:01:21.922 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
I start the MongoDB with this command:
clouduser#caridio-ubuntu-2:~$ sudo service mongodb start
sudo: unable to resolve host caridio-ubuntu-2
mongodb start/running, process 18555
I tried to set an other dbpath and to install an older version of MongoDB. I set up differnt servers. MQTT and Tomcat works both.
Here my config:
it's an answer from 2 years ago
bindIP = [127.0.0.1,141.28.102.148]
so try to add your ips inside the [ ]
if you don't have others interface you can use bindIP = 0.0.0.0
source https://stackoverflow.com/a/34698336/6523542
maybe duplicate of ?? mongodb.conf bind_ip = 127.0.0.1 does not work but 0.0.0.0 works

MongoDB connect error [duplicate]

I've recently installed mongodb on my CentOS 6 VM running on Vagrant.
I added port forwarding to Vagrantfile to forward the mongo port
config.vm.forward_port 27017, 127017
I configured mongod to start automatically when the server starts and have confirmed that the service starts as intended.
however when i run mongo localhost:127017 from my host machine (not vagrant) i get the following error
MongoDB shell version: 1.8.2
connecting to: localhost:127017/test
Fri Jan 20 13:58:28 getaddrinfo("127.0.0.1") failed: nodename nor servname provided, or not known
Fri Jan 20 13:58:28 Error shell/mongo.js:81
exception: connect failed
any ideas?
You will need to set the mongod bind_ip to 0.0.0.0 instead of 127.0.0.1 (which is the loopback address) so that all interfaces can access it.
TCP port numbers are 16-bit unsigned, which mean the max value is 65535 (2^16), and you're trying with 127017.
Can you connect to the mongo server from vagrant ssh? If not, you might want to make sure that mongod is running.
Do you have an ip_bind set up in your mongodb.conf or mongod startup script? (If you do, you might want to unset it--not exactly sure how vagrant's port forwarding works, but this might be what's causing the problem.)
bind_ip to 0.0.0.0 does not work. Try bind_ip=127.0.0.1,10.0.0.25, that worked for me.