一、修改elasticsearch 配置文件
1.在配置文件中開啟x-pack驗證
#進入es安裝目錄下的config目錄
vim elasticsearch.yml
# 配置X-Pack
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
2.重啟elasticsearch服務
3.執行設置用戶名和密碼的命令,需要為4個用戶分別設置密碼:elastic、kibana、logstash_system、beats_system
#進入bin目錄
cd /usr/local/elasticsearch-7.2.0/bin
#執行命令
./elasticsearch-setup-passwords interactive
二、修改kibana配置文件
1.修改kibana.yml配置文件,添加以下配置
#進入kibana安裝目錄
cd /usr/local/kibana-7.2.0-linux-x86_64/config
#修改配置文件
vim kibana.yml
#添加配置
elasticsearch.username: "elastic"
elasticsearch.password: "xxx"
2.重啟kibana服務
3.登錄kibana
三、Springboot 配置
1.SpringBoot2.2.x版本才支持ElasticSearch7.x,需要先升級SpringBoot版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/>
</parent>
2.修改application.yml
spring:
elasticsearch:
#es配置
rest:
#最新配置方式使用restful風格,端口從9300 -> 9200
uris: xx.xx.xx.xx:9200
username: elastic
password: xxx
3.補充
#原來spring-boot-starter-data-elasticsearch連接ES主要使用ElasticsearchTemplate進行操作
#新版本主要使用ElasticsearchRestTemplate
@Autowired
private ElasticsearchRestTemplate elasticsearchRestTemplate;