mongodb keyFile between replicas throws Permission denied - mongodb

I have a single node ReplicaSet with auth activated, a root user and a keyFile I've created with this tutorial, I also have two more mongod processes in the same server in different ports (37017 and 47017) and the same replSet name, but when I try to add the secondaries in the mongo shell connected to PRIMARY with rs.add("172.31.48.41:37017") I get:
{
"ok" : 0,
"errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: 172.31.48.41:27017; the following nodes did not respond affirmatively: 172.31.48.41:37017 failed with Failed attempt to connect to 172.31.48.41:37017; couldn't connect to server 172.31.48.41:37017 (172.31.48.41), connection attempt failed",
"code" : 74
}
Then I went to the mongod process log of the PRIMARY and found out this:
2015-05-19T20:53:59.848-0400 I REPL [conn51] replSetReconfig admin command received from client
2015-05-19T20:53:59.848-0400 W NETWORK [conn51] Failed to connect to 172.31.48.41:37017, reason: errno:13 Permission denied
2015-05-19T20:53:59.848-0400 I REPL [conn51] replSetReconfig config object with 2 members parses ok
2015-05-19T20:53:59.849-0400 W NETWORK [ReplExecNetThread-0] Failed to connect to 172.31.48.41:37017, reason: errno:13 Permission denied
2015-05-19T20:53:59.849-0400 W REPL [ReplicationExecutor] Failed to complete heartbeat request to 172.31.48.41:37017; Location18915 Failed attempt to connect to 172.31.48.41:37017; couldn't connect to server 172.31.48.41:37017 (172.31.48.41), connection attempt failed
2015-05-19T20:53:59.849-0400 E REPL [conn51] replSetReconfig failed; NodeNotFound Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: 172.31.48.41:27017; the following nodes did not respond affirmatively: 172.31.48.41:37017 failed with Failed attempt to connect to 172.31.48.41:37017; couldn't connect to server 172.31.48.41:37017 (172.31.48.41), connection attempt failed
And the log of the mongod that should become SECONDARY shows nothing, the last two lines are:
2015-05-19T20:48:36.584-0400 I REPL [initandlisten] Did not find local replica set configuration document at startup; NoMatchingDocument Did not find replica set configuration document in local.system.replset
2015-05-19T20:48:36.591-0400 I NETWORK [initandlisten] waiting for connections on port 37017
It's clear that I cannot rs.initiate() in this node because it will self vote to be PRIMARY and that would create a conflict, so the line that states "Did not find local replica set configuration document at startup" is to be ignores as far as I know.
So I would think that the permission should be ok since I'm using the same key file in every mongod process and the replSet is the same in every config file, and that's all the tutorial states to be needed, but obviously something is missing.
Any ideas? Is this a bug?

If you are using ec2 instances and ip 27017 port in security group for both instances, just add a secondary instance port. It worked for me.

Related

sudo mongod --dbpath /Users/apple/development/mongodb/data/db when i run this im getting and error that premission denied in mac

connecting to: mongodb://ac-impfze5-shard-00-01.wygb8zb.mongodb.net:27017,ac-impfze5-shard-00-02.wygb8zb.mongodb.net:27017,ac-impfze5-shard-00-00.wygb8zb.mongodb.net:27017/myFirstDatabase?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=atlas-x9mb3l-shard-0&ssl=true
{"t":{"$date":"2023-02-10T20:59:39.312Z"},"s":"I", "c":"NETWORK", "id":5490002, "ctx":"thread1","msg":"Started a new thread for the timer service"}
*** You have failed to connect to a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.
Error: can't connect to new replica set master [ac-impfze5-shard-00-01.wygb8zb.mongodb.net:27017], err: AuthenticationFailed: bad auth : authentication failed :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1

Couldnt connect to mongo atlas from the mongo shell, mongo compass and go mgo Driver

