opsmanager application not able to connect to opsmanager database - mongodb

I have installed opsmanager database in one instance and application in other instance
Taken points from this link
In application database server when i netstat -nltp it shows 127.0.0.1:27017 running mongod
After installing application in other instance I edit the mongo.mongoUri as mongodb://db_instance_publicip:27017 in /opt/mongodb/mms/conf/conf-mms.properties
When I start by sudo service mongodb-mms start is shows below error
uri=mongodb://db_instance_publicip:27017/?maxPoolSize=150} Error: Timed out after 30000 ms while waiting to connect.......
Error: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=db_instance_publicip:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]

Was facing the same issue. The issue in my case was that my Mongo DB was binding to only localhost thanks to this line in /etc/mongod.conf:
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
As the commented part in the same line suggests, I had to replace "127.0.0.1" with "0.0.0.0" and restart Mongo DB and it started working!

Related

Mongo db - connection exception from another container in Docker

In Jenkins I am trying to run in docker container my backend services, which are dependant on Mongo DB.
Currently I have it like this:
stage('Backend clone and build') {
steps { git ([url : 'https://github...', branch : 'develop', credentialsId : '***'])
sh 'docker pull mongo'
sh 'docker run -d -p 27017:27017 --name mongodb mongo'
sh 'docker build -t myimage2 .'
sh 'docker run myimage2'
}
}
After I run the build, I have this exception:
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-4.1.2.jar!/:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:143) ~[mongodb-driver-core-4.1.2.jar!/:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.1.2.jar!/:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.1.2.jar!/:na]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
I tried to link the container with mongodb container as : sh 'docker run --link mongodb:27017 myimage2', but no success.
I was also thinking to define the host via mongodb://localhost:27017 but this command is not accepted in docker. I did not find any solution how to get rid of that exception.
If I dive deeper to that exception, I also found there this:
Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect.
So for some reason it is not able to connect to localhost:27017 where the mongodb should be running.
To help others who may have this same problem, you have 2 options to set up correctly:
Create a docker network and start all the containers on this network so that the containers can discover each other, the default is the bridge network type. In this case, the containers are isolated from the host networking interface and can't be accessed via "localhost".
If you want the containers to run on the host network and be accessible via the host network interface aka localhost or a host IP, do as docker suggests in it's official docs here: https://docs.docker.com/network/host/

Can't connect to MongoDB running in docker container

I run MongoDB in a docker container like this
docker run --name mongo -d -p 27017:27107 mongo
Check with docker ps shows
77f1a11295c3 mongo "docker-entrypoint.s…" 20 minutes ago Up 20 minutes 27017/tcp, 0.0.0.0:27017->27107/tcp mongo
so it's running with the port mapped correctly.
When I try to setup a connection via Intellij
it fails with
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Exception receiving message}, caused by {java.net.SocketException: Connection reset}}].
When I try to connect to connect from a golang web server
clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
client, err := mongo.Connect(context.TODO(), clientOptions)
I get this error and it shuts down the web server:
server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, Average RTT: 0, Last error: connection() error occured during connection handshake: connection(localhost:27017[-64]) incomplete read of message header: read tcp 127.0.0.1:40700->127.0.0.1:27017: read: connection reset by peer }, ] }
Is this a bug in the MongoDB docker image, or is there something else I need to do?
I think you have a typo mistake while creating a container. 27017 and 27107
docker run --name mongo -d -p 27017:27017 mongo
This is clearly visible in docker ps command.
Can you try and see if it solves the problem ?
As #fly2matrix said you have a typo, and I believe you have another issue:
you forward the ports 27017:27107, in which the container port is incorrect. Check 27107 instead of 27017
It seems you're connecting to localhost instead of mongo as I see the phrase localhost in your code.

Can't connect to mLab database

I'm trying to connect to my mongodb database from URI that is hosted on mLab, but I couldn't, this error is displayed:
Connection failed.
SERVER [ds121090-a0.mlab.com:19490] (Type: UNKNOWN)
__/ Connection error (MongoSocketOpenException): Exception opening socket
|____/ I/O error: connect timed out
Details:
Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=ds132132190-a0.mlab.com:19490, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]
mongodb://user:xxxxx#ds132132190.mlab.com:19490/mydb
My localhost db works fine.
What's wrong with my server db?

getting an error while connecting mongodb with replicaset-Bitnami

I have deployed bitnami MongoDB with replicaset on Azure and I haven't changed anything but when I try to connect MongoDB using connection string then I'm getting an error like `
Connection failed.
SERVER [xyz.southeastasia.cloudapp.azure.com:27017] (Type: UNKNOWN)
|_/ Connection error (MongoSocketReadTimeoutException): Timeout while receiving message
|____/ I/O error: Read timed out
Details:
Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=xyz.southeastasia.cloudapp.azure.com:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message}, caused by {java.net.SocketTimeoutException: Read timed out}}]
I have running bitnami mongodb with replicaset on azure which was created one month back that time i haven't faced this issue.
It looks to me that the address may have changed. I advise you to confirm that xyz.southeastasia.cloudapp.azure.com still points to the same IP address you want to connect. Also check that there are no firewall rules blocking the traffic.

Shutdown mongos for upgrade

I am upgrading a mongo sharded cluster, and am in the first step of replacing the mongos process. Can I just kill this process or is there a safer way to shut it down before replacing it?
It is the answer. But may be you misunderstood. You cannot shutdown mongos from command line, but you have to logon to the shell. Here is the result I am trying on my own:
$ mongo --port 27077 (please replace with your own port on mongos instance)
**mongos**> db.shutdownServer({timeoutSecs:30})
shutdown command only works with the admin database; try 'use admin'
mongos> use admin
switched to db admin
mongos> db.shutdownServer({timeoutSecs:30})
2015-02-27T12:53:54.408+0800 DBClientCursor::init call() failed
**server should be down...**
2015-02-27T12:53:54.410+0800 trying reconnect to 127.0.0.1:27077 (127.0.0.1) failed
2015-02-27T12:53:54.410+0800 warning: Failed to connect to 127.0.0.1:27077, reason: errno:111 Connection refused
2015-02-27T12:53:54.410+0800 reconnect 127.0.0.1:27077 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27077 (127.0.0.1), connection attempt failed
2015-02-27T12:53:54.413+0800 trying reconnect to 127.0.0.1:27077 (127.0.0.1) failed
2015-02-27T12:53:54.413+0800 warning: Failed to connect to 127.0.0.1:27077, reason: errno:111 Connection refused
2015-02-27T12:53:54.413+0800 reconnect 127.0.0.1:27077 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27077 (127.0.0.1), connection attempt failed
>
Try to run "top" or "htop" to display all processes running on your computer. You shall see the "mongos" process has gone. Read the log file. Here is the last two lines of my log:
2015-02-27T12:53:54.406+0800 [conn1] terminating, shutdown command received
2015-02-27T12:53:54.406+0800 [conn1] dbexit: shutdown called rc:0 shutdown called
And here is the link of my testing script:
https://github.com/babycaseny/QuickStart/blob/master/StartShard.sh
Note that you have to replace the "localhost" in the mongod/mongos command with the hostname of your computer, or you will not be able to config your shards.
See also this one:
https://groups.google.com/forum/#!topic/mongodb-user/TQLlRI6HG1M
In case you need a command line to do the work, here is one:
mongo admin --port portnumber --eval "db.shutdownServer()"
Notice that you have to run the command in localhost.