ELK: Establecer cuenta de acceso y contraseña para Elasticsearch y Kibanan

Tabla de contenido

1. Establezca la contraseña de Elasticseach:

2. Configure la cuenta y contraseña de Kibanan:

3. Cambie la contraseña de Elasticsearch:

4. Explicación adicional:

1) Kibana no tiene su propia cuenta y contraseña, utiliza la cuenta y contraseña de elasticsearch.

 2) Intente cambiar la contraseña de elasticsearch usando comandos en Windows. Hay varias situaciones de falla:


1. Establezca la contraseña de Elasticseach:

Modifique el archivo de configuración de Elasticsearch: elasticsearch.yml y agregue la siguiente configuración

#设置权限
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

Ventana de línea de comando CMD, ingrese al directorio bin de Elasticsearch y ejecute el comando para establecer el nombre de usuario y la contraseña.

elasticsearch-setup-passwords interactive

Las contraseñas para seis cuentas se establecerán aquí:elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.需要根据提示逐一设置密码。

D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>elasticsearch-setup-passwords interactive
future versions of Elasticsearch will require Java 11; your Java version from [C:\Program Files\Java\jdk1.8.0_291\jre] does not meet this requirement

Your cluster health is currently RED.
This means that some cluster data is unavailable and your cluster is not fully functional.

It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords.
It is very likely that the password changes will fail when run against an unhealthy cluster.

Do you want to continue with the password setup process [y/N]y

Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

如下图所示

Pruebe si hay una contraseña:

Acceda a la dirección y puerto predeterminados: http://localhost:9200/

Ingrese el número de cuenta: elastic, contraseña: 123456. Después de iniciar sesión correctamente, como se muestra a continuación:

Errores que puede encontrar:

1) Problema de codificación del archivo yml:

D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>elasticsearch-setup-passwords interactive
future versions of Elasticsearch will require Java 11; your Java version from [C:\Program Files\Java\jdk1.8.0_291\jre] does not meet this requirement
Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: YAMLException[java.io.CharConversionException: Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)
 at [Source: sun.nio.ch.ChannelInputStream@4738a206; line: 1, column: 1]]; nested: YAMLException[java.io.CharConversionException: Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)]; nested: CharConversionException[Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)];
        at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1097)
        at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1070)
        at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:83)
        at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:100)
        at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:91)
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
        at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:91)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
        at org.elasticsearch.cli.Command.main(Command.java:90)
        at org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordTool.main(SetupPasswordTool.java:107)
Caused by: com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException: java.io.CharConversionException: Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)
 at [Source: sun.nio.ch.ChannelInputStream@4738a206; line: 1, column: 1]
        at com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException.from(YAMLException.java:25)
        at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:346)
        at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:52)
        at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1089)
        ... 10 more
Caused by: org.yaml.snakeyaml.error.YAMLException: java.io.CharConversionException: Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)
        at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:200)
        at org.yaml.snakeyaml.reader.StreamReader.peek(StreamReader.java:146)
        at org.yaml.snakeyaml.scanner.ScannerImpl.scanToNextToken(ScannerImpl.java:1199)
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:289)
        at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226)
        at org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:194)
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:157)
        at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:167)
        at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:340)
        ... 12 more
Caused by: java.io.CharConversionException: Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)
        at com.fasterxml.jackson.dataformat.yaml.UTF8Reader.reportInvalidOther(UTF8Reader.java:394)
        at com.fasterxml.jackson.dataformat.yaml.UTF8Reader.read(UTF8Reader.java:253)
        at com.fasterxml.jackson.dataformat.yaml.UTF8Reader.read(UTF8Reader.java:148)
        at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:184)
        ... 20 more

Como se muestra abajo:

La codificación del archivo cambió a UTF-8

  2) Se ha agregado un elemento de configuración más: (por determinar)

Si sigue lo que escriben algunos blogs, agregue tres configuraciones al archivo elasticsearch.yml.

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

Se producirá el siguiente error:

D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>elasticsearch-setup-passwords interactive
future versions of Elasticsearch will require Java 11; your Java version from [C:\Program Files\Java\jdk1.8.0_291\jre] does not meet this requirement

