Issue Description
When connecting to the DDS instance using client, the error "Authentication failed" is reported, and the connection command used is as follows:
mongo "mongodb://root:<password>@<IP1:Port1>,<IP2:Port2>/admin?authSource=admin&replicaSet=<setname>"
The error message is as follows:
2023-07-19T12:42:13.281+0800 W NETWORK [js] Unable to reach primary for set DDS 2023-07-19T12:42:13.281+0800 I NETWORK [js] Cannot reach any nodes for set DDS. Please check network connectivity and the status of the set. This has happened for 2 checks in a row. 2023-07-19T12:42:13.284+0800 E QUERY [js] Error: connect failed to replica set DDS/<IP>:<Port>,<IP>:<Port> : connect@src/mongo/shell/mongo.js:257:13 @(connect):1:6 exception: connect failed
Cause Analysis
From the error message, it seems that the network access between the client and DDS is not available.
Possible reasons:
• The port of the DDS instance is incorrect and unavailable.
• The DDS instance and the client ECS are not in the same region or subnet.
• The server has SSL mode enabled, but the client is not using SSL mode for access.
Solution
Check whether the DDS instance and ECS are in the same region, security group, and subnet. First, log in to the DDS console, click the instance name, and view the region, VPC, security group, and subnet information of the DDS instance on the Basic Information page. Then, in the ECS console, click the name of ECS and view the region, VPC, security group, and subnet information of the current ECS on the Basic Information page. Ensure that the configuration information is the same for both.
Check whether the port of the instance is correct and run the curl/telnet command to check whether the port is available. Log in to the DDS console, click the instance name, view the IP and port information for the instance on the Basic Information page, and then use the curl or telnet command to test the port connectivity.
Example:
curl check $ curl <IP>:<Port> It looks like you are trying to access MongoDB over HTTP on the native driver port. telnet check $ telnet <IP> <Port> Trying <IP>... Connected to <IP>. Escape character is '^]'. ^] telnet>
Check whether the instance has SSL mode enabled. Log in to the DDS console, click the instance name, and check whether SSL mode is enabled on the Basic Information page. If SSL mode is enabled, then use SSL mode to access after downloading the certificate, the command example is as follows:
./mongo "mongodb://root:<password>@<IP1:Port1>,<IP2:Port2>/admin?authSource=admin&replicaSet=<setName>" --ssl --sslCAFile=<certificate.path> --sslAllowInvalidHostnames