ElasticSearch+Kibana設置用戶名密碼登陸


ElasticSearch版本:7.7.1

配置

修改es的配置文件:elasticsearch.yml,添加如下配置

xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true

es的bin目錄下,執行設置用戶名和密碼的命令

./elasticsearch-setup-passwords interactive

這里會設置六個賬號的密碼:elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.

image-20210425122400164

修改kibana的配置kibana.yml

image-20210425123351140

es修改密碼的命令如下:

curl -H "Content-Type:application/json" -XPOST -u elastic 'http://192.168.140:9200/_xpack/security/user/elastic/_password' -d '{ "password" : "123456" }'

重啟es和kibana

訪問http://192.168.1.40:9200,需要輸入賬號密碼才可以訪問

image-20210425123533151

訪問:http://192.168.1.40:5601/

同樣需要認證才可登陸,登陸賬號密碼為elastic/123456

image-20210425123637430

java客戶端連接

需要與springdata es整合

RestHighLevelClient

    @Bean
    public RestHighLevelClient restHighLevelClient() {

        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo("192.168.1.40:9200")
                .withConnectTimeout(Duration.ofSeconds(5))
                .withSocketTimeout(Duration.ofSeconds(3))
                .withBasicAuth("elastic", "123456")
                .build();
        return RestClients.create(clientConfiguration).rest();
    }

SpringData ES配置

spring:
  elasticsearch:
    rest:
      uris: "http://192.168.1.40:9200"
      read-timeout: "10s"
      username: "elastic"
      password: "123456"
      connection-timeout: "10s"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM