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 2: Create a Cluster Instance
Step 3: Connect to a Cluster Instance
Step 1: Create an ECS
- Log in to the management console.
- Under Compute, select Elastic Cloud Server. On the Elastic Cloud Server page displayed, click Buy ECS.
- 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
- 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
- Configure the ECS password and click Next: Confirm.
Figure 4 Advanced settings
- Confirm the configurations and click Submit.
Figure 5 Confirming the configurations
- View the purchased ECS.
Figure 6 Purchase succeeded
Step 2: Create a Cluster Instance
- Log in to the management console.
- Choose Databases > Document Database Service. On the displayed page, click Buy DB Instance.
- On the displayed page, click Custom Config.
- 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
- View the purchased DDS instance.
Figure 11 Purchase succeeded
Step 3: Connect to a Cluster Instance
- 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
- Enter the password of the ECS.
Figure 13 Entering the password
Figure 14 Successful login
- Download the mongodb-linux-x86_64-rhel70-4.0.27.tgz client installation package.
Figure 15 Downloading the client
- Upload the client installation package to the ECS.
Figure 16 Uploading the client package
Figure 17 Package uploaded
- Decompress the installation package on the ECS.
- 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
- 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.
- 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
- Create a database and a collection.
Figure 19 Creating a database
Figure 20 Creating a collection
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.