本地Elasticsearch安装配置

Elasticsearch是开源的搜索引擎,基于Lucence开发,属于ELK套件中的一员。ELK=Elasticsearch、Logstash、Kibana是以Elasticsearch为核心的搜索、日志搜集,可视化工具套件。

官网:https://www.elastic.co/cn/

下载按照ES

下载ES

下载地址:https://www.elastic.co/cn/downloads/elasticsearch

文档地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

选择对应的系统平台,比如Windows

实际地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.5.2-windows-x86_64.zip

下载后可以启动ES了,不过要注意,默认情况是有安全性的。

启动ES

解压Elasticsearch相关文件,然后找到elasticsearch-8.5.2\bin\elasticsearch.bat文件双击启动即可。

ES8之后推荐用内嵌的JDK,不用外部的JDK。当然也可以配置成使用外部JDK

warning: ignoring JAVA_HOME=C:\softs\Java\jdk11.0.9.1+1; using bundled JDK

启动前最好修改一下config/jvm.options信息,根据实际调整堆内存,默认使用8G内存,本地测试太耗资源。

-Xms2G
-Xmx2G
-Dfile.encoding=GBK

默认启用了安全性,如果要关闭安全性需要修改config/elasticsearch.yml中的xpack.security.enabled: false

如果要外部能访问到Elasticsearch,需要配置监听IP,默认只能本机访问

network.host: 0.0.0.0

下面的信息可以记录下来后面使用,包含用户信息,Token等,本地如果删除data目录,重新启动会有新的生成。

-> Elasticsearch security features have been automatically configured!
-> Authentication is enabled and cluster connections are encrypted.

-> Password for the elastic user (reset with bin/elasticsearch-reset-password -u elastic):
=1WTz10-uoo65zP0qDkP

-> HTTP CA certificate SHA-256 fingerprint:
2395cdb0521b9832270c3ce4c14cb39ae1ccae9ae7e3a34394dccbbe8487c58e

-> Configure Kibana to use this cluster:

  • Run Kibana and click the configuration link in the terminal when Kibana starts.
    • Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
      eyJ2ZXIiOiI4LjUuMiIsImFkciI6WyIxMC4xODEuMy4xNTI6OTIwMCJdLCJmZ3IiOiIyMzk1Y2RiMDUyMWI5ODMyMjcwYzNjZTRjMTRjYjM5YWUxY2NhZTlhZTdlM2EzNDM5NGRjY2JiZTg0ODdjNThlIiwia2
      l0dHlUQTJYUnpqeTR0czM0dyJ9

-> Configure other nodes to join this cluster:

  • On this node:
    • Create an enrollment token with bin/elasticsearch-create-enrollment-token -s node.
    • Uncomment the transport.host setting at the end of config/elasticsearch.yml.
    • Restart Elasticsearch.
  • On other nodes:
    • Start Elasticsearch with bin/elasticsearch --enrollment-token <token>, using the enrollment token that you generated.

默认的账号和密码在日志中:

用户名:elastic,密码:=1WTz10-uoo65zP0qDkP

浏览器访问ES

使用浏览器访问:https://localhost:9200

因为有安全性,会弹出Basic的认证窗口

image-20221213141058342

输入后可以看到服务器信息的json,表示就对了:

