How to use intranet penetration tools to implement Java remote connection to the local Elasticsearch search analysis engine

Preface

In a few simple steps, combined with the Cpolar intranet penetration tool, you can implement Java remote connection to operate the local distributed search and data analysis engine Elasticsearch.

Cpolar intranet penetration provides higher security and privacy protection. By using encrypted communication channels, Cpolar technology can ensure the security of data transmission, which provides users and teams with more reliable protection, allowing them to process with confidence. and storing sensitive work content.

1. Install Cpolar on Windows

Visit the cpolar official website, register an account, and then download and install the client. For specific installation instructions, please refer to the official website documentation tutorial.

Cpolar official website: https://www.cpolar.com/download

  • Windows system: After downloading the installation package from the official website, double-click the installation package and install it by default.
  • Linux system: supports one-click automatic installation script. For details, please refer to the official website documentation - Getting Started Guide

image-20231113140709326

Note! After Cpolar is installed successfully, the default Cpolar web interface access port is also 9200, which may conflict with Elasticsearch. You need to modify the Cpolar management interface port. If the Elasticsearch port is not 9200, you do not need to modify it.

Find the cpolar configuration file: c:\Users\用户名\.cpolar\cpolar.yml, use Notepad++ editing tool or other software to open it

image-20231113140858314

In the configuration file, add a line: client_dashboard_addr: 127.0.0.1:9800, the port can be customized, use 9800 here

image-20231113141453289

After modification, remember to save the configuration file, and then restart the cpolar service in Control Panel – Management Tools – Services – cpolar service

image-20231113141414399

Then enter it in the browser localhost:9800to access the Cpolar Web UI management interface. Enter the account registered on the official website to log in.

image-20231113141644952

2. Create an Elasticsearch public network connection address

After logging in, click Tunnel Management - Create Tunnel on the left dashboard to create a 9200 http tunnel.

  • Tunnel name: You can customize the name. Be careful not to duplicate the existing tunnel name.
  • Protocol: Select http
  • Local address: https://127.0.0.1:9200 (If the local access method is https, you need to fill in the complete address)
  • Domain name type: Choose a random domain name for free
  • Region: Select China

Click创建

image-20231123162335001

After the tunnel is successfully created, click the status on the left - Online Tunnel List to view the generated public network access address. There are two access methods, one is http and https. Since the local one is https, we only need to use the https address. Can

image-20231123162509393

3. Remote connection to Elasticsearch

Import the relevant Maven dependencies. The Elasticsearch version used here is the latest version 8.11.0

<dependency>
			<groupId>co.elastic.clients</groupId>
			<artifactId>elasticsearch-java</artifactId>
			<version>8.11.1</version><!--改为自己的版本-->
		</dependency>

		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
			<version>2.12.3</version>
		</dependency>

		<dependency>
			<groupId>jakarta.json</groupId>
			<artifactId>jakarta.json-api</artifactId>
			<version>2.0.1</version>
		</dependency>

		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>elasticsearch-rest-client</artifactId>
			<version>8.11.1</version><!--改为自己的版本-->
		</dependency>

After importing, we write relevant connection code according to the official demo . The connection address uses the Cpolar public network address created above. If it is in other languages, the connection method is the same.

image-20231123163454683

After setting up, test writing data. Here, test and write an object.

image-20231123164409227

After the execution is successful without errors, we can see the data link written through the browser in the console log information. The link prefix can be seen, and it is also the cpolar public network address, which can be accessed by any browser.

image-20231123164549203

Through the link, we open the browser and enter the username and password to log in. After logging in, we can see the data we wrote, indicating success. In this way, a public network connection address is set.

image-20231123164833381

summary

For a better demonstration, we used the tunnel generated by cpolar in the aforementioned process, and its public network address was randomly generated.

The advantage of this random address is that it is established quickly and can be used immediately. However, its disadvantage is that the URL is generated by random characters and is not easy to remember (for example: 3ad5da5.r10.cpolar.top). In addition, this address will change randomly within 24 hours, making it more suitable for temporary use.

I usually use a fixed second-level subdomain name because when I want to send the URL to colleagues or customers, it is a fixed and easy-to-remember public address (for example: elasticsearch.cpolar.cn), which is more formal and convenient. Communicate and collaborate.

4. Set up a fixed second-level subdomain name

Since the tunnel created using cpolar above uses a random public network address, it will change randomly within 24 hours, which is not conducive to long-term remote access. Therefore, we can configure a second-level subdomain name for it. This address is a fixed address and will not change randomly [ps: cpolar.cn has been filed]

Note that you need to upgrade the cpolar package to a basic package or above, and the bandwidth corresponding to each package is different. [cpolar.cn has been registered]

Log in to the cpolar official website backend , click Reserve on the left, select to reserve the second-level subdomain name, set a second-level subdomain name, click Reserve, and copy the reserved second-level subdomain name after the reservation is successful.

image-20231113151721641

After the reservation is successful, copy the reserved second-level subdomain name address

image-20231113151751358

Log in to the cpolar web UI management interface, click Tunnel Management - Tunnel List on the left dashboard, find the tunnel you want to configure, and click Edit on the right

image-20231113152109057

Modify the tunnel information and configure the successfully reserved second-level subdomain name into the tunnel.

  • Domain name type: Select a second-level subdomain name
  • Sub Domain: Fill in the successfully reserved second-level subdomain name

Click更新

image-20231113152142969

After the update is completed, open the online tunnel list. At this time, you can see that the public network address has changed and the address name has become a reserved and fixed second-level subdomain name.

Finally, use the fixed domain name public network https address to connect, modify the hostname in the code, replace it with the fixed public network address, and then executeimage-20231123165603839

After execution, access through the printed address (new address access requires logging in again). After logging in, you can also see the data we wrote to elasticsearch. The connection is successful. Such a permanent fixed public network address is Set up!

image-20231123170126622

Supongo que te gusta

Origin blog.csdn.net/qq_48652579/article/details/135205828
Recomendado
Clasificación