diff --git a/docs/role-elasticsearch.md b/docs/role-elasticsearch.md index 37f642e4..693dac09 100644 --- a/docs/role-elasticsearch.md +++ b/docs/role-elasticsearch.md @@ -15,7 +15,7 @@ Role Variables * *elasticsearch_node_types*: List of types of this very node. Please refer to [official docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html) for details. (default: not set. allowed value: array of types) + *elasticsearch_nodename*': Node name of the Elasticsearch node. (default: value of `ansible_hostname`) * *elasticsearch_clustername*: Name the Elasticsearch Cluster (default: `elasticsearch`) -* *elasticsearch_heap*: Heapsize for Elasticsearch. (Half of free memory on host. Maximum 30GB. (default: Half of hosts memory. Min 1GB, Max 30GB) +* *elasticsearch_heap*: Heapsize for Elasticsearch. Set to `false` to follow Elastic recommendations for elasticsearch 8.x (default: Half of hosts memory. Min 1GB, Max 30GB) * *elasticsearch_tls_key_passphrase*: Passphrase for elasticsearch certificates (default: `PleaseChangeMeIndividually`) * *elasticsearch_cert_validity_period*: number of days that the generated certificates are valid (default: 1095). * *elasticsearch_cert_expiration_buffer*: Ansible will renew the elasticsearch certificate if its validity is shorter than this value, which should be number of days. (default: 30) diff --git a/roles/elasticsearch/defaults/main.yml b/roles/elasticsearch/defaults/main.yml index 34089ad6..29aaa0c6 100644 --- a/roles/elasticsearch/defaults/main.yml +++ b/roles/elasticsearch/defaults/main.yml @@ -19,7 +19,6 @@ elasticsearch_pamlimits: true elasticsearch_check_calculation: false elasticsearch_clustername: elasticsearch elasticsearch_conf_dir: "/etc/elasticsearch/" -elasticsearch_config_jvm: "jvm.options.j2" elasticsearch_user: elasticsearch elasticsearch_group: elasticsearch elasticsearch_api_host: localhost diff --git a/roles/elasticsearch/tasks/main.yml b/roles/elasticsearch/tasks/main.yml index 69f8d63c..a1e0c2a2 100644 --- a/roles/elasticsearch/tasks/main.yml +++ b/roles/elasticsearch/tasks/main.yml @@ -203,16 +203,40 @@ - Restart Elasticsearch when: elasticsearch_jna_workaround | bool -- name: Copy jvm.options File +- name: Set jvm heap size become: yes ansible.builtin.template: - src: "{{ elasticsearch_config_jvm }}" - dest: "{{ elasticsearch_conf_dir }}/jvm.options" + src: "jvm.options.d/heap.options.j2" + dest: "{{ elasticsearch_conf_dir }}/jvm.options.d/10-heap.options" owner: root group: "{{ elasticsearch_group }}" mode: "660" force: yes notify: Restart Elasticsearch + when: (elasticsearch_heap) + +- name: Set jvm paths + become: yes + ansible.builtin.template: + src: "jvm.options.d/paths.options.j2" + dest: "{{ elasticsearch_conf_dir }}/jvm.options.d/50-paths.options" + owner: root + group: "{{ elasticsearch_group }}" + mode: "660" + force: yes + notify: Restart Elasticsearch + +- name: Set jvm custom options + become: yes + ansible.builtin.template: + src: "jvm.options.d/custom.options.j2" + dest: "{{ elasticsearch_conf_dir }}/jvm.options.d/90-custom.options" + owner: root + group: "{{ elasticsearch_group }}" + mode: "660" + force: yes + notify: Restart Elasticsearch + when: (elasticsearch_jvm_custom_parameters) # On containerized Debian 10 systemd will not recognize elasticsearch service - name: Force systemd to reread configs on container @@ -285,6 +309,7 @@ - name: Show Info about heap ansible.builtin.debug: msg: "Using {{ elasticsearch_heap | int * 1024 }} of {{ ansible_memtotal_mb }} MB as heap for Elasticsearch" + when: (elasticsearch_heap) - name: Show hint about passwords ansible.builtin.debug: diff --git a/roles/elasticsearch/templates/jvm.options.d/custom.options.j2 b/roles/elasticsearch/templates/jvm.options.d/custom.options.j2 new file mode 100644 index 00000000..0135ca0a --- /dev/null +++ b/roles/elasticsearch/templates/jvm.options.d/custom.options.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} + +{% for item in elasticsearch_jvm_custom_parameters %} +{{ item }} +{% endfor %} diff --git a/roles/elasticsearch/templates/jvm.options.d/heap.options.j2 b/roles/elasticsearch/templates/jvm.options.d/heap.options.j2 new file mode 100644 index 00000000..238cdbdf --- /dev/null +++ b/roles/elasticsearch/templates/jvm.options.d/heap.options.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} +# Xms represents the initial size of total heap space +# Xmx represents the maximum size of total heap space +-Xms{{ elasticsearch_heap }}g +-Xmx{{ elasticsearch_heap }}g diff --git a/roles/elasticsearch/templates/jvm.options.d/paths.options.j2 b/roles/elasticsearch/templates/jvm.options.d/paths.options.j2 new file mode 100644 index 00000000..b12bcd81 --- /dev/null +++ b/roles/elasticsearch/templates/jvm.options.d/paths.options.j2 @@ -0,0 +1,12 @@ +# {{ ansible_managed }} + +# specify an alternative path for heap dumps; ensure the directory exists and +# has sufficient space +-XX:HeapDumpPath={{ elasticsearch_heap_dump_path }} + +# specify an alternative path for JVM fatal error logs +-XX:ErrorFile={{ elasticsearch_logpath }}/hs_err_pid%p.log + +## GC logging +8:-Xloggc:{{ elasticsearch_logpath }}/gc.log +9-:-Xlog:gc*,gc+age=trace,safepoint:file={{ elasticsearch_logpath }}/gc.log:utctime,pid,tags:filecount=32,filesize=64m diff --git a/roles/elasticsearch/templates/jvm.options.j2 b/roles/elasticsearch/templates/jvm.options.j2 deleted file mode 100644 index f85b3deb..00000000 --- a/roles/elasticsearch/templates/jvm.options.j2 +++ /dev/null @@ -1,144 +0,0 @@ -## JVM configuration - -################################################################ -## IMPORTANT: JVM heap size -################################################################ -## -## You should always set the min and max JVM heap -## size to the same value. For example, to set -## the heap to 4 GB, set: -## -## -Xms4g -## -Xmx4g -## -## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html -## for more information -## -################################################################ - -# Xms represents the initial size of total heap space -# Xmx represents the maximum size of total heap space --Xms{{ elasticsearch_heap }}g --Xmx{{ elasticsearch_heap }}g - -{% if elasticstack_release is version('8', '>=') %} -################################################################ -## Expert settings -################################################################ -## -## All settings below here are considered expert settings. Do -## not adjust them unless you understand what you are doing. Do -## not edit them in this file; instead, create a new file in the -## jvm.options.d directory containing your adjustments. -## -################################################################ - --XX:+UseG1GC - -## JVM temporary directory --Djava.io.tmpdir=${ES_TMPDIR} - -# Leverages accelerated vector hardware instructions; removing this may -# result in less optimal vector performance -20:--add-modules=jdk.incubator.vector - -## heap dumps - -# generate a heap dump when an allocation from the Java heap fails; heap dumps -# are created in the working directory of the JVM unless an alternative path is -# specified --XX:+HeapDumpOnOutOfMemoryError - -# exit right after heap dump on out of memory error --XX:+ExitOnOutOfMemoryError - -# specify an alternative path for heap dumps; ensure the directory exists and -# has sufficient space --XX:HeapDumpPath={{ elasticsearch_heap_dump_path }} - -# specify an alternative path for JVM fatal error logs --XX:ErrorFile={{ elasticsearch_logpath }}/hs_err_pid%p.log - -## GC logging --Xlog:gc*,gc+age=trace,safepoint:file={{ elasticsearch_logpath }}/gc.log:utctime,pid,tags:filecount=32,filesize=64m -{% else %} -################################################################ -## Expert settings -################################################################ -## -## All settings below this section are considered -## expert settings. Don't tamper with them unless -## you understand what you are doing -## -################################################################ - -## GC configuration -#{% if elasticstack_release is version('7.6.0', '<') %} -##-XX:+UseConcMarkSweepGC -##-XX:CMSInitiatingOccupancyFraction=75 -##-XX:+UseCMSInitiatingOccupancyOnly -#{% else %} -#8-13:-XX:+UseConcMarkSweepGC -#8-13:-XX:CMSInitiatingOccupancyFraction=75 -#8-13:-XX:+UseCMSInitiatingOccupancyOnly -#{% endif %} - -## G1GC Configuration -# NOTE: G1 GC is only supported on JDK version 10 or later -{% if elasticstack_release is version('7.6.0', '<') %} -# To use G1GC uncomment the lines below. -# 10-:-XX:-UseConcMarkSweepGC -# 10-:-XX:-UseCMSInitiatingOccupancyOnly -# 10-:-XX:+UseG1GC -{% if elasticstack_release is version('7.4.0', '<') %} -# 10-:-XX:InitiatingHeapOccupancyPercent=75 -{% else %} -# 10-:-XX:G1ReservePercent=25 -# 10-:-XX:InitiatingHeapOccupancyPercent=30 -{% endif %} -{% else %} -# to use G1GC, uncomment the next two lines and update the version on the -# following three lines to your version of the JDK -# 10-13:-XX:-UseConcMarkSweepGC -# 10-13:-XX:-UseCMSInitiatingOccupancyOnly -14-:-XX:+UseG1GC -14-:-XX:G1ReservePercent=25 -14-:-XX:InitiatingHeapOccupancyPercent=30 -{% endif %} - -## JVM temporary directory --Djava.io.tmpdir=${ES_TMPDIR} - -## heap dumps - -# generate a heap dump when an allocation from the Java heap fails -# heap dumps are created in the working directory of the JVM --XX:+HeapDumpOnOutOfMemoryError - -# specify an alternative path for heap dumps; ensure the directory exists and -# has sufficient space --XX:HeapDumpPath={{ elasticsearch_heap_dump_path }} - -# specify an alternative path for JVM fatal error logs --XX:ErrorFile={{ elasticsearch_logpath }}/hs_err_pid%p.log - -## JDK 8 GC logging - -8:-XX:+PrintGCDetails -8:-XX:+PrintGCDateStamps -8:-XX:+PrintTenuringDistribution -8:-XX:+PrintGCApplicationStoppedTime -8:-Xloggc:{{ elasticsearch_logpath }}/gc.log -8:-XX:+UseGCLogFileRotation -8:-XX:NumberOfGCLogFiles=32 -8:-XX:GCLogFileSize=64m - -# JDK 9+ GC logging -9-:-Xlog:gc*,gc+age=trace,safepoint:file={{ elasticsearch_logpath }}/gc.log:utctime,pid,tags:filecount=32,filesize=64m -{% endif %} - -{% if elasticsearch_jvm_custom_parameters !='' %} -{% for item in elasticsearch_jvm_custom_parameters %} -{{ item }} -{% endfor %} -{% endif %}