ES elasticsearch安装(8.17)

时间:2025-01-20 07:20:33

1、下载windows安装包,当前版本8.17

Download Elasticsearch | Elastic

2、启动,验证

bin目录下面,elasticsearch.bat 命令为其中命令;在启动之前需要先进行配置

2.1、config目录,jvm.options,降低默认内存使用配置,我本地使用默认配置卡

## -Xms4g
## -Xmx4g
需要改成
-Xms2g
-Xmx2g

2.2、config目录,elasticsearch.yml

# 下面两个改为false,设置为ture需要登录
xpack.security.enabled: false
xpack.security.enrollment.enabled: false


# 下面两个改为false,为true需要https登录
xpack.security.http.ssl:
  enabled: false

xpack.security.transport.ssl:
  enabled: false

启动后,http://localhost:9200,

刚开始会报错闪退,cmd到黑窗口执行elasticsearch.bat,提示

No found jdk lib下面的tools.jar

我本地安装jdk17,该版本lib目录下面已经没有tools.jar了

解决方法:将jdk1.8里面的tools.jar复制到对应的目录。这样算是把问题解决了。

显示如下内容

{
  "name" : "DESKTOP-2MKC0A1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "Cq9-MG7fQlmeB8JTCAm90A",
  "version" : {
    "number" : "8.17.0",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "2b6a7fed44faa321997703718f07ee0420804b41",
    "build_date" : "2024-12-11T12:08:05.663969764Z",
    "build_snapshot" : false,
    "lucene_version" : "9.12.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

3、默认访问http://localhost:9200,需要登录的,默认用户elastic,但是密码却没有默认的

3.1、重置elastic密码,

使用命令 elasticsearch-reset-password --username elastic

这样新的密码就显示在下面,可以这样密码很繁琐

C:\Users\HP\Downloads\elasticsearch-8.17.0\bin>elasticsearch-reset-password -u elastic
warning: ignoring JAVA_HOME=D:\java\jdk17; using bundled JDK
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y


Password for the [elastic] user successfully reset.
New value: xUvsSUv0W4+Rde*JE-ty

3.2、修改用户的密码。

 使用命令 elasticsearch-reset-password --username elastic -i

C:\Users\HP\Downloads\elasticsearch-8.17.0\bin>elasticsearch-reset-password --username elastic -i
warning: ignoring JAVA_HOME=D:\java\jdk17; using bundled JDK
This tool will reset the password of the [elastic] user.
You will be prompted to enter the password.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]:
Re-enter password for [elastic]:
Password for the [elastic] user successfully reset.

4、安装ES-head,它是一个elasticsearch的web界面工具

4.1、安装准备,需要本地node.js

4.2、通过node.js 安装grunt

C:\Users\HP\Downloads\elasticsearch-8.17.0\bin>node --version
v20.11.0

C:\Users\HP\Downloads\elasticsearch-8.17.0\bin>npm install -g grunt-cli

added 56 packages in 5s

5 packages are looking for funding
  run `npm fund` for details
npm notice
npm notice New major version of npm available! 10.5.0 -> 11.0.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.0.0
npm notice Run npm install -g npm@11.0.0 to update!
npm notice

C:\Users\HP\Downloads\elasticsearch-8.17.0\bin>grunt -version
grunt-cli v1.5.0

4.3、下载es-head源码

https://github.com/mobz/elasticsearch-head

 查看redme操作,如果本地没有git的,可以直接下载

Running with built in server
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
open http://localhost:9100/

4.4、访问http://localhost:9100, 提示连不上http://localhost:9200,是因为elasticsearch默认配置不能跨域访问,需要修改配置

# 增加配置,允许跨域,这样head插件可以访问es
http.cors.enabled: true 
http.cors.allow-origin: "*"
@注意,设置参数的时候:后面要有空格

4.5、提示还是不能连接elasticsearch服务,此时访问的地址为http://localhost:9100,需要加上用户名和密码参数 http://localhost:9100?auth_user=elastic&auth_password=elastic