If the ECS instance is in a classic network and the ApsaraDB for MongoDB instance is in a VPC, or the MongoDB instance is in a classic network and the ECS instance is in a VPC, you can use the methods described in this topic to quickly connect the ECS instance to the ApsaraDB for MongoDB instance.

Prerequisites

  • The ECS instance and ApsaraDB for MongoDB instance belong to the same Alibaba Cloud account and are in the same region.
  • You also need to add the private IP address of the ECS instance to the whitelist of the ApsaraDB for MongoDB instance. For more information, see Configure a whitelist.
    Note For more information about how to obtain the IP address of an ECS instance, see How to query the IP address of an ECS instance.

Connect an ECS instance in a classic network to an ApsaraDB for MongoDB instance in a VPC

Connect an ECS instance in a classic network to an ApsaraDB for MongoDB instance in a VPC

You can connect an ECS instance in a classic network to an ApsaraDB for MongoDB instance in a VPC by using the following methods:

  • Migrate the ECS instance to the VPC to which the ApsaraDB for MongoDB instance belongs. For more information, see Migrate an ECS instance to a VPC.
  • Change the network type of the ApsaraDB for MongoDB instance to classic network. For more information, see Switch from a VPC to a classic network.
  • Use ClassicLink.
    Note The ClassicLink-based interconnection is a temporary solution in special conditions. To achieve high-speed connection in the production environment, we recommend that you create the ECS and ApsaraDB for MongoDB instances in the same VPC.

    Before you create a ClassicLink connection, make sure that you understand the limits of ClassicLink. For more information, see ClassicLink.

    To enable ClassicLink, perform the following steps:

    1. Log on to the VPC console.
    2. Select the region of the VPC and click the ID of the VPC.
    3. On the VPC Details page, click Enable ClassicLink. In the dialog box that appears, click OK.
    4. Log on to the ECS console.
    5. In the left-side navigation pane, click Instances.
    6. In the upper-left corner of the page, select the region where the instance resides.
    7. In the Operation column corresponding to the ECS instance in a classic network, choose More > Network and Security Group > Set classic link.
    8. In the dialog box that appears, select the VPC to which the ApsaraDB for MongoDB instance belongs and click OK.
    9. In the Connect to VPC dialog box that appears, click Go to the instance security group list and add ClassicLink rules.
    10. Click Add ClassicLink Rule. Configure the following parameters and then click OK.
      Parameter Description
      Classic Security Group The name of the classic network security group.
      Select VPC Security Group Select a VPC security group.
      Mode Select an authorization mode.
      • Classic <=> VPC: allows ECS instances in a VPC and cloud resources in a classic network to access each other. We recommend that you select this mode.
      • Classic => VPC: allows ECS instances in a classic network to access cloud resources in a VPC.
      • VPC => Classic: allows cloud resources in a VPC to access ECS instances in a classic network.
      Protocol Select a communication protocol.
      Port Range Specify the port range in the format of xx/xx. The port used here is port 3717 for MongoDB instances. Enter 3717/3717.
      Priority The priority of the rule. The smaller the value, the higher the priority.
      Description The description of the security group. It must be 2 to 256 characters in length and cannot start with http:// or https://.

Connect an ECS instance in a VPC to an ApsaraDB for MongoDB instance in a classic network

Connect an ECS instance in a VPC to an ApsaraDB for MongoDB instance in a classic network

Switch the network type of the ApsaraDB for MongoDB instance to the VPC to which the ECS instance belongs. For more information, see Switch from a classic network to a VPC.

Note
  • You cannot change the network type of standalone instances.
  • Switching network types will cause a transient disconnection of the ApsaraDB for MongoDB instance. Perform this operation during off-peak hours or ensure that your application has a reconnection mechanism to prevent negative impacts on your business.