ElasticSearch 7.1 Tips
ElasticSearch 部署建议
- 推荐使用 es 自带的 jdk
- 建议手动安装或者使用 ansible
ES 配置
- elasticsearch.yml for configuring Elasticsearch
- jvm.options for configuring Elasticsearch JVM settings
- log4j2.properties for configuring Elasticsearch logging
通用配置
-
jvm 推荐内存 64g , cms heap 31g, young 2g
-
secure (内网可选)
-
logging logging
重点 ES 配置
path
- path.log
- path.data
配置目录,最好使用不同的独立磁盘, log 和 data 分离, data 可配置多个路径
e.g
path:
logs: /var/log/elasticsearch
data: /var/data/elasticsearch
---
path:
logs: /var/log/elasticsearch
data:
- /mnt/es1
- /mnt/es2
cluster.name
用来区分不同的集群
e.g
cluster.name: test
node.name
用来区分集群内的不同机器,建议使用人类可读可理解的命名
node.name: test-one
network.host
默认情况下,es 使用 127.0.0.1,当给定了指定值时,es 会认为该实例处于生产模式。
建议使用内网 ipv4 地址, 不要使用 0.0.0.0, 以避免不小心暴露到公网。
e.g
network.host: 192.168.1.10
discovery and cluster
集群发现与集群配置
discovery.seed_hosts 如果是集群的第一个节点,配置为空,如果是加入已有节点,配置为集群的 master 节点列表
e.g
discovery.seed_hosts:
- 192.168.1.10:9300
cluster.initial_master_nodes 创建新集群是的初始配置,后续添加节点或者重启节点需要移除此配置
You should not use this setting when restarting a cluster or adding a new node to an existing cluster
e.g
cluster.initial_master_nodes:
- test-1
- test-2
- test-3
jvm heap.size
- Set the minimum heap size (Xms) and maximum heap size (Xmx) to be equal to each other.
- The more heap available to Elasticsearch, the more memory it can use for caching. But note that too much heap can subject you to long garbage collection pauses.
- Set Xmx to no more than 50% of your physical RAM, to ensure that there is enough physical RAM left for kernel file system caches.
- Don’t set Xmx to above the cutoff that the JVM uses for compressed object pointers (compressed oops); the exact cutoff varies but is near 32 GB. You can verify that you are under the limit by looking for a line in the logs like the following: heap size [1.9gb], compressed ordinary object pointers [true] Even better, try to stay below the threshold for zero-based compressed oops; the exact cutoff varies but 26 GB is safe on most systems, but can be as large as 30 GB on some systems. You can verify that you are under the limit by starting Elasticsearch with the JVM options -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode and looking for a line like the following: heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops showing that zero-based compressed oops are enabled instead of heap address: 0x0000000118400000, size: 28672 MB, Compressed Oops with base: 0x00000001183ff000
- 禁用动态堆扩展
- heap size 小于物理内存的一半
- 不要触发 JVM 压缩指针的阈值
e.g
-Xms31g
-Xmx31g
jvm dump.path
oom 时推转储文件的存储位置,建议配置到 log 目录下
e.g
-XX:HeapDumpPath=data
-XX:HeapDumpPath=logs
-XX:ErrorFile=logs/hs_err_pid%p.log
gc logging
建议配置到 log 目录下
e.g
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+AlwaysPreTouch
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistributi