Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Connecting to a Replica Set Instance over a Private Network

Updated on 2024-08-03 GMT+08:00

If your applications are deployed on an ECS that is in the same region and VPC as your instances, you can connect to the DB instance over a private network.

This section describes how to use the MongoDB client to connect to a GeminiDB Mongo replica set instance over a private network.

The following uses a Linux ECS and a Window client as an example.

The MongoDB client can connect to an instance with an unencrypted connection or an encrypted connection (SSL). To secure data transmission, connect to your instances using SSL.

Precautions

  • The instances must be in the same VPC and subnet as the ECS.
  • The ECS must be in a security group that has access to the instances.
    • If the instance is associated with the default security group, you do not need to configure security group rules.
    • If the instance is not associated with the default security group, check whether the security group rules allow the ECS to connect to the instance.

      If yes, the ECS can connect to the instance.

      If no, add an inbound rule to the security group. For details, see Configuring Security Group Rules.

Prerequisites

  1. You have created and logged in to an ECS. For details, see Purchasing an ECS and Logging In to an ECS.
  2. You have installed the MongoDB client on the ECS.

    For details about how to install the MongoDB client, see How Can I Install a MongoDB Client?

SSL Connection

NOTICE:

If you connect to an instance over the SSL connection, enable SSL first. Otherwise, an error is reported. For details about how to enable SSL, see Configuring an SSL Connection.

  1. Log in to the management console.
  2. In the service list, choose Databases > GeminiDB Mongo API.
  3. On the Instance Management page, click the instance.
  4. In the navigation pane on the left, choose Connections.
  5. In the Basic Information area, click next to the SSL field to download the root certificate.
  6. Upload the root certificate to the ECS to be connected to the instance.

    The following describes how to upload the certificate to a Linux and a Window ECS

    • In Linux, run the following command:
      scp<IDENTITY_FILE><REMOTE_USER>@<REMOTE_ADDRESS>:<REMOTE_DIR>
      NOTE:
      • IDENTITY_FILE is the directory where the root certificate resides. The file access permission is 600.
      • REMOTE_USER is the ECS OS user.
      • REMOTE_ADDRESS is the ECS address.
      • REMOTE_DIR is the directory of the ECS to which the root certificate is uploaded.
    • In Windows, upload the root certificate using a remote connection tool.

  7. Connect to a DB instance.

    • Method 1: Use the connection address to connect to a replica set instance (recommended).

      The connection addresses provided on the GeminiDB Mongo console includes the IP addresses and ports of the primary node, standby node, and hidden node by default. You can use this connection address to connect to the primary, standby, and hidden nodes of the instance at the same time. In this way, write errors can be avoided after a primary/standby switchover.

      Example command:

      ./mongo "<Connection address>" --ssl --sslCAFile<FILE_PATH> --sslAllowInvalidHostnames

      Table 1 Parameter description

      Parameter

      Description

      <Connection address>

      Connection address of the instance to be connected.

      On the Instance Management page, click the instance to go to the Basic Information page. Obtain the private IP address on the Connections page.

      Figure 1 Obtaining the connection address

      • In the preceding command, ***** needs to be replaced with the password of the instance administrator.

        If the password contains at signs (@), exclamation marks (!), or percent signs (%), replace them with hexadecimal URL codes %40, %21, and %25 respectively.

        For example, if the password is ****@ %***!, the corresponding URL code is **** %40%25*** %21.

      • replica in replicaSet=replica is the name of a replica set. The name of GeminiDB Mongo replica set is fixed and cannot be changed.

      <FILE_PATH>

      Path for storing the root certificate.

      Example:

      ./mongo "mongodb://rwuser:****@192.168.0.252:8635,192.168.0.31:8635/test?authSource=admin&replicaSet=replica" --ssl --sslCAFile/tmp/ca.crt --sslAllowInvalidHostnames

      NOTE:
      • A replica set instance uses the management IP address to generate SSL certificate. --sslAllowInvalidHostnames is required when you connect to a replica set over a private network.
      • If you connect to an instance over a private IP address, add double quotation marks before and after the connection information.
      If the following information is displayed, the instance is successfully connected:
      replica:PRIMARY>
    • Method 2: Connect to a single node.

      Example command:

      ./mongo --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p --authenticationDatabase admin --ssl --sslCAFile<FILE_PATH> --sslAllowInvalidHostnames

      Enter the password of the database account if the following information is displayed:

      Enter password:
      Table 2 Parameter description

      Parameter

      Description

      <DB_HOST>

      Private IP address of the primary or standby node of the instance to be connected.

      Primary node: You can read and write data.

      Secondary node: You can only read data.

      On the Instance Management page, click the instance to go to the Basic Information page. On the Connections page, obtain the private IP address of the corresponding node.

      Figure 2 Obtaining the node IP address

      Alternatively, obtain the private IP address of a node in the Node Information area on the Basic Information page.

      Figure 3 Obtaining the private IP address

      <DB_PORT>

      Database port

      <DB_USER>

      Username of the instance administrator. The default value is rwuser.

      <FILE_PATH>

      Path for storing the root certificate.

      Example:

      ./mongo --host 192.168.0.31 --port 8635 -u rwuser -p --authenticationDatabase admin --ssl --sslCAFile /tmp/ca.crt --sslAllowInvalidHostnames

      If the following information is displayed, the corresponding node is successfully connected:

      • The primary node of the replica set is connected.
        replica:PRIMARY>
      • The standby node of the replica set is connected.
        replica:SECONDARY>

