I am trying to automatically set the heap size on my ElasticSearch v5.6.3 nodes (Ubuntu 16)
The machines are hosted on Azure and I want to do this so that when I scale up the machine, it automatically sets the heap size to an appropriate level without needing to manually open the /etc/elasticsearch/jvm.options file and set it and then restart the service.
As far as I can work out the suggested ways to set the heap size (in ElasticSearch 5) are:
- In the jvm.options file
- via the ES_JAVA_OPTS environment variable.
So it follows that if I run a script to set the ES_JAVA_OPTS at startup before the elasticsearch service starts.
I tried a lot of things to try and get the ES_JAVA_OPTS to be set but when looking at the logs I can see it was using the default.
I've tried various things:
- editting the /etc/init.d/elasticsearch script and reinstalling the service
- editting the elasticsearch-systemd-pre-exec to set the variable.
- Setting the variable in rc.local
In the end, I have put a script in init.d and used the runlevel to execute it first.
The script updates the jvm.options file using sed like so:
#!/bin/bash
memoryInKb="$(awk '/MemTotal/ {print $2}' /proc/meminfo)"
heapSize="$(expr $memoryInKb / 1024 / 1000 / 2)"
sed -i "s/#*-Xmx[0-9]\+g/-Xmx${heapSize}g/g" /etc/elasticsearch/jvm.options
sed -i "s/#*-Xms[0-9]\+g/-Xms${heapSize}g/g" /etc/elasticsearch/jvm.options
But I think this is really dirty. There must be a nicer way of doing this?
I tried setting the ES_JAVA_OPTS in the same way but it didn't work.
My ultimate aim is make scaling up easier.
0 Answers