Updated on 2022-09-20 GMT+08:00

Connecting to an Instance from an ECS

This section uses the Linux OS as an example to describe how to purchase and connect to a cluster instance over a private network.

Step 1: Create an ECS

Step 2: Create a Cluster Instance

Step 3: Connect to a Cluster Instance

Step 1: Create an ECS

  1. Log in to the management console.
  2. Under Compute, select Elastic Cloud Server. On the Elastic Cloud Server page displayed, click Buy ECS.
  3. Configure basic settings and click Next: Configure Network. The region and AZ of the ECS are the same as those of the cluster instance to be connected.
    Figure 1 Basic configurations
    Figure 2 Selecting an image
  4. Configure the ECS network information and click Next: Configure Advanced Settings. The VPC and security group of the ECS are the same as those of the cluster instance to be connected.
    Figure 3 Network settings
  5. Configure the ECS password and click Next: Confirm.
    Figure 4 Advanced settings
  6. Confirm the configurations and click Submit.
    Figure 5 Confirming the configurations
  7. View the purchased ECS.
    Figure 6 Purchase succeeded

Step 2: Create a Cluster Instance

  1. Log in to the management console.
  2. Choose Databases > Document Database Service. On the displayed page, click Buy DB Instance.
  3. On the displayed page, click Custom Config.
  4. Configure the instance information and click Submit. The region, AZ, VPC, and security group of the ECS are the same as those of the cluster instance to be connected.
    Figure 7 Basic configurations
    Figure 8 Administrator settings
    Figure 9 Network and required duration
    Figure 10 Advanced settings
  5. View the purchased DDS instance.
    Figure 11 Purchase succeeded

Step 3: Connect to a Cluster Instance

  1. Use the Linux remote connection tool to log in to the ECS. Remote host is the EIP bound to the ECS.
    Figure 12 Creating a session
  2. Enter the password of the ECS.
    Figure 13 Entering the password
    Figure 14 Successful login
  3. Download the mongodb-linux-x86_64-rhel70-4.0.27.tgz client installation package.
    Figure 15 Downloading the client
  4. Upload the client installation package to the ECS.
    Figure 16 Uploading the client package
    Figure 17 Package uploaded
  5. Decompress the installation package on the ECS.

    tar zxvf mongodb-linux-x86_64-rhel70-4.0.27.tgz

  6. Obtain the client tool from the bin directory of the installation package.

    cd mongodb-linux-x86_64-rhel70-4.0.27/bin

    The common tools are as follows:

    • MongoDB client mongo
    • Data export tool mongoexport
    • Data import tool mongoimport
  7. Before using a client tool, assign the execute permission to it.
    • Run the chmod +x mongo command to grant a client permission to connect to a DB instance.
    • Run the chmod +x mongoexport command to grant a client permission to export data.
    • Run the chmod +x mongoimport command to grant a client permission to import data.
  8. Connect to the DDS instance.

    ./mongo mongodb://rwuser:<password>@<DB_HOST1>:<DB_PORT1>,<DB_HOST2>:<DB_PORT2>/test?authSource=admin

    <password> is the password for the database username. Replace it with the actual password.

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

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

    Figure 18 Connection succeeded
  9. Create a database and a collection.
    Figure 19 Creating a database
    Figure 20 Creating a collection