Non-SSL Connection

NOTICE:

If you connect to an instance over an unencrypted connection, disable SSL first. Otherwise, an error is reported. For details about how to disable SSL, see Configuring an SSL Connection.

  1. Connect to the ECS.
  2. Connect to the DB instance in the directory where the MongoDB client is located.

    • Use the connection address to connect to a replica set instance (recommended).

      The connection addresses provided on the GeminiDB Mongo console includes the IP addresses and ports of the primary node, standby node, and hidden node by default. Connecting to a replica set with this method allows access to the primary, standby, and hidden nodes at the same time, so write errors can be avoided after a primary/standby switchover.

      Example command:

      ./mongo "<Connection address>"

      Table 3 Parameter description

      Parameter

      Description

      <Connection address>

      You can obtain the connection address in either of the following ways:

      Click the instance name. On the displayed Basic Information page, the address is displayed in the Address field in the Network Information area.

      Figure 4 Obtaining the private IP address

      Alternatively, click the instance name to go to the Basic Information page. In the navigation pane on the left, choose Connections to obtain the address of the instance.

      Figure 5 Obtaining the connection address

      • In the preceding command, ***** needs to be replaced with the password of the instance administrator.

        If the password contains at signs (@),exclamation marks (!), or percent signs (%), replace them with hexadecimal URL codes %40, %21, and %25 respectively.

        For example, if the password is ****@ %***!, the corresponding URL code is **** %40%25*** %21.

      • replica in replicaSet=replica is the name of a replica set. The name of GeminiDB Mongo replica set is fixed and cannot be changed.

      Example:

      ./mongo "mongodb://rwuser:****@192.168.0.196:8635,192.168.0.67:8635,192.168.0.32:8635/test?authSource=admin&replicaSet=replica"

      If the following information is displayed, the connection is successful.
      replica:PRIMARY>
    • Connecting to a single node.

      You can also connect to the private IP address of a specified node.

      Example command:

      ./mongo --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p --authenticationDatabase admin

      Table 4 Parameter description

      Parameter

      Description

      <DB_HOST>

      Private IP address of the primary or standby node of the instance to be connected.

      • Primary node: You can read and write data.
      • Secondary node: You can only read data.

      On the Instance Management page, click the instance to go to the Basic Information page. Obtain the private IP address of the corresponding node from the node information list.

      Figure 6 Obtaining the private IP address

      Alternatively, click the target instance to go to the Basic Information page. In the navigation pane on the left, choose Connections. On the Connections page, obtain the private IP address of the node.

      Figure 7 Obtaining the connection address

      <DB_PORT>

      Database port

      <DB_USER>

      Username of the instance administrator. The default value is rwuser.

      Enter the password of the database account if the following information is displayed:

      Enter password:

      Example:

      ./mongo --host 192.168.1.6 --port 8635 -u rwuser -p --authenticationDatabase admin

      If the following information is displayed, the corresponding node is successfully connected:

      The command output for connecting to the primary node of the replica set is as follows:

      replica:PRIMARY>

      The command output for connecting to the standby node of the replica set is as follows:

      replica:SECONDARY>

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback