官网下载ElasticSearch8和Kibana8

进入

https://www.elastic.co/cn/downloads/elasticsearch

下载Es8和Kibana8

注意选择windows版本

安装ElasticSearch8

解压缩Es8到任务目录

到/bin 目录执行 ./elasticsearch.bat

在命令行控制台中找到密码和token 保存起来

->  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  VWFjE60dbpKIjbajGJQ4

->  HTTP CA certificate SHA-256 fingerprint:
  b6a69429e178231857760658deedfcfe6e858d8fcfcc3d230099dcc04acf429d

->  Configure Kibana to use this cluster:
* Run Kibana and click the configuration link in the terminal when Kibana starts.
* Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjAuMCIsImFkciI6WyIxNzIuMTkuNTEuNjU6OTIwMCIsIjE5Mi4xNjguMzEuMTE6OTIwMCIsIjE5Mi4xNjguMTA2LjE6OTIwMCIsIjE5Mi4xNjguMjMuMTo5MjAwIl0sImZnciI6ImI2YTY5NDI5ZTE3ODIzMTg1Nzc2MDY1OGRlZWRmY2ZlNmU4NThkOGZjZmNjM2QyMzAwOTlkY2MwNGFjZjQyOWQiLCJrZXkiOiJ5RU1DX0g0QjhLSUNnMWNqdlRwZjpqS2ZENmdIRVFGR0gxbkFWbVplS1NRIn0=

其中kibana使用的token有效期为30分钟,如果过期,需要使用如下命令行重新生成token

bin/elasticsearch-create-enrollment-token -s node

访问如下网址,测试安装是否成功

https://localhost:9200/

出现如下图片则代表安装完毕

这时候你可以使用账号elastic和之前保存的密码登录了
登录后可以看到一些json数据

安装kibana8

然后解压缩kibana8到任意目录

执行 /bin 中的./kibana.bat

复制控制台出现的连接 拷贝到浏览器中打开

将刚才的token复制到文本框中 并确认,
 

用户名elastic
密码就是上一步保存的密码登录即可
至此 Kibana8安装完毕

访问URL

​ http://localhost:5601/

使用SpringBoot访问带有CA证书的SE数据库

添加依赖包

<dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>8.0.0</version>
        </dependency>

配置Bean 其中需要访问用到的密码 以及上文提到的CA证书

@Bean(destroyMethod = "close")
    public RestClient restClient() throws CertificateException, IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

        final CredentialsProvider credentialsProvider =
                new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("elastic", "VWFjE60dbpKIjbajGJQ4"));

        Path caCertificatePath = Paths.get("E:\\es\\elasticsearch-8.0.0-windows-x86_64\\elasticsearch-8.0.0\\config\\certs\\http_ca.crt");
        CertificateFactory factory =
                CertificateFactory.getInstance("X.509");
        Certificate trustedCa;
        try (InputStream is = Files.newInputStream(caCertificatePath)) {
            trustedCa = factory.generateCertificate(is);
        }
        KeyStore trustStore = KeyStore.getInstance("pkcs12");
        trustStore.load(null, null);
        trustStore.setCertificateEntry("ca", trustedCa);
        SSLContextBuilder sslContextBuilder = SSLContexts.custom()
                .loadTrustMaterial(trustStore, null);
        final SSLContext sslContext = sslContextBuilder.build();
        RestClientBuilder builder = RestClient.builder(
                new HttpHost("localhost", 9200, "https"))
                .setHttpClientConfigCallback(httpClientBuilder -> {
                    httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                    return httpClientBuilder.setSSLContext(sslContext);
                });
        return builder.build();
    }

访问指定索引(表)

//注入client
    @Autowired
    RestClient restClient;

..... 逻辑代码中 ......

        Request request = new Request("GET","/ess_book/_doc/1");
        Response response = restClient.performRequest(request);
        return EntityUtils.toString(response.getEntity());

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