elasticsearch配置

elasticsearch 配置笔记

Elasticsearch has three configuration files:

elasticsearch.yml for configuring Elasticsearch
jvm.options for configuring Elasticsearch JVM settings
log4j2.properties for configuring Elasticsearch logging

ES Server 配置

ES 配置

#自动创建索引
action.auto_create_index: .monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*

可重新加载配置
Just like the settings values in elasticsearch.yml, changes to the keystore contents are not automatically applied to the running Elasticsearch node. Re-reading settings requires a node restart. However, certain secure settings are marked as reloadable.

POST _nodes/reload_secure_settings
POST _nodes/<node_id>/reload_secure_settings
curl -X POST "localhost:9200/_nodes/reload_secure_settings?pretty" -H 'Content-Type: application/json' -d'
{
  "secure_settings_password": "s3cr3t" 
}
'

jvm配置

可以通过配置 jvm.options文件 或 ES_JAVA_OPTS`环境变量配置es jvm

-Xmx16g
8-9:-Xmx20g

ES日志配置

######## Server JSON ############################
appender.rolling.type = RollingFile 
appender.rolling.name = rolling
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_server.json 
appender.rolling.layout.type = ESJsonLayout 
appender.rolling.layout.type_name = server 
appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.json.gz 
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy 
appender.rolling.policies.time.interval = 1 
appender.rolling.policies.time.modulate = true 
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy 
appender.rolling.policies.size.size = 256MB 
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.fileIndex = nomax
appender.rolling.strategy.action.type = Delete 
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.rolling.strategy.action.condition.type = IfFileName 
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* 
appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize 
appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB 
################################################

设置ES log级别

  1. -E logger.org.elasticsearch.transport=trace debug in single node
  2. 修改 elasticsearch.yml logger.org.elasticsearch.transport: info es未启动时配置
  3. 动态修改日志级别 dynamically need to adjust a logging level on an actively-running cluster.
PUT /_cluster/settings
{
  "transient": {
    "logger.org.elasticsearch.transport": "trace"
  }
}
  1. 修改 log4j2.properties
logger.transport.name = org.elasticsearch.transport
logger.transport.level = trace

References

https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/targz.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/secure-settings.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/logging.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/auditing-settings.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-settings.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-settings.html