如何更改Elasticsearch最大内存大小

我有一个默认configuration的Elasticsearch的Apache服务器,除了默认configuration的最大大小为1GB,一切都可以正常工作。

我没有如此大量的文件存储在Elasticsearch中,所以我想减less内存。

我已经看到,我不得不在Javaconfiguration中更改-Xmx参数,但我不知道如何。

我看到我可以执行此操作:

 bin/ElasticSearch -Xmx=2G -Xms=2G 

但是当我必须重新启动Elasticsearch时,这将会丢失。

将Elasticsearch作为服务安装时,是否可以更改最大内存使用量?

2016年11月24日更新 :Elasticsearch 5显然改变了configurationJVM的方式。 在这里看到这个答案 。 下面的答案仍适用于版本<5。

tirdadc,谢谢你在下面的评论中指出这一点。


我有一个pastebin页面,当我想知道内存和ES时,我会与其他人分享。 这对我有用 : http : //pastebin.com/mNUGQCLY 。 我也将粘贴这里的内容:

参考文献:

https://github.com/grigorescu/Brownian/wiki/ElasticSearch-Configuration http://www.elasticsearch.org/guide/reference/setup/installation/

编辑以下文件以修改内存和文件数量限制。 这些说明假设Ubuntu 10.04,可能在更高版本和其他发行版/操作系统上工作。 ( 编辑 :这也适用于Ubuntu 14.04。)

/etc/security/limits.conf

 elasticsearch - nofile 65535 elasticsearch - memlock unlimited 

/ etc / default / elasticsearch(在CentOS / RH上:/ etc / sysconfig / elasticsearch)

 ES_HEAP_SIZE=512m MAX_OPEN_FILES=65535 MAX_LOCKED_MEMORY=unlimited 

/etc/elasticsearch/elasticsearch.yml

 bootstrap.mlockall: true 

ElasticSearch 5中 ,文档已经改变了 ,这意味着上面的答案都不适用于我。

我试着在/etc/default/elasticsearch ES_HEAP_SIZEetc/init.d/elasticsearch ES_HEAP_SIZE中更改ES_HEAP_SIZE ,但是当我运行ps aux | grep elasticsearch ps aux | grep elasticsearch的输出还显示:

/usr/bin/java -Xms2g -Xmx2g # aka 2G min and max ram

我不得不做出这些变化:

/etc/elasticsearch/jvm.options

 # Xms represents the initial size of total heap space # Xmx represents the maximum size of total heap space -Xms1g -Xmx1g # the settings shipped with ES 5 were: -Xms2g # the settings shipped with ES 5 were: -Xmx2g 

对于任何想在Centos 7上执行此操作或者在运行SystemD的其他系统上执行此操作的用户,都可以将其更改为

 /etc/sysconfig/elasticsearch 

取消注释ES_HEAP_SIZE行,并设置一个值,例如:

 # Heap Size (defaults to 256m min, 1g max) ES_HEAP_SIZE=16g 

(忽略关于1g max的评论 – 这是默认的)

以前的答案在我的情况下是不够的,可能是因为我在Debian 8上,而他们被引用到以前的一些分布。

Debian 8上修改通常放在/usr/lib/systemd/system/elasticsearch.service中的服务脚本,并在其他“Environment = *”行下面添加Environment=ES_HEAP_SIZE=8G

现在使用systemctl daemon-reload重新加载服务脚本并重新启动服务。 工作应该完成!

如果您使用位于https://github.com/elasticsearch/elasticsearch-servicewrapper的; Elasticsearch的Github存储库中提供的服务包装,那么位于elasticsearch-servicewrapper / service / elasticsearch.conf的conf文件将控制内存设置。 在elasticsearch.conf的顶部是一个参数:

 set.default.ES_HEAP_SIZE=1024 

只要减less这个参数,比如说“set.default.ES_HEAP_SIZE = 512”,就可以减lessElasticsearch的分配内存。

请注意,如果您使用elasticsearch-wrapper,则elasticsearch.conf中提供的ES_HEAP_SIZE将覆盖所有其他设置。 这使我想了一下,因为从文档来看,似乎可以从elasticsearch.yml中设置堆内存。

如果你的服务包装设置被设置在其他地方,比如在James的例子中的/ etc / default / elasticsearch,那么在那里设置ES_HEAP_SIZE。

如果您使用所提供的RPM / DEB软件包来安装ES,您可以通过编辑初始化脚本(RHEL / CentOS上的/etc/init.d/elasticsearch)来进行调整。 如果你看看这个文件,你会看到一个包含以下内容的块:

 export ES_HEAP_SIZE export ES_HEAP_NEWSIZE export ES_DIRECT_SIZE export ES_JAVA_OPTS export JAVA_HOME 

要resize,只需将ES_HEAP_SIZE行更改为以下内容:

 export ES_HEAP_SIZE=xM/xG 

(其中x是你想要分配的RAM的MB / GB的数量)

例:

 export ES_HEAP_SIZE=1G 

将分配1GB。

编辑脚本后,保存并退出,然后重新启动服务。 您可以通过运行以下命令来检查它是否被正确设置:

 ps aux | grep elasticsearch 

然后检查返回的java进程中的-Xms和-Xmx标志:

 /usr/bin/java -Xms1G -Xmx1G 

希望这可以帮助 :)

ubuntu 14.04说明:

sudo vim /etc/init.d/elasticsearch

ES_HEAP_SIZE=512m

然后在:

sudo vim /etc/elasticsearch/elasticsearch.yml

组:

bootstrap.memory_lock: true

有更多的信息在文件中的评论

如果您使用Windows Server,则可以更改环境variables,重新启动服务器以应用新的环境值并启动Elastic Service。 在Windows Server中安装Elastic的更多详细信息

在弹性searchpath家目录,即通常是/ usr / share / elasticsearch,有一个configuration文件bin / elasticsearch.in.sh。 在该文件中编辑参数ES_MIN_MEM,ES_MAX_MEM分别更改-Xms2g,-Xmx4g。 请确保在更改configuration后重新启动了节点。