美文网首页
Salt:基础概念

Salt:基础概念

作者: 真徐小白 | 来源:发表于2017-04-12 16:36 被阅读139次

    Grains

    Grains收集操作系统,域名,IP地址,内核,OS种类,内存以及其他系统信息。

    Grains几乎是静态的数据,如果系统信息发生改变,Grains也会刷新相应数据。

    Grains不区分大小写.

    相关命令:

    salt '*' grains.ls      //列出grains
    salt '*' grains.items   //显示grains数据
    

    Pillar

    Pillars为Salt提供全局数据。

    Pillars只会被指定的minion访问,所以可以用来存储一些敏感数据。

    配置pillar存储位置
    /etc/salt/master

    pillar_roots:
      base:
        - /srv/pillar
    

    pillar根文件,
    /srv/pillar/top.sls

    base:
      '*':
        - packages
    

    定义pillar数据
    /srv/pillar/packages.sls

    {% if grains['os'] == 'RedHat' %}
    apache: httpd
    git: git
    {% elif grains['os'] == 'Debian' %}
    apache: apache2
    git: git-core
    {% endif %}
    

    定位minion

    salt可以通过多种方式定位minion。

    通过grains

    salt -G "os:CentOs" test.ping
    

    匹配操作系统为CentOs的minion

    组合

    salt -C 'G@os:Debian and webser* or E@db.*' test.ping
    

    匹配ID以webser开头并且操作系统为Debian,或者ID以db.开头的minion

    全局匹配
    Match all minions:
    salt '*' test.ping
    Match all minions in the example.net domain or any of the example domains:
    salt '*.example.net' test.ping
    salt '*.example.*' test.ping
    Match all the webN minions in the example.net domain (web1.example.net, web2.example.net … webN.example.net):
    salt 'web?.example.net' test.ping
    Match the web1 through web5 minions:
    salt 'web[1-5]' test.ping
    Match the web1 and web3 minions:
    salt 'web[1,3]' test.ping
    Match the web-x, web-y, and web-z minions:
    salt 'web-[x-z]' test.ping

    正则匹配
    salt -E 'web1-(prod|devel)' test.ping

    列表
    salt -L 'web1,web2,web3' test.ping

    IP地址匹配
    salt -S 192.168.40.20 test.ping
    salt -S 10.0.0.0/24 test.ping

    Salt Mine

    Salt Mine从minions收集数据并存储在master.

    使用场景:
    获取一组web服务器的ip地址,用来生成haproxy的loadbalance 配置。

    详细内容请参见官方文档。

    相关文章

      网友评论

          本文标题:Salt:基础概念

          本文链接:https://www.haomeiwen.com/subject/adumattx.html