I'm trying to connect mongo shell with my mongo atlas M0 cluster and ending up getting this error
Error Message
Solution I tried which didnt work:
I upgraded the monog version to 4.2 to be insync with mongo version in
atlas, didnt solve the problem getting this error mongo
"mongodb://cluster0-shard-00-02.79t7i.azure.mongodb.net:27017,cluster0-shard-00-00.79t7i.azure.mongodb.net:27017,cluster0-shard-00-01.79t7i.azure.mongodb.net:27017/testdatabase?tls=true"
MongoDB shell version v4.2.8 connecting to:
mongodb://cluster0-shard-00-02.79t7i.azure.mongodb.net:27017,cluster0-shard-00-00.79t7i.azure.mongodb.net:27017,cluster0-shard-00-01.79t7i.azure.mongodb.net:27017/testdatabase?compressors=disabled&gssapiServiceName=mongodb&tls=true
*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.
2020-08-16T00:14:57.693+0545 E QUERY [js] Error: couldn't connect
to server cluster0-shard-00-01.79t7i.azure.mongodb.net:27017,
connection attempt failed: HostUnreachable: Connection reset by peer :
connect#src/mongo/shell/mongo.js:341:17 #(connect):2:6
2020-08-16T00:14:57.695+0545 F - [main] exception: connect
failed 2020-08-16T00:14:57.695+0545 E - [main] exiting with
code 1
On trying with mgo go driver i'm getting the error as:
time="2020-08-17T15:32:32+05:45" level=debug msg="mongo host and port
:
mongodb://cluster0-shard-00-00.akidp.azure.mongodb.net:27017,cluster0-shard-00-01.akidp.azure.mongodb.net:27017,cluster0-shard-00-02.akidp.azure.mongodb.net:27017"
time="2020-08-17T15:33:32+05:45" level=error msg="Unable to connect to
mongo no reachable servers" panic: runtime error: invalid memory
address or nil pointer dereference [signal SIGSEGV: segmentation
violation code=0x1 addr=0x0 pc=0x8f3a02]
goroutine 1 [running]: gopkg.in/mgo%2ev2.(*Session).Copy(0x0,
0x7fbebca1b008)
/home/sgupta/go/pkg/mod/gopkg.in/mgo.v2#v2.0.0-20180705113604-9856a29383ce/session.go:1593
+0x22 github.optum.com/claredi/oti.git/ds.Copy(0xc001ae3a30, 0x0, 0x0) /home/sgupta/go/src/github.optum.com/claredi/oti.git/ds/ds.go:166
+0x3c github.optum.com/claredi/oti.git/ds/announcements.indexes() /home/sgupta/go/src/github.optum.com/claredi/oti.git/ds/announcements/announcements.go:47
+0xff github.optum.com/claredi/oti.git/ds.Init(0xc0000f8000, 0xc0001efe68)
/home/sgupta/go/src/github.optum.com/claredi/oti.git/ds/ds.go:98
+0x52e main.startAPIServer(0x0, 0xc000098360) /home/sgupta/go/src/github.optum.com/claredi/oti.git/api/main.go:83
+0xe98 main.main() /home/sgupta/go/src/github.optum.com/claredi/oti.git/api/main.go:26
+0x4d exit status 2
Hoping to get a resolution from the experts. Thanks in Advance :)
First, in Atlas:
Ensure the cluster itself looks healthy in "Clusters"
Go to "Network Access" and ensure your IP is allowed
Just to be safe, go to "Database Access" and create a new user with proper permissions
If your problem is similar to Cannot connect to mongodb atlas through mongo shell, it might be that your IP changed or something, and you need to allow your current IP.

MongoDB secondary replica set sync failure with Primary (in the reporting replica)

In the mongoDB secondary replica (reporting) I am getting the sync failure and also below error messages after 30 Hrs of the traffic run.
2020-07-15T01:50:29.987+0000 W EXECUTOR [conn408277] Terminating session due to error: InternalError: failed to create service entry worker thread
2020-07-15T01:50:31.656+0000 I - [listener] pthread_create failed: Resource temporarily unavailable
Can anyone help on how to debug & fix the issue please

Mongodb 3.4 - fail to start mongodb

How can I start mongodb. The child process fail.
-bash-4.1$ mongod --config /mongodb/etc/mongod-ctr.conf
about to fork child process, waiting until server is ready for connections.
forked process: 22965
ERROR: child process failed, exited with error number 48
-bash-4.1$ mongo
MongoDB shell version v3.4.17
connecting to: mongodb://127.0.0.1:27017
2018-11-27T13:52:13.826-0500 W NETWORK [thread1] Failed to
connect to 127.0.0.1:27017, in(checking socket for error after
poll), reason: Connection refused
According to the MongoDB error code manual, and your error status, there seems to be another process either running on port 27017, or you just don't have the right permissions.
You can use the command lsof -i -P -n to see a list of all applications, and the ports they are using.

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.