Skip to content

Commit 971b69f

Browse files
authored
integrate jvm.options template and default variables; #222 (#223)
This PR is for #222 Additional Documenation will be contributed later on. I don't wont to contribute separatly into documentation. It will be done with the contribution for the review. fixes #222
1 parent ddffeea commit 971b69f

File tree

3 files changed

+168
-15
lines changed

3 files changed

+168
-15
lines changed

roles/elasticsearch/defaults/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ elasticsearch_heap: "{{ [[(ansible_memtotal_mb // 1024) // 2, 30] | min, 1] | ma
1818
elasticsearch_pamlimits: true
1919
elasticsearch_check_calculation: false
2020
elasticsearch_clustername: elasticsearch
21+
elasticsearch_conf_dir: "/etc/elasticsearch/"
22+
elasticsearch_config_jvm: "jvm.options.j2"
23+
elasticsearch_user: elasticsearch
24+
elasticsearch_group: elasticsearch
25+
26+
# JVM custom parameters
27+
elasticsearch_java_home: ''
28+
elasticsearch_jvm_custom_parameters: ''
29+
elasticsearch_heap_dump_path: "/var/lib/elasticsearch"
2130

2231
elasticsearch_jna_workaround: false
2332

roles/elasticsearch/tasks/main.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,16 @@
170170
- Restart Elasticsearch
171171
when: elasticsearch_jna_workaround | bool
172172

173-
- name: Set initial heap
174-
lineinfile:
175-
path: /etc/elasticsearch/jvm.options
176-
regexp: '^-Xms'
177-
line: '-Xms{{ elasticsearch_heap }}g'
178-
notify:
179-
- Restart Elasticsearch
180-
181-
- name: Set maximum heap
182-
lineinfile:
183-
path: /etc/elasticsearch/jvm.options
184-
regexp: '^-Xmx'
185-
line: '-Xmx{{ elasticsearch_heap }}g'
186-
notify:
187-
- Restart Elasticsearch
173+
- name: Copy jvm.options File
174+
become: yes
175+
template:
176+
src: "{{ elasticsearch_config_jvm }}"
177+
dest: "{{ elasticsearch_conf_dir }}/jvm.options"
178+
owner: root
179+
group: "{{ elasticsearch_group }}"
180+
mode: "660"
181+
force: yes
182+
notify: Restart Elasticsearch
188183

