ApsaraDB for MongoDB only supports connections from an ECS instance over an internal network. To connect to an ApsaraDB for MongoDB instance from a local server over the Internet, you can install rinetd on the Linux ECS instance.

Background information

Procedure

  1. Install rinetd on the Linux ECS instance.
    wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xvf rinetd.tar.gz&&cd rinetd
    sed -i 's/65536/65535/g' rinetd.c (Change the range of port numbers.)
    mkdir /usr/man&&make&&make install
  2. Open the configuration file.
    vi /etc/rinetd.conf
  3. Add the following content to the configuration file:
    0.0.0.0 3717 Endpoint of the ApsaraDB for MongoDB instance 3717 logfile /var/log/rinetd.log
  4. Run the following command to start rinetd:
    rinetd
    Note You can run the echo rinetd >>/etc/rc.local command to set automatic startup for rinetd and run the pkill rinetd command to terminate the process.
  5. Perform a verification test.

    Connect to the Linux ECS instance from the local server by using the mongo shell. For example, the IP address of the ECS instance where rinetd is installed is 1.1.1.1.

    mongo --host 1.1.1.1:3717 -u root -p Password --authenticationDatabase admin

    Then your local server can connect to the ApsaraDB for MongoDB instance through the 3717 port of the Linux ECS instance over the Internet.

    Note rinetd is an open-source program. You can use rinetd to test connection conditions. If you have any issues when you use rinetd, see rinetd documentation or contact rinetd customer service.