1、最小主节点数

防止集群发生脑裂,计算方式:( master 候选节点个数 / 2) + 1

Elasticsearch主要配置及性能调优_第1张图片


可以通过修改配置文件elasticsearch.yml

discovery.zen.minimum_master_nodes: 2


或者通过api接口动态修改

curl -XPUT 'http://127.0.0.1:9200/_cluster/settings' -d '
{
    "persistent" : {
        "discovery.zen.minimum_master_nodes" : 2
    }
}'


2、集群恢复配置

gateway.recover_after_nodes: 8  ##Elasticsearch 在存在至少 8 个节点(数据节点或者 master 节点)才进行数据恢复
gateway.expected_nodes: 10      ##集群有多少个节点
gateway.recover_after_time: 5m  ##等待节点多长时间

上面三个参数意味着

等待集群至少存在 8 个节点

等待 5 分钟,或者10 个节点上线后,才进行数据恢复,这取决于哪个条件先达到。


3、最好使用单播

discovery.zen.ping.unicast.hosts: ["host1", "host2:port"]



4、堆内存:大小和交换

根据《Elasticsearch官网》所说分配机器的的一半内存给Lucene,并且不要超过32GB给Elasticsearch;并且避免Elasticsearch使用Swap空间

Elasticsearch主要配置及性能调优_第2张图片

Elasticsearch主要配置及性能调优_第3张图片

Elasticsearch主要配置及性能调优_第4张图片


5、线程池

非必要尽量避免修改线程池,实在需要修改尽量避免超过CPU核心数2倍,官网原文如下:

Elasticsearch主要配置及性能调优_第5张图片


参考资料:

1、https://www.elastic.co/blog/a-heap-of-trouble

2、https://www.elastic.co/guide/cn/elasticsearch/guide/current/important-configuration-changes.html

3、https://elasticsearch.cn/question/3995