From 5a91e6944ed04f1ab8f453bb5f797eff76d7096b Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Tue, 14 Feb 2017 16:48:50 +0100 Subject: [PATCH] library/roles/ELK/elasticsearch: Compatibility fixes for version 5.x. Version 5.x is now the default. --- ELK/elasticsearch/defaults/main.yml | 22 +++-- ELK/elasticsearch/tasks/elasticsearch.yml | 37 ++++---- ELK/elasticsearch/tasks/plugins.yml | 7 +- .../templates/elasticsearch.yml.j2 | 4 +- ELK/elasticsearch/templates/jvm.options.j2 | 95 +++++++++++++++++++ 5 files changed, 139 insertions(+), 26 deletions(-) create mode 100644 ELK/elasticsearch/templates/jvm.options.j2 diff --git a/ELK/elasticsearch/defaults/main.yml b/ELK/elasticsearch/defaults/main.yml index f59fee99..f7674f4b 100644 --- a/ELK/elasticsearch/defaults/main.yml +++ b/ELK/elasticsearch/defaults/main.yml @@ -1,9 +1,11 @@ --- elasticsearch_repo_key: https://packages.elastic.co/GPG-KEY-elasticsearch -elasticsearch_repo: 'deb http://packages.elastic.co/elasticsearch/2.x/debian stable main' +elasticsearch_repo_version: 5.x +elasticsearch_repo: 'deb http://packages.elastic.co/elasticsearch/{{ elasticsearch_repo_version }}/debian stable main' elasticsearch_packages: - elasticsearch +elasticsearch_package_state: 'present' elasticsearch_cluster_name: 'Elasticsearch Cluster' elasticsearch_enabled: True elasticsearch_http_port: 9200 @@ -11,15 +13,23 @@ elasticsearch_data_dir: /var/lib/elasticsearch elasticsearch_log_dir: /var/log/elasticsearch elasticsearch_bind_ip: 127.0.0.1 elasticsearch_discovery_host_list: '["127.0.0.1", "[::1]"]' -elasticsearch_define_majority_of_nodes: False -elasticsearch_majority_of_nodes: 3 +elasticsearch_define_majority_of_nodes: True +elasticsearch_majority_of_nodes: 1 +elasticsearch_real_cluster: False elasticsearch_recover_after_nodes: 3 elasticsearch_max_local_storage_nodes: 1 -elasticsearch_destructive_requires_name: True +elasticsearch_destructive_requires_name: 'true' elasticsearch_define_heap_size: False elasticsearch_heap_size: 2g elasticsearch_additional_java_opts: '' -elasticsearch_max_open_files: 65535 +elasticsearch_max_open_files: 65536 -elasticsearch_plugins: +# bin/plugin for 2.x, bin/elasticsearch-plugin for 5.x +elasticsearch_plugin_bin: /usr/share/elasticsearch/bin/elasticsearch-plugin +#elasticsearch_plugins: +# - { name: 'royrusso/elasticsearch-HQ', state: 'present' } + +# elasticsearch 5 not supported yet +elasticsearch_hq_install: False +elasticsearch_hq_plugin: - { name: 'royrusso/elasticsearch-HQ', state: 'present' } diff --git a/ELK/elasticsearch/tasks/elasticsearch.yml b/ELK/elasticsearch/tasks/elasticsearch.yml index 06ff279e..543b66d8 100644 --- a/ELK/elasticsearch/tasks/elasticsearch.yml +++ b/ELK/elasticsearch/tasks/elasticsearch.yml @@ -1,24 +1,25 @@ --- -- name: Install the elasticsearch repo key - apt_key: url={{ elasticsearch_repo_key }} state=present - tags: [ 'ELK', 'elasticsearch', 'elk' ] +- block: + - name: Install the elasticsearch repo key + apt_key: url={{ elasticsearch_repo_key }} state=present -- name: Install the elasticsearch deb repository - apt_repository: repo='{{ elasticsearch_repo }}' state=present update_cache=yes - tags: [ 'ELK', 'elasticsearch', 'elk' ] + - name: Install the elasticsearch deb repository + apt_repository: repo='{{ elasticsearch_repo }}' state=present update_cache=yes -- name: Install the elasticsearch deb packages - apt: name='{{ item }}' state=present - with_items: '{{ elasticsearch_packages }}' - tags: [ 'ELK', 'elasticsearch', 'elk' ] + - name: Install the elasticsearch deb packages + apt: name='{{ item }}' state={{ elasticsearch_package_state }} update_cache=yes cache_valid_time=1800 + with_items: '{{ elasticsearch_packages }}' -- name: Install the elasticsearch startup default - template: src=elasticsearch-default.j2 dest=/etc/default/elasticsearch owner=root group=elasticsearch mode=0640 - notify: Restart elasticsearch - tags: [ 'ELK', 'elasticsearch', 'elk' ] + - name: Install the elasticsearch startup default + template: src=elasticsearch-default.j2 dest=/etc/default/elasticsearch owner=root group=elasticsearch mode=0640 + notify: Restart elasticsearch -- name: Install the elasticsearch configuration - template: src=elasticsearch.yml.j2 dest=/etc/elasticsearch/elasticsearch.yml owner=root group=elasticsearch mode=0640 - notify: Restart elasticsearch - tags: [ 'ELK', 'elasticsearch', 'elk' ] + - name: Install the elasticsearch JVM options + template: src=jvm.options.j2 dest=/etc/elasticsearch/jvm.options owner=root group=elasticsearch mode=0640 + notify: Restart elasticsearch + - name: Install the elasticsearch configuration + template: src=elasticsearch.yml.j2 dest=/etc/elasticsearch/elasticsearch.yml owner=root group=elasticsearch mode=0640 + notify: Restart elasticsearch + + tags: [ 'ELK', 'elasticsearch', 'elk' ] diff --git a/ELK/elasticsearch/tasks/plugins.yml b/ELK/elasticsearch/tasks/plugins.yml index 4b3f199e..b274db5d 100644 --- a/ELK/elasticsearch/tasks/plugins.yml +++ b/ELK/elasticsearch/tasks/plugins.yml @@ -1,9 +1,14 @@ --- - block: - name: Manage a list of elasticsearch plugins - elasticsearch_plugin: name="{{ item.name }}" state={{ item.state }} url={{ item.url|default(omit) }} version={{ item.version|default(omit) }} + elasticsearch_plugin: name="{{ item.name }}" state={{ item.state }} plugin_bin={{ elasticsearch_plugin_bin }} url={{ item.url|default(omit) }} version={{ item.version|default(omit) }} with_items: '{{ elasticsearch_plugins | default ([]) }}' + - name: Install the elasticsearch HQ plugin + elasticsearch_plugin: name="{{ item.name }}" state={{ item.state }} plugin_bin={{ elasticsearch_plugin_bin }} url={{ item.url|default(omit) }} version={{ item.version|default(omit) }} + with_items: '{{ elasticsearch_hq_plugin | default ([]) }}' + when: elasticsearch_hq_install + when: elasticsearch_plugins is defined tags: [ 'elasticsearch', 'es_plugins' ] diff --git a/ELK/elasticsearch/templates/elasticsearch.yml.j2 b/ELK/elasticsearch/templates/elasticsearch.yml.j2 index 9b3a44f4..cd34bca2 100644 --- a/ELK/elasticsearch/templates/elasticsearch.yml.j2 +++ b/ELK/elasticsearch/templates/elasticsearch.yml.j2 @@ -77,16 +77,18 @@ discovery.zen.minimum_master_nodes: {{ elasticsearch_majority_of_nodes }} # For more information, see the documentation at: # # +{% if elasticsearch_real_cluster %} # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # -gateway.recover_after_nodes: +gateway.recover_after_nodes: {{ elasticsearch_recover_after_nodes }} # # For more information, see the documentation at: # # {% endif %} +{% endif %} # ---------------------------------- Various ----------------------------------- # # Disable starting multiple nodes on a single system: diff --git a/ELK/elasticsearch/templates/jvm.options.j2 b/ELK/elasticsearch/templates/jvm.options.j2 new file mode 100644 index 00000000..097abc76 --- /dev/null +++ b/ELK/elasticsearch/templates/jvm.options.j2 @@ -0,0 +1,95 @@ +## 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_size }} +-Xmx{{ elasticsearch_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 + +# disable calls to System#gc +-XX:+DisableExplicitGC + +# pre-touch memory pages used by the JVM during initialization +-XX:+AlwaysPreTouch + +## basic + +# force the server VM +-server + +# 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 + +# flag to explicitly tell Netty to not use unsafe +-Dio.netty.noUnsafe=true + +## 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=${heap.dump.path} + +## GC logging + +#-XX:+PrintGCDetails +#-XX:+PrintGCTimeStamps + +#-XX:+PrintGCDateStamps +#-XX:+PrintClassHistogram +#-XX:+PrintTenuringDistribution +#-XX:+PrintGCApplicationStoppedTime + +# log GC status to a file with time stamps +# ensure the directory exists +#-Xloggc:${loggc} + +# Elasticsearch 5.0.0 will throw an exception on unquoted field names in JSON. +# If documents were already indexed with unquoted fields in a previous version +# of Elasticsearch, some operations may throw errors. +# +# WARNING: This option will be removed in Elasticsearch 6.0.0 and is provided +# only for migration purposes. +#-Delasticsearch.json.allow_unquoted_field_names=true