gpt4 book ai didi

elasticsearch - Elasticsearch:如何知道默认端口9200已使用时使用的HTTP端口号

转载 作者:行者123 更新时间:2023-12-03 00:48:25 25 4
gpt4 key购买 nike

在Elasticsearch文档中,指定了有关http.port配置的以下内容:

http.port

Port to bind to for incoming HTTP requests. Accepts a single value or a range. If a range is specified, the node will bind to the first available port in the range.

Defaults to 9200-9300.


假设由于9200已经在使用中,Elasticsearch自动选择端口9202。 Java客户端应用程序如何知道选择了哪个端口并必须使用它创建RestHighLevelClient对象?有没有办法查询可以提供端口号信息的另一项服务?
提前致谢。

更新
在第一个答案之后,我尝试通过执行以下操作在Windows机器(生产环境)中重现这些步骤:
> tasklist | findstr "elasticsearch"
elasticsearch-service-x64 2232 Services 0 537,764 K

> netstat -aon | find /i "2232"
TCP 0.0.0.0:9200 0.0.0.0:0 LISTENING 2232
TCP 0.0.0.0:9300 0.0.0.0:0 LISTENING 2232
TCP 127.0.0.1:9200 0.0.0.0:0 LISTENING 2232
TCP 127.0.0.1:9300 0.0.0.0:0 LISTENING 2232
TCP 127.0.0.1:49201 127.0.0.1:49202 ESTABLISHED 2232
TCP 127.0.0.1:49202 127.0.0.1:49201 ESTABLISHED 2232
TCP 127.0.0.1:49203 127.0.0.1:49204 ESTABLISHED 2232
TCP 127.0.0.1:49204 127.0.0.1:49203 ESTABLISHED 2232
TCP 127.0.0.1:49205 127.0.0.1:49206 ESTABLISHED 2232
TCP 127.0.0.1:49206 127.0.0.1:49205 ESTABLISHED 2232
...
TCP 127.0.0.1:49275 127.0.0.1:49276 ESTABLISHED 2232
TCP 127.0.0.1:49276 127.0.0.1:49275 ESTABLISHED 2232
TCP [::1]:9200 [::]:0 LISTENING 2232
TCP [::1]:9300 [::]:0 LISTENING 2232

结果显示使用9200端口(http.port)的几行:
TCP    0.0.0.0:9200           0.0.0.0:0              LISTENING       2232
TCP 127.0.0.1:9200 0.0.0.0:0 LISTENING 2232
TCP [::1]:9200 [::]:0 LISTENING 2232
如果必须解析该结果以获得端口号,我应该寻找哪些IP地址?还是根本没关系?

最佳答案

RestHighLevelClient是线程安全的,由应用程序在启动时或执行第一个请求时实例化。如何“在幕后”完成操作,也许您可​​以 checkin RestClientBuilder.java here

不确定该问题,但是如果不确定使用哪个端口ES,可以对其进行检查。

[root@myserver ~]# service elasticsearch status
elasticsearch (pid 5384) is running...

## netstat on pid
[root@myserver~]# netstat -plunt | grep 5384
tcp 0 0 ::ffff:10.100.14.146:9300 :::* LISTEN 5384/java
tcp 0 0 ::ffff:10.100.14.19:9200 :::* LISTEN 5384/java
tcp 0 0 ::ffff:127.0.0.1:9200 :::* LISTEN 5384/java

关于elasticsearch - Elasticsearch:如何知道默认端口9200已使用时使用的HTTP端口号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57075664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com