This commit is contained in:
2017-12-21 10:20:08 +01:00
parent 1e8ed33102
commit 55d50352c9
8 changed files with 171 additions and 0 deletions

0
elasticsearch/.gitkeep Normal file
View File

16
elasticsearch/config.sls Normal file
View File

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

13
elasticsearch/init.sls Normal file
View File

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

50
elasticsearch/install.sls Normal file
View File

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

View File

@@ -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

View File

@@ -0,0 +1 @@
echo Hello $1

View File

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

View File

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