diff --git a/elasticsearch/.gitkeep b/elasticsearch/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/elasticsearch/config.sls b/elasticsearch/config.sls new file mode 100644 index 0000000..ac97f4b --- /dev/null +++ b/elasticsearch/config.sls @@ -0,0 +1,16 @@ +{%- if grains['kernel'] == 'Linux' %} + {%- if grains['os'] == 'RedHat' %} + {%- if grains['Role'] == 'Elasticsearch' %} + +{%- if salt['pillar.get']('elasticsearch:config') %} +manage elasticsearch configuration from pillar: + file.serialize: + - name: /etc/elasticsearch/elasticsearch.yml + - dataset_pillar: elasticsearch:config + - formatter: yaml + - user: root +{%- endif %} + + {%- endif %} + {%- endif %} +{%- endif %} \ No newline at end of file diff --git a/elasticsearch/init.sls b/elasticsearch/init.sls new file mode 100644 index 0000000..5ec83ca --- /dev/null +++ b/elasticsearch/init.sls @@ -0,0 +1,13 @@ +{%- if grains['kernel'] == 'Linux' %} + {%- if grains['os'] == 'RedHat' %} + {%- if grains['Role'] == 'Elasticsearch' %} + + include: + - elasticsearch.install + - elasticsearch.config + - elasticsearch.services + + {%- endif %} + {%- endif %} +{%- endif %} + diff --git a/elasticsearch/install.sls b/elasticsearch/install.sls new file mode 100644 index 0000000..4418885 --- /dev/null +++ b/elasticsearch/install.sls @@ -0,0 +1,50 @@ +{%- if grains['kernel'] == 'Linux' %} + {%- if grains['os'] == 'RedHat' %} + {%- if grains['Role'] == 'Elasticsearch' %} + + {% set launchmanaged = '1' %} + + elasticsearch_repo: + pkgrepo.managed: + - humanname: Elasticsearch + - name: elasticsearch + - baseurl: http://XSPW50A595K/saltrepo/redhat + - enabled: 1 + - gpgcheck: 0 + + java-1.8.0-openjdk: + pkg.installed + + elasticsearch_folder_data: + cmd.run: + - name: "mkdir -p /data/elasticsearch" + - cwd: / + - stateful: True + - if_missing: '/data/elasticsearch' + + elasticsearch_folder_logs: + cmd.run: + - name: "mkdir -p /logs/elasticsearch" + - cwd: / + - stateful: True + - if_missing: '/logs/elasticsearch' + + elasticsearch: + pkg.installed + +# TODO : USE GRAINS instead file to keep the External Script launched. + + elasticsearch_patch_kernel: + cmd.script: + - name: patch_kernel2.sh + - env: + - BATCH: 'yes' + - source: salt://elasticsearch/patch_kernel2.sh + - cwd: / + - args: {{ launchmanaged }} +# If missing is not compatible pour module cmd. +# - if_missing: '/data/kernel-{{ launchmanaged }}.patched' + + {%- endif %} + {%- endif %} +{%- endif %} diff --git a/elasticsearch/patch_kernel.sh b/elasticsearch/patch_kernel.sh new file mode 100644 index 0000000..adfcdf3 --- /dev/null +++ b/elasticsearch/patch_kernel.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# Iwan CLEMENT & Joseph ZACHARIE + +SCRIPTVER="0.2" +SCRIPTDATE="20170915" + +LAUNCHMANAGED=$1 + +SYSCTLROOT="/proc/sys" +SYSCTLFILE="/etc/sysctl.conf" +LIMITFILE="/etc/security/limits.conf" +FLAGFILE="/data/kernel-$LAUNCHMANAGED.patched" +ELASTICDATA="/data/elasticsearch" +ELASTICLOGS="/logs/elasticsearch" +ELASTICUSER="elasticsearch" +ELASTICGRP=$ELASTICUSER + +if [ $LAUNCHMANAGED -eq "" ] then exit 1 + +function logons() { + echo -e "$(date +"%Y%m%d_%H%M%S") $1" >>"$FLAGFILE" +} + +function sysctlconfig () { + logons "$1 parameter setting" + CHAINE=$1 + VALEUR=$2 + SYSFILE=$SYSCTLROOT/${CHAINE/\./\/} + logons "Initial value for $CHAINE: $(cat $SYSFILE)" + logons "New setting $VALEUR pushed to $SYSFILE" + cat $VALUE >"$SYSFILE" + echo "$1=$2" >>"$SYSCTLFILE" +} + +if [ ! -f $FLAGFILE ] +then + logons "ScriptVersion=$SCRIPTVER" + logons "ScriptDate=$SCRIPTDATE" + logons "Patch Kernel" + echo "* soft nofile 65536" >> "$LIMITFILE" + echo "* hard nofile 131072" >> "$LIMITFILE" + echo "* soft nproc 2048" >> "$LIMITFILE" + echo "* hard nproc 4096" >> "$LIMITFILE" + sysctlconfig "fs.file-max" "524288" + sysctlconfig "vm.max_map_count" "262144" + #echo "fs.file-max = 524288" >> /etc/sysctl.conf + #echo "vm.max_map_count=262144" >> /etc/sysctl.conf + + chmod 750 $ELASTICDATA + chmod 750 $ELASTICLOGS + chmod 755 $ELASTICDATA/nodes + + chown $ELASTICUSER:$ELASTICGRP $ELASTICDATA -R + chown $ELASTICUSER:$ELASTICGRP $ELASTICLOGS -R + + logons "done" +fi \ No newline at end of file diff --git a/elasticsearch/patch_kernel2.sh b/elasticsearch/patch_kernel2.sh new file mode 100644 index 0000000..ab8b135 --- /dev/null +++ b/elasticsearch/patch_kernel2.sh @@ -0,0 +1 @@ +echo Hello $1 \ No newline at end of file diff --git a/elasticsearch/services.sls b/elasticsearch/services.sls new file mode 100644 index 0000000..cd36eff --- /dev/null +++ b/elasticsearch/services.sls @@ -0,0 +1,20 @@ +{%- if grains['kernel'] == 'Linux' %} + {%- if grains['os'] == 'RedHat' %} + {%- if grains['Role'] == 'Elasticsearch' %} + + +include: + - elasticsearch.config + +start elasticsearch service: + service.running: + - name: elasticsearch + - enable: True + {%- if salt['pillar.get']('elasticsearch:config') %} + - watch: + - file: /etc/elasticsearch/elasticsearch.yml + {%- endif %} + + {%- endif %} + {%- endif %} +{%- endif %} \ No newline at end of file diff --git a/elasticsearch/upgrade_5_6_1.sls b/elasticsearch/upgrade_5_6_1.sls new file mode 100644 index 0000000..93edd01 --- /dev/null +++ b/elasticsearch/upgrade_5_6_1.sls @@ -0,0 +1,14 @@ +{%- if grains['kernel'] == 'Linux' %} + {%- if grains['os'] == 'RedHat' %} + {%- if grains['Role'] == 'Elasticsearch' %} + +#VERIFY THAT ELASTIC IS ALLREADY PRESENT E.G. INCLUDE ELASTIC.INSTALL.SLS + elasticsearch_force_upgrade: + cmd.run: + - name: "yum install -y http://XSPW50A595K/saltrepo/redhat/elasticsearch/elasticsearch-5.6.1.rpm" + - cwd: / + - stateful: True + + {%- endif %} + {%- endif %} +{%- endif %}