1. received plaintext http traffic on an https channel, closing connection Netty4HttpChannel

[2022-02-16T21:08:50,085][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [DESKTOP-VCT39JM] received plaintext http traffic on an https channel, closing connection Netty4HttpChannel{localAddress=/[0:0:0:0:0:0:0:1]:9200, remoteAddress=/[0:0:0:0:0:0:0:1]:1172}

解决

是因为开启了 ssl 认证。
在 ES/config/elasticsearch.yml 文件中把 xpack.security.http.ssl:enabled 设置成 false 即可

# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: false
  keystore.path: certs/http.p12

2. elasticsearch 账号密码

windows 下直接启动 ElasticSearch ,见到 started 为成功启动,访问 htttp://localhost:9200 需要输入密码,是因为开启了密码验证模式。
找了一轮没看到有账号密码,干脆就设置免密登录就好。

解决

找到 elasticsearch.yml 文件, 把 xpack.security.enabled 属性设置为 false 即可。

# Enable security features
xpack.security.enabled: false

3. 设置内存大小

ES 的内存是自己调节的。在 config/jvm.options 文件中直接设置就好(追加):

-Xms512m
-Xmx2048m

4. windows Could not rename log file ‘logs/gc.log’ to ‘logs/gc.log.14’ (Permission denied).

ES 在 windows 中只允许打开一个应用程序,当你再想去创建一个 ES 应用程序的时候,就会显示 Permission denied,即使是使用 cmd 管理员运行 elasticsearch.bat 文件也是一样的错误。

  • 解决: 注意查看是否已经在别的地方已经打开 ES 服务,实在不行则进行电脑重启

5. org/elasticsearch/action/ActionRequest has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

public static void main(String[] args) throws IOException {
    // 创建 ES 客户端
    RestHighLevelClient client = new RestHighLevelClient(
        RestClient.builder(new HttpHost(Constants.HOST, Constants.PORT, Constants.HTTP))
    );

    client.close();
}

通过上述代码,使用 RestHighLevelCilent 访问 ES 客户端的时候,出现以下错误:Exception in thread "main" java.lang.UnsupportedClassVersionError:org/elasticsearch/action/ActionRequest has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

看到注释,我们知道是版本不兼容的问题,查找资料看到这样一个表:

Major version numbers map to Java versions:

45 = Java 1.1
46 = Java 1.2
47 = Java 1.3
48 = Java 1.4
49 = Java 5
50 = Java 6
51 = Java 7
52 = Java 8
53 = Java 9
54 = Java 10
55 = Java 11
56 = Java 12
57 = Java 13

讲道理在这个版本任你发,我用Java8 的年代,RestHighLevelClient 肯定是兼容Java 8 的,那么就只有 ES 版本太高了,把 pom.xmlES 依赖版本降到跟 elasticsearch-rest-high-level-client 一样就可以了

<properties>
    <elasticsearch.version>7.17.0</elasticsearch.version>   	 																	<elasticsearch.client.version>7.17.0</elasticsearch.client.version>
</properties>

<dependies>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>${elasticsearch.version}</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>${elasticsearch.client.version}</version>
    </dependency>
</dependies>
  • 解决:把 pom.xmlelasticsearchelasticsearch-rest-high-level-client 版本一致即可。
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