配置https ssl elasticsearch,springboot项目中连接elasticsearch https

配置self-signed证书

参考之前的文章
创建self-signed证书
下面展示一些 内联代码片

# Enable security features
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
  enabled: true
  key: /etc/elasticsearch/certs/server.key
  certificate: /etc/elasticsearch/certs/server.crt
  certificate_authorities: /etc/elasticsearch/certs/rootCA.crt

# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
  enabled: true
  key: /etc/elasticsearch/certs/server.key
  certificate: /etc/elasticsearch/certs/server.crt
  certificate_authorities: /etc/elasticsearch/certs/rootCA.crt

cluster.initial_master_nodes: ["your_hostname"]

# Allow HTTP API connections from localhost and local networks
# Connections are encrypted and require user authentication
http.host: [_local_, _site_]
path.repo: ["/opt/apps/elasticsearchdata"]
# Allow other nodes to join the cluster from localhost and local networks
# Connections are encrypted and mutually authenticated
#transport.host: [_local_, _site_]

更改user和权限

sudo chown -R elasticsearch:elasticsearch /etc/elasticsearch/certs/
sudo chmod -R 777 etc/elasticsearch/certs/

在这里插入图片描述

重启elasticsearch

在这里插入图片描述

查看https接口:

在这里插入图片描述

在springboot项目中连接elasticsearch https

引入rootCA.crt到jdk的cacerts(windows和linux都是一样)

keytool -import -alias yourAliasName -file /etc/elasticsearch/certs/rootCA.crt -keystore  jdk_home/lib/security/cacerts

在这里插入图片描述
启动springboot项目应该可以连接上elasticsearch了。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Boot项目使用Elasticsearch,需要在pom.xml文件添加相关依赖。以下是一个使用Spring Boot和Elasticsearch的简单示例: 1.添加依赖 ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency> ``` 2.配置Elasticsearch属性 在application.properties文件添加Elasticsearch配置属性,例如: ```properties spring.data.elasticsearch.cluster-name=my-application spring.data.elasticsearch.cluster-nodes=localhost:9300 ``` 3.定义实体类 在Spring Boot应用程序,可以使用Spring Data Elasticsearch来定义Elasticsearch实体类。例如: ```java @Document(indexName="blog",type="article") public class Article { @Id private String id; private String title; private String content; // getters and setters } ``` 4.定义Elasticsearch存储库 定义一个Elasticsearch存储库接口,例如: ```java public interface ArticleRepository extends ElasticsearchRepository<Article, String> { List<Article> findByTitle(String title); } ``` 5.在服务使用Elasticsearch存储库 在服务注入Elasticsearch存储库,并使用它执行Elasticsearch操作,例如: ```java @Service public class ArticleService { @Autowired private ArticleRepository articleRepository; public List<Article> search(String title) { return articleRepository.findByTitle(title); } public void save(Article article) { articleRepository.save(article); } } ``` 这是一个简单的示例,演示了如何在Spring Boot应用程序使用Elasticsearch。你可以使用这个示例作为起点,根据自己的需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值