修改elasticsearch.yml配置文件

以单机实例为例,原配置文件

1
2
3
4
5
6
cluster.name: elasticsearch
node.name: es-node-1
path.data: /data/elasticsearch-7.17.1/data
path.logs: /data/elasticsearch-7.17.1/logs
network.host: 0.0.0.0
cluster.initial_master_nodes: ["es-node-1"]

修改后配置文件如下:

1
2
3
4
5
6
7
8
cluster.name: elasticsearch
node.name: es-node-1
path.data: /data/elasticsearch-7.17.1/data
path.logs: /data/elasticsearch-7.17.1/logs
network.host: 0.0.0.0
- cluster.initial_master_nodes: ["es-node-1"] #这一行注释掉,因为它和下一行的single-node冲突
+ discovery.type: single-node
+ xpack.security.enabled: true

重新启动elsticsearch服务

1
./bin/elasticsearch -d

交互式重置各用户密码

1
./bin/elasticsearch-setup-passwords interactive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[es@test elasticsearch-7.17.1]$ ./bin/elasticsearch-setup-passwords interactive
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,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_system]:
Reenter password for [kibana_system]:
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_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]

重置密码后浏览器验证

输入账号密码
成功登录