elasticsearchalreadyLinux

Elasticsearch:添加账户密码并配置可以elastic

2022-04-21  本文已影响0人  前浪浪奔浪流

Elastic 安全是非常重要的。没有这个我们的数据可以被任何的人进行访问,串改,删除。Elastic Stack 的安全是由 x-pack 所提供的。在 Elastic Stack 7.0 版本之前,这个是商用的版本,需要进行安装,并购买。从Elastic Stack 7.0之后,x-pack 都已经在发布版中,所以不需要进行安装。我们只需要进行配置就可以了。

在节点上启用 Elastic 安全功能

使用基本和试用许可证时,默认情况下会禁用 Elasticsearch 安全功能。 要启用它们,首先,我们必须停止所以正在运行的 Elastic Stack 软件:
systemctl stop kibana.service
systemctl stop elasticsearch.service

修改 /etc/elasticsearch/elasticsearch.yml配置文件

#开启密码验证
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.ml.enabled: true
#开启elasticsearch-head的访问
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,Content-Type,X-Requested-with,Content-Length

然后保存退出

重启elasticsearch服务
systemctl start elasticsearch.service

为内置用户编辑创建密码(ES必须是启动状态)

在 Elasticsearch 的安装目录/usr/share/elasticsearch/
里打入如下的命令:

./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/jdk1.8.0_11/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]

你安装提示进行设置。在这个过程中选择你喜欢的密码来设置。

对于一些用户喜欢一个随机的密码,那么你可以使用如下的方式来创建你自己密码:

./bin/elasticsearch-setup-passwords auto
这样它可以帮我生成一些随机的密码。

经过上面的配置后,我们可以在 terminal 中使用如下的方式来进行访问 Elasticsearch:

curl -u elastic:password 'http://localhost:9200'
或者
curl 'http://elastic:password@localhost:9200'
在这里, elastic 是超级用户的用户名,password 是我们设置的密码。我们也可以在浏览器中尝试访问 Elasticsearch:
image.png

ES开启安全密码认证后,es-head连接方式

es-head连接方式
在web界面访问时,该框由原来的 http://172.16.3.227:9100替换为 http://172.16.3.227:9100/?auth_user=elastic&auth_password=123456

image.png
cors解释:Cross Origin Resource Sharing 跨域资源共享

http.cors.enabled 是否支持跨域,默认为false
http.cors.allow-origin 当设置允许跨域,默认为*,表示支持所有域名,如果我们只是允许某些网站能访问,那么可以使用正则表达式。比如只允许本地地址。 /https?:\ /\ /localhost(:[0-9]+)?/
http.cors.max-age 浏览器发送一个“预检”OPTIONS请求,以确定CORS设置。最大年龄定义多久的结果应该缓存。默认为1728000(20天)
http.cors.allow-methods 允许跨域的请求方式,默认OPTIONS,HEAD,GET,POST,PUT,DELETE
http.cors.allow-headers 跨域允许设置的头信息,默认为X-Requested-With,Content-Type,Content-Length
http.cors.allow-credentials 是否返回设置的跨域Access-Control-Allow-Credentials头,如果设置为true,那么会返回给客户端。
上一篇 下一篇

猜你喜欢

热点阅读