Through intranet penetration, Windows can remotely connect to MongoDB database without public network IP.

Preface

MongoDB is a database based on distributed file storage. Written in C++ language. Designed to provide scalable, high-performance data storage solutions for WEB applications.

MongoDB is a product between a relational database and a non-relational database. It is the most feature-rich among non-relational databases and is most like a relational database. The data structure it supports is very loose and is a bson format similar to json, so it can store more complex data types. The biggest feature of Mongo is that the query language it supports is very powerful. Its syntax is somewhat similar to an object-oriented query language. It can almost implement most functions similar to single-table queries in relational databases, and it also supports indexing of data.

Implement remote access to MongoDB in a few simple steps.

1. Install the database

Open the MongoDB official websitehttps://www.mongodb.com/try/download/community, here we take the windows version as an example.

20230220114401

After downloading, double-click to install. At this step of installation, you must click complate to set the account password.

20230220114402

After entering, you can set a password and click next, or click next to install directly.

20230220114403

After installation, we use the connection tool to test the connection. Here we use navicat to connect.

20230220114404

2. Intranet penetration

After the local connection is OK, the database can only be accessed within the LAN at present. However, we can use the cpolar intranet penetration tool to map the MongoDB database on the intranet to the public network to achieve remote access without the need for a public network IP. No need to set up a router.

2.1 Install cpolar intranet penetration

Enter the cpolar official website download page, download the windows installation package locally and then unzip it and install it by default.

cpolar官网:https://www.cpolar.com/

20230220114405

2.2 Create tunnel mapping

After cpolar is installed successfully, double-click to open cpolar [or access the local 9200 port on the browser: 127.0.0.1:9200], use the cpolar email account to log in to the web UI management interface, if you have not registered a cpolar account, click Free Registration, and it will jump Just go to the cpolar official website to register an account.

20230220114406

After successfully logging in, click Tunnel Management - Create Tunnel on the left dashboard to create a TCP protocol tunnel pointing to the local port 27017:

  • Tunnel name: It can be customized. Be careful not to duplicate the existing tunnel name.
  • Protocol: tcp
  • Local address: 27017
  • Domain name type: Choose a random domain name for free
  • Region: Default is China top

Click Create

20230220114407

After the tunnel is successfully created, click Status on the left - Online Tunnel List. You can see that the tunnel just created has generated a corresponding public network address. Copy it.

20230220114408

2.3 Test remote connection with random public network address

Open navicat, enter the tcp public network address: 3.tcp.cpolar.top port number 11249, then click Test Connection, and the connection is successful.

20230220114409

3. Configure a fixed TCP port address

Since the tunnel created above is a random address tunnel, the address will change within 24 hours. In order to make the connection more stable, we can configure a fixed TCP connection address for it.

It should be noted that configuring a fixed TCP port address requires upgrading cpolar to the Professional Edition package or above.

3.1 Reserve a fixed public network TCP port address

Log in to the cpolar official website, click Reserve on the left, and select the reserved TCP address. Let's first reserve a fixed port address for remote MongoDB.

  • Region: Select China VIP
  • Description: Notes, which can be customized

Click to keep

20230220114411

After the address is successfully reserved, the system will generate the corresponding fixed public address and copy it.
20230220114412

3.2 Configure a fixed public network TCP port address

Access port 9200 on the browser,http://127.0.0.1:9200/, log in to the cpolar web ui management interface, click Tunnel management on the left dashboard - Tunnel list, find the MongoDB tunnel, click Edit on the right

20230220114413

Modify the tunnel information and configure the successfully reserved fixed TCP address into the tunnel:

  • Port type: modified to fixed tcp port
  • Reserved tcp address: fill in the successfully reserved address

Click to update

20230220114414

After the tunnel is successfully updated, click the status on the left dashboard - Online Tunnel List, find the tunnel that needs to be edited, and you can see that the public network address has been updated to a fixed TCP address.

20230220114415

3.3 Test fixed address public network remote access

Test remote MongoDB using a fixed TCP port address, open navicat again, and connect using a fixed TCP address

20230220114416

Guess you like

Origin blog.csdn.net/qq_72916130/article/details/134122333
Recommended