Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions roles/elasticsearch/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ elasticsearch_heap: "{{ [[(ansible_memtotal_mb // 1024) // 2, 30] | min, 1] | ma
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

# JVM custom parameters
elasticsearch_java_home: ''
elasticsearch_jvm_custom_parameters: ''
elasticsearch_heap_dump_path: "/var/lib/elasticsearch"

elasticsearch_jna_workaround: false

Expand Down
25 changes: 10 additions & 15 deletions roles/elasticsearch/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,16 @@
- Restart Elasticsearch
when: elasticsearch_jna_workaround | bool

- name: Set initial heap
lineinfile:
path: /etc/elasticsearch/jvm.options
regexp: '^-Xms'
line: '-Xms{{ elasticsearch_heap }}g'
notify:
- Restart Elasticsearch

- name: Set maximum heap
lineinfile:
path: /etc/elasticsearch/jvm.options
regexp: '^-Xmx'
line: '-Xmx{{ elasticsearch_heap }}g'
notify:
- Restart Elasticsearch
- name: Copy jvm.options File
become: yes
template:
src: "{{ elasticsearch_config_jvm }}"
dest: "{{ elasticsearch_conf_dir }}/jvm.options"
owner: root
group: "{{ elasticsearch_group }}"
mode: "660"
force: yes
notify: Restart Elasticsearch

- name: Start Elasticsearch
service:
Expand Down
149 changes: 149 additions & 0 deletions roles/elasticsearch/templates/jvm.options.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
## 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
{% if elasticsearch_heap is defined %}
-Xms{{ elasticsearch_heap }}
-Xmx{{ elasticsearch_heap }}
{% else %}
-Xms2g
-Xmx2g
{% endif %}

{% 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 %}