首先,你要有一套es
$ ./bin/elasticsearch-plugin install x-pack
-> Installing x-pack
-> Failed installing x-pack
ERROR: this distribution of Elasticsearch contains X-Pack by default
这里可以看到,es 7.12版本默认是包含x-pack了,不需要像之前的版本安装了
修改配置文件
$ cp config/elasticsearch.yml{,.bak} '良好的备份习惯,可以有效减少跑路的次数'
$ vim config/elasticsearch.yml '加入下面的参数,然后重启es'
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
设置密码
auto 随机生成一个密码interactive 自定义密码
$ ./bin/elasticsearch-setup-passwords interactive
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]: # 输入 elastic 用户的密码
Reenter password for [elastic]: # 确认 elastic 用户的密码
Enter password for [apm_system]: # 输入 apm_system 用户的密码
Reenter password for [apm_system]: # 确认 apm_system 用户的密码
Enter password for [kibana_system]: # 输入 kibana_system 用户的密码
Reenter password for [kibana_system]: # 确认 kibana_system 用户的密码
Enter password for [logstash_system]: # 输入 logstash_system 用户的密码
Reenter password for [logstash_system]: # 确认 logstash_system 用户的密码
Enter password for [beats_system]: # 输入 beats_system 用户的密码
Reenter password for [beats_system]: # 确认 beats_system 用户的密码
Enter password for [remote_monitoring_user]: # 输入 remote_monitoring_user 用户的密码
Reenter password for [remote_monitoring_user]: # 确认 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]
使用密码
-u 表示使用的用户
$ curl -XGET -u elastic "http://192.168.145.154:9200/_cat/nodes"
Enter host password for user 'elastic': # 这里输入之前设定的密码,密码不是明文显示的
192.168.145.154 52 67 3 0.00 0.15 0.23 cdfhilmrstw * node-1