{
  "name" : "10390-SDIT",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "pmYKiFFBRQGuobOA23iupQ",
  "version" : {
    "number" : "8.5.2",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "a846182fa16b4ebfcc89aa3c11a11fd5adf3de04",
    "build_date" : "2022-11-17T18:56:17.538630285Z",
    "build_snapshot" : false,
    "lucene_version" : "9.4.1",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

修改密码

按照日志中提示,可以用命令修改密码,应该是要在启动服务的情况下使用:

按照用户设置密码

按照用户设置密码,elastic是超级用户

重置密码(自动生成):elasticsearch-reset-password.bat -u elastic

修改密码(手动修改):elasticsearch-reset-password.bat -u elastic -i

设置内部用户密码

es内置用户用于特定的管理目的用户:apm_system、beats_system、elastic、kibana、logstash_system 、remote_monitoring_user,在使用它们之前,我们必须为它们设置密码。

https://www.elastic.co/guide/en/elasticsearch/reference/8.5/setup-passwords.html

elasticsearch-setup-passwords即将要废弃,以后要使用elasticsearch-reset-password、ES自带API修改密码、或者用Kibana修改

注意:一旦设置过elastic用户的密码之后,这种设置内部用户密码的功能将不能使用了

自动设置:elasticsearch-setup-passwords.bat auto

手动设置:elasticsearch-setup-passwords.bat interactive

Kibana访问ES

下载安装

下载Kibana:https://www.elastic.co/cn/downloads/kibana

文档地址:https://www.elastic.co/guide/en/kibana/current/install.html

Kibana因为使用Node.js开发,目前已经不能在Windows7上运行,放到一台更高版本操作系统上运行,Windows7不支持高版本的Node.js

修改kibana.yml,配置Elasticsearch地址等信息,需要使用kibana用户

server.port: 5601
# 监听端口,默认本机localhost,不能通过其他机器访问
server.host: "0.0.0.0"
#es地址
elasticsearch.hosts: ["https://localhost:9200"]
# 用户名
elasticsearch.username: "kibana"
# 密码
elasticsearch.password: "12345678"
# 语言
i18n.locale: "zh-CN"
elasticsearch.ssl.verificationMode: none

解压后进入文件夹,启动Kibana

启动:bin/kibana.bat

访问Kibana

访问地址:http://localhost:5601

目前测试用kibana用户登录没有权限,要用elastic用户登录

image-20221214101226541

登录kibana账号没有权限:

image-20221214101138636

登录elastic账号成功:

image-20221214101304214

常见问题

Windows下Elasticsearch控制台乱码

修改config/jvm.options文件

增加一行:-Dfile.encoding=GBK

Windows7不支持Kibana

Windows7下运行会报错,就算配置NODE_SKIP_PLATFORM_CHECK=1以后也会有其他错误,似乎只能用更高版本的系统来运行Kibana,或者换Linux

E:\New2022\kibana-8.5.3\bin>kibana.bat
Node.js is only supported on Windows 8.1, Windows Server 2012 R2, or higher.
Setting the NODE_SKIP_PLATFORM_CHECK environment variable to 1 skips this
check, but Node.js might not execute correctly. Any issues encountered on
unsupported platforms will not be fixed.

不能设置内部密码

设置内部密码时报错,其实就是手动或者重置过elastic的密码的就不能在使用此命令

E:\New2022\elasticsearch-8.5.2\bin>elasticsearch-setup-passwords.bat interactive
warning: ignoring JAVA_HOME=C:\softs\Java\jdk11.0.9.1+1; using bundled JDK

Failed to authenticate user 'elastic' against https://10.181.3.152:9200/_security/_authenticate?pretty
Possible causes include:

  • The password for the 'elastic' user has already been changed on this cluster
  • Your elasticsearch node is running against a different keystore
    This tool used the keystore at E:\New2022\elasticsearch-8.5.2\config\elasticsearch.keystore

You can use the elasticsearch-reset-password CLI tool to reset the password of the 'elastic' user

ERROR: Failed to verify bootstrap password

删除/data目录应该可以重新设置。

不过建议用elasticsearch-reset-password -u kibana -i等命令替代。

参考说明:https://www.elastic.co/guide/en/elasticsearch/reference/8.5/setup-passwords.html

elasticsearch-setup-passwords即将要废弃,以后要使用elasticsearch-reset-password、ES自带API修改密码、或者用Kibana修改

Kibana启动错误

Unable to retrieve version information from Elasticsearch nodes. self signed certificate in certificate chain

外部的Kibana访问可能会出现这个错误,应该证书验证问题。

配置kibana.yml中的,不验证ssl证书:

elasticsearch.ssl.verificationMode: none
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