Elasticsearch + kibana set user name and password to log in

Elasticsearch version: 7.7.1

to configure

Modify the configuration file of es: elasticsearch.yml, and add the following configuration

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

Execute the command to set the user name and password in the bin directory of ES

./elasticsearch-setup-passwords interactive

Passwords for six accounts will be set here: elastic, APM_ system,kibana,logstash_ system,beats_ system,remote_ monitoring_ user.

Modify kibana configuration kibana. YML :

Es the command to change the password is as follows:

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

Restart es and kibana

visit http://192.168.1.40:9200 , you need to enter your account and password to access

visit: http://192.168.1.40:5601/

Authentication is also required to log in. The login account password is elastic/123456

Java client connection

Need to integrate with 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 configuration

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

Similar Posts: