If an ECS instance and an ApsaraDB for MongoDB instance do not belong to the same Alibaba Cloud account, you can use the methods in this topic to connect the ECS instance to the ApsaraDB for MongoDB instance over an internal network.
Method 1: Migrate the ApsaraDB for MongoDB instance to the Alibaba Cloud account to which the ECS instance belongs
This method uses the data migration feature of Data Transmission Service (DTS) to migrate the ApsaraDB for MongoDB database to the Alibaba Cloud account to which the ECS instance belongs.
Procedure
- Create an ApsaraDB for MongoDB instance in the Alibaba Cloud account to which the
ECS instance belongs. For more information, see Create a replica set instance. Skip this step if you have created an ApsaraDB for MongoDB instance.
Note When you create the ApsaraDB for MongoDB instance, select the same region, zone, and VPC as the ECS instance.
- Migrate the MongoDB database from the instance that belongs to the source Alibaba Cloud account to the instance that belongs to the destination Alibaba Cloud account. For more information, see Migrate data between ApsaraDB for MongoDB instances created by different Alibaba Cloud accounts.
- 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 or an ECS security group for an ApsaraDB for MongoDB instance.
Note For information about how to obtain the IP address of an ECS instance, see How do I query IP addresses of ECS instances?
Method 2: Migrate the ECS instance to the Alibaba Cloud account to which the ApsaraDB for MongoDB instance belongs
This method migrates the ECS instance to the Alibaba Cloud account to which the ApsaraDB for MongoDB instance belongs by sharing the ECS instance as a custom image.
Prerequisites
The ECS instance and ApsaraDB for MongoDB instance are in the same region. Images cannot be shared across regions.
Procedure
- Create a custom image from the ECS instance.
- Share the custom image to the Alibaba Cloud account to which the ApsaraDB for MongoDB instance belongs. For more information, see Share or unshare custom images.
- Create an ECS instance from the custom image.
Note When you create the ECS instance, select the same VPC as the ApsaraDB for MongoDB instance.
- 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 or an ECS security group for an ApsaraDB for MongoDB instance.
Note For information about how to obtain the IP address of an ECS instance, see How do I query IP addresses of ECS instances?
Method 3: Establish a connection between the ECS instance and ApsaraDB for MongoDB instance by using Cloud Enterprise Network
Procedure
- Switch the network type of the ApsaraDB for MongoDB instance to VPC. For more information, see Switch the network type of an ApsaraDB for MongoDB instance. If the network type is VPC, skip this step.
- Switch the network type of the ECS instance to VPC. For more information, see Migrate ECS instances. If the network type is VPC, skip this step.
- Based on the running environment, select one of the following CEN-based connections over an internal network. For more information, see
- 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 or an ECS security group for an ApsaraDB for MongoDB instance.
Note For information about how to obtain the IP address of an ECS instance, see How do I query IP addresses of ECS instances?