通过配置阿里云Elasticsearch实例的YML参数,您可以设置允许自动创建索引、删除索引指定名称、配置Auditlog索引、开启Watcher以及其他配置。本文介绍如何配置YML参数,以及CORS访问、reindex白名单、Auditlog索引和queue大小的配置。
注意事项
因阿里云Elasticsearch网络架构调整,2020年10月起创建的实例暂时不支持Watcher、LDAP认证、跨集群Reindex、跨集群搜索、实例网络互通功能,待后期功能上线后开放,请耐心等待。
修改配置
配置CORS访问
通过配置跨域资源共享CORS(Cross-origin resource sharing)访问,设置是否允许其他域资源下的浏览器向阿里云Elasticsearch发送请求。您可以在YML文件配置中,配置CORS访问,支持配置的参数如下。
参数 | 默认值 | 说明 |
---|---|---|
http.cors.enabled | false | 设置是否启用跨域资源访问(Elasticsearch是否允许其他域资源下的浏览器向其发送请求):
|
http.cors.allow-origin | “” | 域资源配置项,可设置接受来自哪些域名的请求。默认不允许接受跨域请求且无配置。支持正则表达式,例如/https?:\/\/localhost(:[0-9]+)?/,表示可响应符合此正则的请求信息。
注意 *是合法配置,表示集群支持来自任意域名的跨域请求,这将会给Elasticsearch实例带来安全风险,不建议使用。
|
http.cors.max-age | 1728000(20天) | 浏览器可发送OPTIONS请求以获取CORS配置信息,此配置项可设置获取的信息在浏览器中的缓存时间,单位为秒。 |
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 | false | 凭证信息配置项目,设置是否允许响应头中返回Access-Control-Allow-Credentials信息:
|
配置reindex白名单
通过当前集群调用reindex API,从远程集群迁移索引数据前,需要先配置reindex白名单。您可以在YML文件配置中,配置reindex白名单,支持配置的参数如下。
参数 | 默认值 | 说明 |
---|---|---|
reindex.remote.whitelist | [] | 设置远程Elasticsearch集群的访问地址,将其添加到当前集群的远程访问白名单中。
白名单支持host和port的组合,并使用逗号分隔多个主机配置(例如otherhost:9200,another:9200,127.0.10.**:9200,localhost:**),不识别协议信息。 |
配置reindex白名单时,如果远程Elasticsearch集群为单可用区的阿里云Elasticsearch实例,请使用<阿里云Elasticsearch实例的域名>:9200;如果为多可用区实例,请使用实例中所有数据节点的IP地址与端口的组合。具体示例如下:
- 单可用区
reindex.remote.whitelist: ["es-cn-09k1rgid9000g****.elasticsearch.aliyuncs.com:9200"]
- 多可用区
reindex.remote.whitelist: ["10.0.xx.xx:9200","10.0.xx.xx:9200","10.0.xx.xx:9200","10.15.xx.xx:9200","10.15.xx.xx:9200","10.15.xx.xx:9200"]
说明 reindex白名单配置完成后,即可调用reindex API重建索引。具体操作,请参见通过reindex迁移数据。
配置Auditlog
您可以在YML文件配置中,开启Elasticsearch的Auditlog索引,查看相关日志文件。开启后,您可以自定义Auditlog配置,示例如下。
xpack.security.audit.index.bulk_size: 5000
xpack.security.audit.index.events.emit_request_body: false
xpack.security.audit.index.events.exclude: run_as_denied,anonymous_access_denied,realm_authentication_failed,access_denied,connection_denied
xpack.security.audit.index.events.include: authentication_failed,access_granted,tampered_request,connection_granted,run_as_granted
xpack.security.audit.index.flush_interval: 180s
xpack.security.audit.index.rollover: hourly
xpack.security.audit.index.settings.index.number_of_replicas: 1
xpack.security.audit.index.settings.index.number_of_shards: 10
配置 | 默认设置 | 说明 |
---|---|---|
xpack.security.audit.index.bulk_size | 1000 | 当您将多个审计事件分批写入到一个Auditlog索引中时,可通过该参数,设置写入事件的数量。 |
xpack.security.audit.index.flush_interval | 1s | 控制缓冲事件刷新到索引的频率。 |
xpack.security.audit.index.rollover | daily | 控制滚动构建到新索引的频率,可以设置为hourly、daily、weekly或monthly。 |
xpack.security.audit.index.events.include | access_denied, access_granted, anonymous_access_denied, authentication_failed, connection_denied, tampered_request, run_as_denied, run_as_granted | 控制何种Auditlog事件可以被写入到索引中。完整事件类型列表,请参见Accesslog事件类型。 |
xpack.security.audit.index.events.exclude | null(默认不处理任何事件) | 构建索引过程中,排除的Auditlog事件。 |
xpack.security.audit.index.events.emit_request_body | false | 当触发明确的事件类型时(例如authentication_failed),是否忽略或包含以REST发送的请求体。 |
注意
- 当Auditlog中包含Requestbody信息时,可能会在日志文件中暴露敏感信息。
- 当开启Auditlog后,Auditlog日志文件将输出到Elasticsearch实例中,并使用.security_audit_log-*开头的索引名称,该索引将占用实例的存储空间。由于Elasticsearch不支持自动过期清除策略,因此需要手动清除旧的Auditlog索引。
您也可以通过xpack.security.audit.index.settings,配置存储Auditlog的索引。以下配置构建Auditlog索引的分片和副本均为1。
xpack.security.audit.index.settings:
index:
number_of_shards: 1
number_of_replicas: 1
说明 如果您希望通过传入配置参数生成Auditlog索引,请在开启Auditlog索引(设置xpack.security.audit.enabled为true)的同时传入此配置。否则,Auditlog索引将使用默认的number_of_shards: 5、number_of_replicas: 1配置。
详细信息,请参见Auditing Security Settings。
配置queue大小
通过自定义queue大小,调整文档写入和搜索的队列大小。您可以在YML文件配置中,配置queue大小。以下示例配置文档写入和搜索queue大小为500和1200,实际业务中请根据具体情况自行调整。
thread_pool.bulk.queue_size: 500
thread_pool.write.queue_size: 500
thread_pool.search.queue_size: 1200
参数 | 默认值 | 说明 |
---|---|---|
thread_pool.bulk.queue_size | 200 | 文档写入队列大小,适用于阿里云Elasticsearch 5.x版本。 |
thread_pool.write.queue_size | 200 | 文档写入队列大小,适用于阿里云Elasticsearch 6.x及7.x版本。 |
thread_pool.search.queue_size | 1000 | 文档搜索队列大小。 |