当前位置:   article > 正文

ELK: 给Elasticsearch, Kibanan设置访问的账号和密码_kibana默认账号密码

kibana默认账号密码

目录

1、设置Elasticseach的密码:

2、设置Kibanan的账号和密码:

3、修改Elasticsearch的密码:

4、补充说明:

1)kibana并没有自己的账号和密码,它使用的就是elasticsearch的账号密码。

 2)在windwos下尝试命令的方式修改elasticsearch的密码,失败的几种情况:


1、设置Elasticseach的密码:

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

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

CMD命令行窗口,进入Elasticsearch的bin目录下,执行设置用户名和密码的命令

elasticsearch-setup-passwords interactive

这里会设置六个账号的密码:elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.需要根据提示逐一设置密码。

  1. D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>elasticsearch-setup-passwords interactive
  2. 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
  3. Your cluster health is currently RED.
  4. This means that some cluster data is unavailable and your cluster is not fully functional.
  5. It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords.
  6. It is very likely that the password changes will fail when run against an unhealthy cluster.
  7. Do you want to continue with the password setup process [y/N]y
  8. Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
  9. You will be prompted to enter passwords as the process progresses.
  10. Please confirm that you would like to continue [y/N]y
  11. Enter password for [elastic]:
  12. Reenter password for [elastic]:
  13. Enter password for [apm_system]:
  14. Reenter password for [apm_system]:
  15. Enter password for [kibana]:
  16. Reenter password for [kibana]:
  17. Enter password for [logstash_system]:
  18. Reenter password for [logstash_system]:
  19. Enter password for [beats_system]:
  20. Reenter password for [beats_system]:
  21. Enter password for [remote_monitoring_user]:
  22. Reenter password for [remote_monitoring_user]:
  23. Changed password for user [apm_system]
  24. Changed password for user [kibana]
  25. Changed password for user [logstash_system]
  26. Changed password for user [beats_system]
  27. Changed password for user [remote_monitoring_user]
  28. Changed password for user [elastic]

如下图所示

测试是否有密码:

访问默认的地址和端口:http://localhost:9200/

输入账号:elastic,密码:123456,登录成功后,如下图:

可能会遇到的错误:

1) yml文件的编码问题:

  1. D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>elasticsearch-setup-passwords interactive
  2. 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
  3. 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)
  4. 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)];
  5. at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1097)
  6. at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1070)
  7. at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:83)
  8. at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:100)
  9. at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:91)
  10. at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
  11. at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
  12. at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:91)
  13. at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
  14. at org.elasticsearch.cli.Command.main(Command.java:90)
  15. at org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordTool.main(SetupPasswordTool.java:107)
  16. Caused by: com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException: java.io.CharConversionException: Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)
  17. at [Source: sun.nio.ch.ChannelInputStream@4738a206; line: 1, column: 1]
  18. at com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException.from(YAMLException.java:25)
  19. at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:346)
  20. at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:52)
  21. at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1089)
  22. ... 10 more
  23. Caused by: org.yaml.snakeyaml.error.YAMLException: java.io.CharConversionException: Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)
  24. at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:200)
  25. at org.yaml.snakeyaml.reader.StreamReader.peek(StreamReader.java:146)
  26. at org.yaml.snakeyaml.scanner.ScannerImpl.scanToNextToken(ScannerImpl.java:1199)
  27. at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:289)
  28. at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226)
  29. at org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:194)
  30. at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:157)
  31. at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:167)
  32. at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:340)
  33. ... 12 more
  34. Caused by: java.io.CharConversionException: Invalid UTF-8 middle byte 0xe8 (at char #2887, byte #2047)
  35. at com.fasterxml.jackson.dataformat.yaml.UTF8Reader.reportInvalidOther(UTF8Reader.java:394)
  36. at com.fasterxml.jackson.dataformat.yaml.UTF8Reader.read(UTF8Reader.java:253)
  37. at com.fasterxml.jackson.dataformat.yaml.UTF8Reader.read(UTF8Reader.java:148)
  38. at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:184)
  39. ... 20 more

如下图:

文件编码改为UTF-8

  2) 多加了一个配置项目:(待确定)

如果按照有些博客写的,elasticsearch.yml文件,添加三个配置

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

会出现下列错误:

  1. D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>elasticsearch-setup-passwords interactive
  2. 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
  3. Unexpected response code [500] from calling GET http://127.0.0.1:9200/_security/_authenticate?pretty
  4. It doesn't look like the X-Pack security feature is enabled on this Elasticsearch node.
  5. Please check if you have enabled X-Pack security in your elasticsearch.yml configuration file.
  6. ERROR: X-Pack Security is disabled by configuration.

如下图:

 3)没有启动Elasticsearch

  1. D:\devsofts\elk7.6.2\elasticsearch-7.6.2-windows-x86_64\elasticsearch-7.6.2\bin>elasticsearch-setup-passwords interactive
  2. 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
  3. Connection failure to: http://127.0.0.1:9200/_security/_authenticate?pretty failed: Connection refused: connect
  4. 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的账号和密码,去掉前面的#号)

  1. # If your Elasticsearch is protected with basic authentication, these settings provide
  2. # the username and password that the Kibana server uses to perform maintenance on the Kibana
  3. # index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
  4. # is proxied through the Kibana server.
  5. elasticsearch.username: "elastic"
  6. 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命令的一些写法:

在window中linux格式下的单引号要改成双引号,json格式数据中双引号要加\转义

应该如下:

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,会发现错误日志:Authentication of [elastic] was terminated by realm [reserved] - failed to authenticate user [elastic]

 2)在windwos下尝试命令的方式修改elasticsearch的密码,失败的几种情况:

curl命令中,参数的单引号和双引号混用,会引起如下错误:

  1. 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'
  2. Enter host password for user 'elastic':
  3. curl: (6) Could not resolve host: password
  4. curl: (3) URL using bad/illegal format or missing URL
  5. curl: (7) Failed to connect to 0.18.214.135 port 80 after 0 ms: Network unreachable
  6. curl: (3) unmatched close brace/bracket in URL position 1:
  7. }'

 curl命令中,json格式数据中双引号没有加\转义

  1. 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"
  2. Enter host password for user 'elastic':
  3. {"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}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/259820
推荐阅读
相关标签
  

闽ICP备14008679号