189184
- name: Start Elasticsearch
190185
service:
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
## JVM configuration
2+
3+
################################################################
4+
## IMPORTANT: JVM heap size
5+
################################################################
6+
##
7+
## You should always set the min and max JVM heap
8+
## size to the same value. For example, to set
9+
## the heap to 4 GB, set:
10+
##
11+
## -Xms4g
12+
## -Xmx4g
13+
##
14+
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
15+
## for more information
16+
##
17+
################################################################
18+
19+
# Xms represents the initial size of total heap space
20+
# Xmx represents the maximum size of total heap space
21+
{% if elasticsearch_heap is defined %}
22+
-Xms{{ elasticsearch_heap }}
23+
-Xmx{{ elasticsearch_heap }}
24+
{% else %}
25+
-Xms2g
26+
-Xmx2g
27+
{% endif %}
28+
29+
{% if elasticstack_release is version('8', '>=') %}
30+
################################################################
31+
## Expert settings
32+
################################################################
33+
##
34+
## All settings below here are considered expert settings. Do
35+
## not adjust them unless you understand what you are doing. Do
36+
## not edit them in this file; instead, create a new file in the
37+
## jvm.options.d directory containing your adjustments.
38+
##
39+
################################################################
40+
41+
-XX:+UseG1GC
42+
43+
## JVM temporary directory
44+
-Djava.io.tmpdir=${ES_TMPDIR}
45+
46+
# Leverages accelerated vector hardware instructions; removing this may
47+
# result in less optimal vector performance
48+
20:--add-modules=jdk.incubator.vector
49+
50+
## heap dumps
51+
52+
# generate a heap dump when an allocation from the Java heap fails; heap dumps
53+
# are created in the working directory of the JVM unless an alternative path is
54+
# specified
55+
-XX:+HeapDumpOnOutOfMemoryError
56+
57+
# exit right after heap dump on out of memory error
58+
-XX:+ExitOnOutOfMemoryError
59+
60+
# specify an alternative path for heap dumps; ensure the directory exists and
61+
# has sufficient space
62+
-XX:HeapDumpPath={{ elasticsearch_heap_dump_path }}
63+
64+
# specify an alternative path for JVM fatal error logs
65+
-XX:ErrorFile={{ elasticsearch_logpath }}/hs_err_pid%p.log
66+
67+
## GC logging
68+
-Xlog:gc*,gc+age=trace,safepoint:file={{ elasticsearch_logpath }}/gc.log:utctime,pid,tags:filecount=32,filesize=64m
69+
{% else %}
70+
################################################################
71+
## Expert settings
72+
################################################################
73+
##
74+
## All settings below this section are considered
75+
## expert settings. Don't tamper with them unless
76+
## you understand what you are doing
77+
##
78+
################################################################
79+
80+
## GC configuration
81+
{% if elasticstack_release is version('7.6.0', '<') %}
82+
-XX:+UseConcMarkSweepGC
83+
-XX:CMSInitiatingOccupancyFraction=75
84+
-XX:+UseCMSInitiatingOccupancyOnly
85+
{% else %}
86+
8-13:-XX:+UseConcMarkSweepGC
87+
8-13:-XX:CMSInitiatingOccupancyFraction=75
88+
8-13:-XX:+UseCMSInitiatingOccupancyOnly
89+
{% endif %}
90+
91+
## G1GC Configuration
92+
# NOTE: G1 GC is only supported on JDK version 10 or later
93+
{% if elasticstack_release is version('7.6.0', '<') %}
94+
# To use G1GC uncomment the lines below.
95+
# 10-:-XX:-UseConcMarkSweepGC
96+
# 10-:-XX:-UseCMSInitiatingOccupancyOnly
97+
# 10-:-XX:+UseG1GC
98+
{% if elasticstack_release is version('7.4.0', '<') %}
99+
# 10-:-XX:InitiatingHeapOccupancyPercent=75
100+
{% else %}
101+
# 10-:-XX:G1ReservePercent=25
102+
# 10-:-XX:InitiatingHeapOccupancyPercent=30
103+
{% endif %}
104+
{% else %}
105+
# to use G1GC, uncomment the next two lines and update the version on the
106+
# following three lines to your version of the JDK
107+
# 10-13:-XX:-UseConcMarkSweepGC
108+
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
109+
14-:-XX:+UseG1GC
110+
14-:-XX:G1ReservePercent=25
111+
14-:-XX:InitiatingHeapOccupancyPercent=30
112+
{% endif %}
113+
114+
## JVM temporary directory
115+
-Djava.io.tmpdir=${ES_TMPDIR}
116+
117+
## heap dumps
118+
119+
# generate a heap dump when an allocation from the Java heap fails
120+
# heap dumps are created in the working directory of the JVM
121+
-XX:+HeapDumpOnOutOfMemoryError
122+
123+
# specify an alternative path for heap dumps; ensure the directory exists and
124+
# has sufficient space
125+
-XX:HeapDumpPath={{ elasticsearch_heap_dump_path }}
126+
127+
# specify an alternative path for JVM fatal error logs
128+
-XX:ErrorFile={{ elasticsearch_logpath }}/hs_err_pid%p.log
129+
130+
## JDK 8 GC logging
131+
132+
8:-XX:+PrintGCDetails
133+
8:-XX:+PrintGCDateStamps
134+
8:-XX:+PrintTenuringDistribution
135+
8:-XX:+PrintGCApplicationStoppedTime
136+
8:-Xloggc:{{ elasticsearch_logpath }}/gc.log
137+
8:-XX:+UseGCLogFileRotation
138+
8:-XX:NumberOfGCLogFiles=32
139+
8:-XX:GCLogFileSize=64m
140+
141+
# JDK 9+ GC logging
142+
9-:-Xlog:gc*,gc+age=trace,safepoint:file={{ elasticsearch_logpath }}/gc.log:utctime,pid,tags:filecount=32,filesize=64m
143+
{% endif %}
144+
145+
{% if elasticsearch_jvm_custom_parameters !='' %}
146+
{% for item in elasticsearch_jvm_custom_parameters %}
147+
{{ item }}
148+
{% endfor %}
149+
{% endif %}

0 commit comments

Comments
 (0)