下载地址:https://www.elastic.co/cn/downloads/past-releases/winlogbeat-8-8-1
解压\elasticsearch\elasticsearch-8.5.1
进入bin目录,启动elasticsearch.bat
问题1:
warning: ignoring JAVA_HOME=D:\jdk1.8.0_271; using bundled JDK
JDK问题,使用ES自带JDK
修改elasticsearch-env.bat文件
set JAVA="%ES_HOME%\jdk\bin\java.exe"
set JAVA_HOME="%ES_HOME%\jdk"
启动elasticsearch.bat
问题2:
内存问题,修改\elasticsearch-8.5.1\config\jvm.options文件
启动elasticsearch.bat
问题3
修改conf目录下的elasticsearch.yml文件,新增一条配置,关闭更新配置
启动elasticsearch.bat成功。
记录密码
关闭密码:打开config 目录下面的 elasticsearch.yml 文件,把加密关闭
修改密码
修改elasticsearch.yml 改为
xpack.security.enabled: true
重启ES后bin目录下执行
./elasticsearch-setup-passwords interactive
出现异常
修改命令
./elasticsearch-reset-password -u elastic -i
修改密码完成
问题4
最大的坑!!!!!
最大的坑!!!!!
最大的坑!!!!!
ES8默认采用HTTPS请求,Java连接失败,需要将elasticsearch-8.5.1\config\certs下http_ca.crt证书配置到项目的resource目录下,或修改elasticsearch.yml配置文件,关闭https,注意将证书路径也注释掉。
依赖配置
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>8.7.1</version>
</dependency>
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
代码
try {
HttpHost[] httpHosts = Arrays.stream(clusterNodes.split(",")).map(x -> {
String[] hostInfo = x.split(":");
return new HttpHost(hostInfo[0], Integer.parseInt(hostInfo[1]));
}).toArray(HttpHost[]::new);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//设置账号密码
credentialsProvider.setCredentials(
AuthScope.ANY, new UsernamePasswordCredentials(account, passWord));
builder = RestClient.builder(httpHosts)
.setHttpClientConfigCallback(httpClientBuilder ->
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
// Create the low-level client
restClient = builder.build();
// Create the transport with a Jackson mapper
transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
// And create the API client
client = new ElasticsearchClient(transport);
Boolean acknowledged = client.indices().create(c -> c.index("user")).acknowledged();
System.out.println("<<<<<<<<<<<<<<<acknowledged>>>>>>>>>>>>>>>>>>>" + acknowledged);
} catch (Exception e) {
e.printStackTrace();
}