From 69ee71f540c2302e0b5485b8be116a345662f9e4 Mon Sep 17 00:00:00 2001 From: Antsiferov Grigory Date: Sun, 25 Feb 2018 09:02:49 +0300 Subject: [PATCH] Add elasticsearch jvm.options template and states --- sls/elasticsearch/config.sls | 20 ++++++-- sls/elasticsearch/files/jvm.options.tpl | 62 +++++++++++++++++++++++++ sls/elasticsearch/init.sls | 1 + 3 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 sls/elasticsearch/files/jvm.options.tpl diff --git a/sls/elasticsearch/config.sls b/sls/elasticsearch/config.sls index f0d8463..5cad082 100644 --- a/sls/elasticsearch/config.sls +++ b/sls/elasticsearch/config.sls @@ -10,10 +10,16 @@ fqdn = __salt__['grains.get']('fqdn') fqdn_ipv6 = __salt__['grains.get']('fqdn_ipv6') hosts = __salt__['pillar.get']('elastic:hosts', []) -l_nofile = __salt__['pillar.get']('elastic:limits:nofile', 1048576) -l_memlock = __salt__['pillar.get']('elastic:limits:memlock', 'unlimited') -max_map_count = __salt__['pillar.get']('elastic:limits:max_map_count', 262144) -max_threads = __salt__['pillar.get']('elastic:limits:max_threads', 4096) +limits = __salt__['pillar.get']('elastic:limits', {}) +l_nofile = limits.get('nofile', 1048576) +l_memlock = limits.get('memlock', 'unlimited') +max_map_count = limits.get('max_map_count', 262144) +max_threads = limits.get('max_threads', 4096) + +jvm = __salt__['pillar.get']('elastic:jvm', {}) +jvm_heap_size = jvm.get('heap_size', '2g') +jvm_stack_size = jvm.get('stack_size', '1m') +jvm_extra_options = jvm.get('extra_options', {}) # defaults config = { @@ -45,6 +51,12 @@ state('/etc/elasticsearch/elasticsearch.yml').file.managed( mode=644, user='root', group='root', contents="# This file is generated by Salt\n" + yaml.dump(config)) +state('/etc/elasticsearch/jvm.options').file.managed( + mode=644, user='root', group='root', + template='jinja', source='salt://elasticsearch/files/jvm.options.tpl', + defaults={'heap_size': jvm_heap_size, 'stack_size': jvm_stack_size, + 'extra_options': jvm_extra_options}) + state('/etc/conf.d/elasticsearch').file.managed( mode=644, user='root', group='root', template='jinja', source="salt://elasticsearch/files/elasticsearch.confd.tpl", diff --git a/sls/elasticsearch/files/jvm.options.tpl b/sls/elasticsearch/files/jvm.options.tpl new file mode 100644 index 0000000..451076f --- /dev/null +++ b/sls/elasticsearch/files/jvm.options.tpl @@ -0,0 +1,62 @@ +## Managed by Salt +## JVM configuration + +# Xms represents the initial size of total heap space +# Xmx represents the maximum size of total heap space +## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html + +-Xms{{ heap_size }} +-Xmx{{ heap_size }} + +## 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 +-XX:+UseConcMarkSweepGC +-XX:CMSInitiatingOccupancyFraction=75 +-XX:+UseCMSInitiatingOccupancyOnly + +## optimizations + +# pre-touch memory pages used by the JVM during initialization +-XX:+AlwaysPreTouch + +## basic + +# force the server VM +-server + +# explicitly set the stack size +-Xss{{ stack_size }} + +# set to headless, just in case +-Djava.awt.headless=true + +# ensure UTF-8 encoding by default (e.g. filenames) +-Dfile.encoding=UTF-8 + +# use our provided JNA always versus the system one +-Djna.nosys=true + +# turn off a JDK optimization that throws away stack traces for common +# exceptions because stack traces are important for debugging +-XX:-OmitStackTraceInFastThrow + +# flags to configure Netty +-Dio.netty.noUnsafe=true +-Dio.netty.noKeySetOptimization=true +-Dio.netty.recycler.maxCapacityPerThread=0 + +# log4j 2 +-Dlog4j.shutdownHookEnabled=false +-Dlog4j2.disable.jmx=true + +{% for key, value in extra_options.items() %} +-{{ key }}{{ '='+value if value else '' }} +{% endfor %} diff --git a/sls/elasticsearch/init.sls b/sls/elasticsearch/init.sls index 87999e7..070ce76 100644 --- a/sls/elasticsearch/init.sls +++ b/sls/elasticsearch/init.sls @@ -10,5 +10,6 @@ elasticsearch: - pkg: icedtea3 - pkg: elasticsearch_pkg - file: /etc/elasticsearch/elasticsearch.yml + - file: /etc/elasticsearch/jvm.options - file: /etc/security/limits.d/elasticsearch.conf - file: /etc/conf.d/elasticsearch