Debian安装和使用Elasticsearch 8.9

命令行通过 .deb 包安装 Elasticsearch

创建一个新用户

bash 复制代码
adduser elastic --> rust
# 添加sudo权限
# https://phoenixnap.com/kb/how-to-create-sudo-user-on-ubuntu
usermod -aG sudo elastic
groups elastic

下载Elasticsearch v8.9.0 Debian 包

https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html#install-deb

Elasticsearch: 初学者指南

https://medium.com/@animeshblog/elasticsearch-the-beginners-cookbook-1cf30f98218

快速开始

主要参考:Verifying HTTPS with a certificate fingerprint

创建 Elasticsearch Java客户端

java 复制代码
package org.elastic.service.es;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.TransportUtils;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;

import javax.net.ssl.SSLContext;

/**
 * <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html#_verifying_https_with_a_certificate_fingerprint">Verifying HTTPS with a certificate fingerprint</a>
 */
public class MEElastic {
    /**
     * The SHA-256 fingerprint of the certificate used to sign the Elasticsearch server certificate.
     * <p>
     * come from <a href="https://security.stackexchange.com/a/14345">What is the actual value of a certificate fingerprint?</a>
     */
    private static final String fingerprint = "2c895506b07083da7299656fa7fc4b433c3e26c03cf1a99eef23c537711b6e6e";


    private static final String esUsername = "elastic";

    private static final String esPassword = "k_*t_arOy7RF6EQVL-QA";

    private RestClient elasticsearchRestClient() {
        SSLContext sslContext = TransportUtils
                .sslContextFromCaFingerprint(fingerprint);
        BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
        credsProv.setCredentials(
                AuthScope.ANY, new UsernamePasswordCredentials(esUsername, esPassword)
        );
        return RestClient
                .builder(new HttpHost("127.0.0.1", 9200, "https"))
                .setHttpClientConfigCallback(hc -> hc
                        .setSSLContext(sslContext)
                        .setDefaultCredentialsProvider(credsProv)
                        .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
                )
                .build();
    }

    public ElasticsearchClient elasticsearchClient() {
        // Create the transport and the API client
        ElasticsearchTransport transport = new RestClientTransport(elasticsearchRestClient(), new JacksonJsonpMapper());
        return new ElasticsearchClient(transport);
    }
}

测试ElasticsearchClient

java 复制代码
@Test
void elasticsearchClient() throws IOException {
    MEElastic meElastic = new MEElastic();
    ElasticsearchClient esClient = meElastic.elasticsearchClient();
    GetIndexResponse rsp = esClient.indices().get(request -> request.index("test"));
    System.out.println(rsp);
    esClient._transport().close();
}
相关推荐
我爱学习好爱好爱几秒前
Elasticsearch 7.17.10 双节点集群部署(二):安装 elasticsearch-head 插件实现可视化
大数据·linux·elasticsearch
Elastic 中国社区官方博客1 小时前
SearchClaw:将 Elasticsearch 通过可组合技能引入 OpenClaw
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
k7Cx7e8 小时前
Debian执行ssh root@localhost 提示认证失败
运维·debian·ssh
无你想你8 小时前
Datawhale之春晚机器人跳舞复刻
大数据·elasticsearch·机器人
刘一说9 小时前
Git 工具知识全景图:从核心概念到高效协作实践
大数据·git·elasticsearch
MarsLord9 小时前
ElasticSearch快速入门实战(1)-索引、别名、建模最佳实践
大数据·elasticsearch·搜索引擎
阿干tkl9 小时前
openEuler 部署 Elasticsearch单节点与集群方式
elasticsearch
淘矿人9 小时前
【claude】05_Claude Skill 实战案例精选(上):开发类技能+weelinking中转服务
大数据·人工智能·python·elasticsearch·搜索引擎·cloudera
是垚不是土9 小时前
ClaudeCode×Elasticsearch:服务日志查询的 AI 化落地实践
大数据·运维·人工智能·elasticsearch·云计算·jenkins
etcix9 小时前
go cli translator that use bing api and youdao api
开发语言·elasticsearch·golang