2016-09-15 06:53:42 +00:00
|
|
|
#!pydsl
|
|
|
|
# -*- mode: python -*-
|
|
|
|
from salt.utils import dictupdate
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
state('/etc/elasticsearch/').file.directory(
|
|
|
|
create=True, mode=755, user='root', group='root')
|
|
|
|
|
|
|
|
fqdn = __salt__['grains.get']('fqdn')
|
|
|
|
fqdn_ipv6 = __salt__['grains.get']('fqdn_ipv6')
|
|
|
|
hosts = __salt__['pillar.get']('elastic:hosts', [])
|
|
|
|
|
2018-02-25 06:02:49 +00:00
|
|
|
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', {})
|
2017-03-02 11:44:40 +00:00
|
|
|
|
2016-09-15 06:53:42 +00:00
|
|
|
# defaults
|
|
|
|
config = {
|
|
|
|
'node': {
|
|
|
|
'name': '${HOSTNAME}',
|
2017-09-27 09:19:39 +00:00
|
|
|
'master': False, 'data': False, 'ingest': False,
|
2016-09-15 06:53:42 +00:00
|
|
|
'max_local_storage_nodes': 1,
|
|
|
|
},
|
|
|
|
'path': {
|
|
|
|
'data': '/var/lib/elasticsearch',
|
|
|
|
'logs': '/var/log/elasticsearch',
|
|
|
|
},
|
2017-03-02 11:44:40 +00:00
|
|
|
'bootstrap': {'memory_lock': True},
|
2016-09-15 06:53:42 +00:00
|
|
|
'network': { 'host': '${HOSTNAME}' },
|
|
|
|
'http': { 'port': 9200 },
|
|
|
|
'gateway': { 'recover_after_nodes': len(hosts)/2 },
|
|
|
|
'discovery': { 'zen': {
|
|
|
|
'minimum_master_nodes': 1,
|
|
|
|
'ping': { 'unicast': {}},
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
|
|
|
config['discovery']['zen']['ping']['unicast']['hosts'] = filter(
|
|
|
|
lambda x: x != fqdn and x not in fqdn_ipv6,
|
|
|
|
hosts)
|
|
|
|
dictupdate.update(config, __pillar__['elastic']['config'])
|
|
|
|
|
|
|
|
state('/etc/elasticsearch/elasticsearch.yml').file.managed(
|
|
|
|
mode=644, user='root', group='root',
|
|
|
|
contents="# This file is generated by Salt\n" + yaml.dump(config))
|
2017-03-01 17:01:27 +00:00
|
|
|
|
2018-02-25 06:02:49 +00:00
|
|
|
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})
|
|
|
|
|
2017-03-02 11:44:40 +00:00
|
|
|
state('/etc/conf.d/elasticsearch').file.managed(
|
|
|
|
mode=644, user='root', group='root',
|
|
|
|
template='jinja', source="salt://elasticsearch/files/elasticsearch.confd.tpl",
|
2017-03-02 11:54:09 +00:00
|
|
|
defaults={'es_java_opts': '', 'l_nofile': l_nofile, 'l_memlock': l_memlock,
|
2018-02-17 17:53:54 +00:00
|
|
|
'max_map_count': max_map_count, 'max_threads': max_threads, 'es_startup_sleep_time': 10})
|
2017-03-02 11:44:40 +00:00
|
|
|
|
2017-03-01 17:01:27 +00:00
|
|
|
state('/etc/security/limits.d/elasticsearch.conf').file.managed(
|
|
|
|
mode=644, user='root', group='root',
|
2017-03-02 11:44:40 +00:00
|
|
|
contents='\n'.join([
|
|
|
|
"elasticsearch soft nofile {0}".format(l_nofile),
|
|
|
|
"elasticsearch hard nofile {0}".format(l_nofile),
|
2017-03-03 14:21:18 +00:00
|
|
|
"elasticsearch soft memlock {0}".format(l_memlock),
|
|
|
|
"elasticsearch hard memlock {0}".format(l_memlock)]))
|