Unexpected response code [500] from calling GET http://127.0.0.1:9200/_security/_authenticate?pretty
It doesn't look like the X-Pack security feature is enabled on this Elasticsearch node.
Please check if you have enabled X-Pack security in your elasticsearch.yml configuration file.

ERROR: X-Pack Security is disabled by configuration.

Como se muestra abajo:

 3) Elasticsearch no se inicia

D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>elasticsearch-setup-passwords interactive
future versions of Elasticsearch will require Java 11; your Java version from [C:\Program Files\Java\jdk1.8.0_291\jre] does not meet this requirement

Connection failure to: http://127.0.0.1:9200/_security/_authenticate?pretty failed: Connection refused: connect

ERROR: Failed to connect to elasticsearch at http://127.0.0.1:9200/_security/_authenticate?pretty. Is the URL correct and elasticsearch running?

Como se muestra abajo:

2. Configure la cuenta y contraseña de Kibanan:

1) Abra kibana.yml en el directorio conf de Kibana y modifique la configuración de nombre de usuario y contraseña de elasticsearch en él. El valor predeterminado está comentado, como se muestra a continuación:

Modificar la configuración de kibana kibana.yml: (Cambie a la cuenta de Elasticsearch y la contraseña establecidas anteriormente, elimine el signo # al frente)

# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
elasticsearch.username: "elastic"
elasticsearch.password: "123456"

Como se muestra abajo:

2) Pruebe el inicio de sesión en Kibana, como se muestra a continuación. Ingrese el nombre de usuario de inicio de sesión establecido (elástico) y la contraseña (123456) para iniciar sesión correctamente.

3. Cambie la contraseña de Elasticsearch:

La mayoría de los comandos para cambiar contraseñas en línea son los siguientes: este es el comando curl en Linux.

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

En la línea de comando CMD de Windows, para cambiar la contraseña de Elasticsearch, debe prestar atención a algunas formas de escribir el comando curl:

En la ventana, las comillas simples en formato Linux deben cambiarse a comillas dobles y las comillas dobles en los datos en formato json deben estar en formato \escaped.

Debería ser el siguiente:

curl -H "Content-Type:application/json" -XPOST -u elastic -d "{\"password\" : \"1234567\" }" http://127.0.0.1:9200/_xpack/security/user/elastic/_password

Como se muestra en la imagen:

4. Explicación adicional:

1) Kibana no tiene su propia cuenta y contraseña, utiliza la cuenta y contraseña de elasticsearch.

Por lo tanto, debe configurarse en kibana.yml. Si kibaba.yml no establece la contraseña correcta de la cuenta de elasticsearch,

Al acceder a http://localhost:5601/ . No se puede abrir.

Verifique elasticsearch.log y encontrará el registro de errores: La autenticación de [elastic] fue cancelada por el reino [reservado] - no se pudo autenticar al usuario [elastic]

 2) Intente cambiar la contraseña de elasticsearch usando comandos en Windows. Hay varias situaciones de falla:

En el comando curl, mezclar comillas simples y dobles para los parámetros provocará el siguiente error:

D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>curl -H "Content-Type:application/json" -XPOST -u elastic -d '{ "password" : "1234567" }'  'http://127.0.0.1:9200/_xpack/security/user/elastic/_password'
Enter host password for user 'elastic':
curl: (6) Could not resolve host: password
curl: (3) URL using bad/illegal format or missing URL
curl: (7) Failed to connect to 0.18.214.135 port 80 after 0 ms: Network unreachable
curl: (3) unmatched close brace/bracket in URL position 1:
}'

 En el comando curl, las comillas dobles en los datos en formato json no se escapan.

D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>curl -H "Content-Type:application/json" -XPOST -u elastic -d "{"password" : "666666" }" "http://127.0.0.1:9200/_xpack/security/user/elastic/_password"
Enter host password for user 'elastic':
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected character ('p' (code 112)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5f92bad8; line: 1, column: 3]"}],"type":"json_parse_exception","reason":"Unexpected character ('p' (code 112)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@5f92bad8; line: 1, column: 3]"},"status":400}

Supongo que te gusta

Origin blog.csdn.net/louis_lee7812/article/details/127023312
Recomendado
Clasificación