首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >teg salt sls文件解读

teg salt sls文件解读

作者头像
葫芦
发布2019-06-20 20:50:49
9930
发布2019-06-20 20:50:49
举报
文章被收录于专栏:葫芦葫芦葫芦

salt sls文件解读

es-rpm-file:
  file.managed: #文件上传
    - name: /opt/elasticsearch-2.4.2.rpm   #子节点文件
    - source: salt://test/es-2-4/elasticsearch-2.4.2.rpm #主节点文件
    - user: root  #子节点上文件属主
    - group: root #子节点上文件属主
    - mode: 755 #授权

es-install:
  cmd.run:
    - cwd: /opt #运行路径
    - names:
      - yum -y localinstall elasticsearch-2.4.2.rpm #运行命令
    - unless: test ! -z `rpm -qa elasticsearch` #返回成功0则不执行下面
    - require:                       #依赖顺序
      - file: es-rpm-file

es-mkdir:
  cmd.run:
    - cwd: /data
    - names:
      - mkdir -p /data/es
      - chown -R elasticsearch:elasticsearch /data/es
    - require:
      - cmd: es-install


es-jvm-file:
  file.managed:
    - name: /etc/sysconfig/elasticsearch
    - source: salt://test/es-2-4/elasticsearch
    - template: jinja
    - user: elasticsearch
    - group: elasticsearch
    - mode: 755
    - require:
      - cmd: es-install

es-config-file:
  file.managed:
    - name: /etc/elasticsearch/elasticsearch.yml
    - source: salt://test/es-2-4/elasticsearch.yml
    - template: jinja
    - user: elasticsearch
    - group: elasticsearch
    - mode: 755
    - require:
      - cmd: es-install

file.managed

/usr/lib/python2.7/site-packages/salt/states/file.py

def managed(name,
            source=None,
            source_hash='',
            source_hash_name=None,
            user=None,
            group=None,
            mode=None,
            template=None,
            makedirs=False,
            dir_mode=None,
            context=None,
            replace=True,
            defaults=None,
            backup='',
            show_changes=True,
            create=True,
            contents=None,
            tmp_ext='',
            contents_pillar=None,
            contents_grains=None,
            contents_newline=True,
            contents_delimiter=':',
            encoding=None,
            encoding_errors='strict',
            allow_empty=True,
            follow_symlinks=True,
            check_cmd=None,
            skip_verify=False,
            win_owner=None,
            win_perms=None,
            win_deny_perms=None,
            win_inheritance=True,
            **kwargs):

cmd.run

/usr/lib/python2.7/site-packages/salt/states/cmd.py

def run(name,
        onlyif=None,
        unless=None,
        creates=None,
        cwd=None,
        runas=None,
        shell=None,
        env=None,
        stateful=False,
        umask=None,
        output_loglevel='debug',
        quiet=False,
        timeout=None,
        ignore_timeout=False,
        use_vt=False,
        **kwargs):
    '''
    Run a command if certain circumstances are met.  Use ``cmd.wait`` if you
    want to use the ``watch`` requisite.

    name
        The command to execute, remember that the command will execute with the
        path and permissions of the salt-minion.

    onlyif
        A command to run as a check, run the named command only if the command
        passed to the ``onlyif`` option returns true

    unless
        A command to run as a check, only run the named command if the command
        passed to the ``unless`` option returns false

    cwd
        The current working directory to execute the command in, defaults to
        /root

    runas
        The user name to run the command as

    shell
        The shell to use for execution, defaults to the shell grain

    env
        A list of environment variables to be set prior to execution.

jinja语法修改配置文件

通过jinja语法修改 /etc/sysconfig/elasticsearch

...
{% if 7000 < grains['mem_total'] < 10000 %}
ES_HEAP_SIZE=4g
{% elif 5000 < grains['mem_total'] < 7000 %}
ES_HEAP_SIZE=3g
{% elif 3000 < grains['mem_total'] < 5000 %}
ES_HEAP_SIZE=2g
{% elif 1000 < grains['mem_total'] < 3000 %}
ES_HEAP_SIZE=1g
{% endif %}
...

通过jinja语法修改 /etc/elasticsearch/elasticsearch.yml

...
node.name: {{grains['fqdn']}}   <!--主机名 -->

network.publish_host: {{grains['fqdn_ip4'][0]}} <!--ip -->
...
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019/06/20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • salt sls文件解读
  • file.managed
    • cmd.run
      • jinja语法修改配置文件
      相关产品与服务
      Elasticsearch Service
      腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档