如何修复 ElasticSearch [1]: initial heap size [...] not equal to maximum heap size [...];

问题:

你的 ElasticSearch 服务器启动失败,出现类似这样的错误消息

output.txt
ERROR: [1] bootstrap checks failed
[1]: initial heap size [536870912] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents memory locking from locking the entire heap
ERROR: Elasticsearch did not exit normally - check the logs at /usr/share/elasticsearch/logs/docker-cluster.log

解决方案

将初始堆大小设置为等于最大堆大小:-Xms 参数和 -Xmx 参数必须相等,例如:

jvm_opts.txt
-Xms2048m -Xmx2048m

通常(例如在基于 docker 的设置中)你可以在 ES_JAVA_OPTS 中设置:

env_vars.txt
ES_JAVA_OPTS=-Xms2048m -Xmx2048m

对于基于 docker-compose 的环境,这是一个有效的示例配置:

docker-compose.yml
environment:
    - cluster.name=docker-cluster
    - node.name=elasticsearch1
    - cluster.initial_master_nodes=elasticsearch1
    - bootstrap.memory_lock=true
    - http.cors.allow-origin=http://localhost:1358,http://127.0.0.1:1358
    - http.cors.enabled=true
    - http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
    - http.cors.allow-credentials=true
    - "ES_JAVA_OPTS=-Xms2048m -Xmx2048m"

之后,重启你的 ElasticSearch 实例。


Check out similar posts by category: ElasticSearch