当前位置: 首页 > news >正文

Debian安装和使用Elasticsearch 8.9

命令行通过 .deb 包安装 Elasticsearch

elastic

创建一个新用户

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客户端

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 clientElasticsearchTransport transport = new RestClientTransport(elasticsearchRestClient(), new JacksonJsonpMapper());return new ElasticsearchClient(transport);}
}

测试ElasticsearchClient

@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();
}
http://www.lryc.cn/news/123080.html

相关文章:

  • 三 、CTR预估数据准备
  • netty学习分享 二
  • 聊聊web服务器NGINX
  • 【hello C++】特殊类设计
  • js实现按创建时间戳1609459200000 开始往后开始显示运行时长-demo
  • latex三线表按页面大小填充
  • 佛祖保佑,永不宕机,永无bug
  • redis分布式集群-redis+keepalived+ haproxy
  • 快递管理系统springboot 寄件物流仓库java jsp源代码mysql
  • 自学黑客/网络安全(学习路线+教程视频+工具包+经验分享)
  • 如何进行游戏平台搭建?
  • 安全防御问题
  • x-www-form-urlencoded、application/json到底是什么
  • LeetCode 33题:搜索旋转排序数组
  • 用python来爬取某鱼的商品信息(1/2)
  • 网工最常犯的9大错误,越早知道越吃香
  • Windows - UWP - 网络不好的情况下安装(微软商店)MicrosoftStore的应用
  • 1040:输出绝对值
  • [Docker精进篇] Docker部署和实践 (二)
  • day9 | 28. 实现 strStr()、459.重复的子字符串
  • hive on tez资源控制
  • 企业有VR全景拍摄的需求吗?能带来哪些好处?
  • 【问题解决】Git命令行常见error及其解决方法
  • 【100天精通python】Day34:使用python操作数据库_ORM(SQLAlchemy)使用
  • CCLINK IE转MODBUS-TCP网关modbus tcp协议详解
  • vue2根据不同的电脑分辨率显示页面内容及不同设备适配显示
  • 概率论:多维随机变量及分布
  • flutter-第三方组件
  • 迪瑞克斯拉算法
  • 数据结构:力扣OJ题(每日一练)