Maverick
Maverick

Reputation: 1187

mongodump error "Failed: can't create session: could not connect to server:"

I can successfully connect with my mongodb locally with self-signed certificates. Security authorization is set to "disabled" under mongo config and TLS is enabled. Using the mongodump command locally

mongodump --ssl --authenticationDatabase admin --host=127.0.0.1 --port=27017 -u=admin -p=821ewuyuiuw3! --sslPEMKeyFile=/etc/ssl/mongodb.pem --sslCAFile=/etc/ssl/rootCA.pem --archive=/home/backups/mongodump.gz --gzip

The admin user exists despite the fact I disabled the authorization. I get the same error without the credentials also.

I always get the error :

2021-12-03T14:58:29.420+0200    Failed: can't create session: could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: 127.0.0.1:27017, Type: Unknown, Last error: connection() error occured during connection handshake: x509: cannot validate certificate for 127.0.0.1 because it doesn't contain any IP SANs }, ] }

I tried also using export GODEBUG=x509ignoreCN=0 without success. Any solution to this?

Upvotes: 3

Views: 7534

Answers (2)

SyedAsadRazaDevops
SyedAsadRazaDevops

Reputation: 387

i recently had the same issue on my server, because I change the hostname of OS, so check your hostname. in ubuntu:

sudo nano /etc/hosts

make sure it had your localhost value=127.0.0.1

OR also you can test your command by just simply define the host value

sudo mongodump --host=127.0.0.1 --port=27017 --db mydb 

Upvotes: 0

Maverick
Maverick

Reputation: 1187

I finally managed to make it work with both of the following commands. It seems that it was needed the parameter --tlsInsecure

mongodump --ssl  --host=127.0.0.1 --port=27017  --sslPEMKeyFile=/etc/ssl/mongoCer/mongodb.pem --sslCAFile=/etc/ssl/mongoCer/rootCA.pem --archive=./mongo-daily-backups/mongodump-date_2020-11-16_time_20-37-11.gz --gzip --tlsInsecure

and

mongodump --ssl  --host=127.0.0.1 --port=27017 --archive=./mongo-daily-backups/mongodump-date_2020-11-16_time_20-37-11.gz --gzip --tlsInsecure

Upvotes: 3

Related Questions