ELK: Elasticsearch と Kibanan のアクセス アカウントとパスワードを設定する

目次

1. Elasticseach のパスワードを設定します。

2. Kibanan のアカウントとパスワードを設定します。

3. Elasticsearch のパスワードを変更します。

4. 追加説明:

1) Kibana は独自のアカウントとパスワードを持たず、elasticsearch のアカウントとパスワードを使用します。

 2) Windows でコマンドを使用して elasticsearch のパスワードを変更しようとすると、失敗する状況がいくつかあります。


1. Elasticseach のパスワードを設定します。

Elasticsearch 構成ファイル elasticsearch.yml を変更し、次の構成を追加します。

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

CMD コマンド ライン ウィンドウで、Elasticsearch の bin ディレクトリに入り、コマンドを実行してユーザー名とパスワードを設定します。

elasticsearch-setup-passwords interactive

6 つのアカウントのパスワードがここで設定されます。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]

如下图所示

パスワードがあるかどうかをテストします。

デフォルトのアドレスとポートにアクセスします: http://localhost:9200/

アカウント番号: elastic、パスワード: 123456 を入力します。ログインに成功すると、以下のようになります。

発生する可能性のあるエラー:

1) 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

以下に示すように:

ファイルエンコーディングがUTF-8に変更されました

  2) 設定項目が 1 つ追加されました: (未定)

一部のブログの内容に従う場合は、elasticsearch.yml ファイルに 3 つの設定を追加します。

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

次のエラーが発生します。

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.

以下に示すように:

 3) Elasticsearchが開始されていない

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?

以下に示すように:

2. Kibanan のアカウントとパスワードを設定します。

1) Kibana の conf ディレクトリにある kibana.yml を開き、内部の elasticsearch のユーザー名とパスワードの設定を変更します。デフォルトは、以下に示すようにコメントアウトされています。

kibana 設定を変更しますkibana.yml: (以前に設定した Elasticsearch アカウントとパスワードに変更し、先頭の # 記号を削除します)

# 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"

以下に示すように:

2) 以下に示すように Kibana ログインをテストし、設定したログイン ユーザー名 (elastic) とパスワード (123456) を入力して正常にログインします。

3. Elasticsearch のパスワードを変更します。

オンラインでパスワードを変更するコマンドのほとんどは次のとおりです (Linux では、curl コマンドです)。

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

Windows の CMD コマンド ラインで Elasticsearch のパスワードを変更するには、curl コマンドの記述方法に注意する必要があります。

ウィンドウでは、linux 形式の単一引用符を二重引用符に変更し、json 形式のデータの二重引用符を \escaped する必要があります。

次のようになるはずです。

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

図に示すように:

4. 追加説明:

1) Kibana は独自のアカウントとパスワードを持たず、elasticsearch のアカウントとパスワードを使用します。

したがって、kibana.yml で設定する必要があります。kibaba.yml が正しい elasticsearch アカウントのパスワードを設定しない場合、

http://localhost:5601/にアクセスする場合開けることはできません。

elasticsearch.log を確認すると、エラー ログが見つかります: [elastic] の認証はレルム [予約] によって終了しました - ユーザー [elastic] の認証に失敗しました。

 2) Windows でコマンドを使用して elasticsearch のパスワードを変更しようとすると、失敗する状況がいくつかあります。

curl コマンドでは、パラメータに一重引用符と二重引用符を混在させると、次のエラーが発生します。

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:
}'

 curlコマンドでは、json形式データ内のダブルクォーテーションはエスケープされません。

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}

おすすめ

転載: blog.csdn.net/louis_lee7812/article/details/127023312