成都创新互联网站制作重庆分公司

saltstackgrains

1、什么是Grains

成都创新互联专注于临江企业网站建设,自适应网站建设,商城开发。临江网站建设公司,为临江等地区提供建站服务。全流程按需策划,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务

  Grains是SaltStack的一个组件,存放着minion启动时收集的底层系统的静态信息。Grains是存储在minion端的,当minion启动时,会进行Grains的采集工作,然后保存下来。在以后的生命周期(再次重启minion,会重新收集)是不会发生变化的,所以是静态数据。Grains中包含诸如运行的内核版本、操作系统、CPU个数、内存、物理设备型号等信息。

  数据采集更新方式:Minion启动时收集,也可以使用saltutil.sync_grains

2、Grains的应用场景

Grains可以在state系统中使用,用于配置管理模块。

Grains可以target中使用,在用来匹配Minion,比如匹配操作系统,使用-G选项。

Grains可以用于信息查询,Grains保存着收集到的客户端的详细信息。

3、Grains常用操作

a、列出Minion上所有可用的grains的名称

[root@master ~]# salt '*' grains.ls
node02.saltstack.com:
    - SSDs
    - biosreleasedate
    - biosversion
    - cpu_flags
    - cpu_model
    - cpuarch
    - domain
    - fqdn
    - fqdn_ip4
    - fqdn_ip6
    - gpus
    - host
    - hwaddr_interfaces
    - id
    - init
    - ip4_interfaces
    - ip6_interfaces
    - ip_interfaces
    - ipv4
    - ipv6
    - kernel
    - kernelrelease
    - locale_info
    - localhost
    - lsb_distrib_codename
    - lsb_distrib_id
    - lsb_distrib_release
    - machine_id
    - manufacturer
    - master
    - mdadm
    - mem_total
    - nodename
    - num_cpus
    - num_gpus
    - os
    - os_family
    - osarch
    - oscodename
    - osfinger
    - osfullname
    - osmajorrelease
    - osrelease
    - osrelease_info
    - path
    - productname
    - ps
    - pythonexecutable
    - pythonpath
    - pythonversion
    - saltpath
    - saltversion
    - saltversioninfo
    - selinux
    - serialnumber
    - server_id
    - shell
    - virtual
    - zmqversion
node01.saltstack.com:
    - SSDs
    - biosreleasedate
    - biosversion
    - cpu_flags
    - cpu_model
    - cpuarch
    - domain
    - fqdn
    - fqdn_ip4
    - fqdn_ip6
    - gpus
    - host
    - hwaddr_interfaces
    - id
    - init
    - ip4_interfaces
    - ip6_interfaces
    - ip_interfaces
    - ipv4
    - ipv6
    - kernel
    - kernelrelease
    - locale_info
    - localhost
    - lsb_distrib_codename
    - lsb_distrib_id
    - lsb_distrib_release
    - machine_id
    - manufacturer
    - master
    - mdadm
    - mem_total
    - nodename
    - num_cpus
    - num_gpus
    - os
    - os_family
    - osarch
    - oscodename
    - osfinger
    - osfullname
    - osmajorrelease
    - osrelease
    - osrelease_info
    - path
    - productname
    - ps
    - pythonexecutable
    - pythonpath
    - pythonversion
    - saltpath
    - saltversion
    - saltversioninfo
    - selinux
    - serialnumber
    - server_id
    - shell
    - virtual
    - zmqversion

b、列出Minion上所有grains的的名称及内容

[root@master ~]# salt 'node01.saltstack.com' grains.items
node01.saltstack.com:
    ----------
    SSDs:
    biosreleasedate:
        07/02/2015
    biosversion:
        6.00
    cpu_flags:
        - fpu
        - vme
        - de
        - pse
        - tsc
        - msr
        - pae
        - mce
        - cx8
        - apic
        - sep
        - mtrr
        - pge
        - mca
        - cmov
        - pat
        - pse36
        - clflush
        - dts
        - mmx
        - fxsr
        - sse
        - sse2
        - ss
        - syscall
        - nx
        - rdtscp
        - lm
        - constant_tsc
        - up
        - arch_perfmon
        - pebs
        - bts
        - xtopology
        - tsc_reliable
        - nonstop_tsc
        - aperfmperf
        - unfair_spinlock
        - pni
        - pclmulqdq
        - ssse3
        - cx16
        - pcid
        - sse4_1
        - sse4_2
        - x2apic
        - popcnt
        - tsc_deadline_timer
        - aes
        - xsave
        - avx
        - f16c
        - rdrand
        - hypervisor
        - lahf_lm
        - ida
        - arat
        - epb
        - pln
        - pts
        - dts
        - fsgsbase
        - smep
    cpu_model:
        Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
    cpuarch:
        x86_64
    domain:
        saltstack.com
    fqdn:
        node01.saltstack.com
    fqdn_ip4:
        - 10.10.10.141
    fqdn_ip6:
    gpus:
        |_
          ----------
          model:
              SVGA II Adapter
          vendor:
              unknown
    host:
        node01
    hwaddr_interfaces:
        ----------
        eth0:
            00:0c:29:98:68:91
        lo:
            00:00:00:00:00:00
        pan0:
            f6:aa:1f:cb:87:f0
    id:
        node01.saltstack.com
    init:
        upstart
    ip4_interfaces:
        ----------
        eth0:
            - 10.10.10.141
        lo:
            - 127.0.0.1
        pan0:
    ip6_interfaces:
        ----------
        eth0:
            - fe80::20c:29ff:fe98:6891
        lo:
            - ::1
        pan0:
    ip_interfaces:
        ----------
        eth0:
            - 10.10.10.141
            - fe80::20c:29ff:fe98:6891
        lo:
            - 127.0.0.1
            - ::1
        pan0:
    ipv4:
        - 10.10.10.141
        - 127.0.0.1
    ipv6:
        - ::1
        - fe80::20c:29ff:fe98:6891
    kernel:
        Linux
    kernelrelease:
        2.6.32-573.el6.x86_64
    locale_info:
        ----------
        defaultencoding:
            UTF8
        defaultlanguage:
            en_US
        detectedencoding:
            UTF-8
    localhost:
        node01.saltstack.com
    lsb_distrib_codename:
        Final
    lsb_distrib_id:
        CentOS
    lsb_distrib_release:
        6.7
    machine_id:
        5bd0d598c3ad4f78b38c6e7600000020
    manufacturer:
        VMware, Inc.
    master:
        master.saltstack.com
    mdadm:
    mem_total:
        1863
    nodename:
        node01.saltstack.com
    num_cpus:
        1
    num_gpus:
        1
    os:
        CentOS
    os_family:
        RedHat
    osarch:
        x86_64
    oscodename:
        Final
    osfinger:
        CentOS-6
    osfullname:
        CentOS
    osmajorrelease:
        6
    osrelease:
        6.7
    osrelease_info:
        - 6
        - 7
    path:
        /sbin:/usr/sbin:/bin:/usr/bin
    productname:
        VMware Virtual Platform
    ps:
        ps -efH
    pythonexecutable:
        /usr/bin/python2.6
    pythonpath:
        - /usr/bin
        - /usr/lib64/python26.zip
        - /usr/lib64/python2.6
        - /usr/lib64/python2.6/plat-linux2
        - /usr/lib64/python2.6/lib-tk
        - /usr/lib64/python2.6/lib-old
        - /usr/lib64/python2.6/lib-dynload
        - /usr/lib64/python2.6/site-packages
        - /usr/lib64/python2.6/site-packages/PIL
        - /usr/lib64/python2.6/site-packages/gst-0.10
        - /usr/lib64/python2.6/site-packages/gtk-2.0
        - /usr/lib64/python2.6/site-packages/webkit-1.0
        - /usr/lib/python2.6/site-packages
        - /usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info
    pythonversion:
        - 2
        - 6
        - 6
        - final
        - 0
    saltpath:
        /usr/lib/python2.6/site-packages/salt
    saltversion:
        2015.5.10
    saltversioninfo:
        - 2015
        - 5
        - 10
        - 0
    selinux:
        ----------
        enabled:
            False
        enforced:
            Disabled
    serialnumber:
        VMware-56 4d e6 9b 20 1f b4 60-77 5d 03 1d 1d 98 68 91
    server_id:
        1356238538
    shell:
        /bin/sh
    virtual:
        VMware
    zmqversion:
        3.2.5

c、查看虚拟化的类型

[root@master ~]# salt '*' grains.get virtual
node01.saltstack.com:
    VMware
node02.saltstack.com:
    VMware

d、查询eth0所有IP地址

[root@master ~]# salt '*' grains.get ip_interfaces
node01.saltstack.com:
    ----------
    eth0:
        - 10.10.10.141
        - fe80::20c:29ff:fe98:6891
    lo:
        - 127.0.0.1
        - ::1
    pan0:
node02.saltstack.com:
    ----------
    eth0:
        - 10.10.10.142
        - fe80::20c:29ff:fead:83d
    lo:
        - 127.0.0.1
        - ::1
    pan0:

e、查询eth0所有IP地址

[root@master ~]# salt '*' grains.get ip_interfaces:eth0
node02.saltstack.com:
    - 10.10.10.142
    - fe80::20c:29ff:fead:83d
node01.saltstack.com:
    - 10.10.10.141
    - fe80::20c:29ff:fe98:6891

4、自定义grains

a)在minion上的/etc/salt/minion直接配置grains

[root@node01 ~]# vim /etc/salt/minion
grains:
  roles: IT
  dept: system
[root@master ~]# salt -G 'roles:IT' test.ping
node01.saltstack.com:
    True
[root@master ~]# salt -G 'dept:system' test.ping
node01.saltstack.com:
    True

b)通过/etc/salt/grains进行定义

[root@node01 ~]# vim /etc/salt/grains 
virtual: openstack
[root@node01 ~]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon:                               [确定]
Starting salt-minion daemon:                               [确定]
[root@node02 ~]# cat /etc/salt/grains 
virtual: xen
[root@node02 ~]# /etc/init.d/salt-minion restart
Stopping salt-minion daemon:                               [确定]
Starting salt-minion daemon:                               [确定]
[root@master ~]# salt -G 'virtual:xen' test.ping
node02.saltstack.com:
    True

在minion端添加一个MySQLversion的信息

[root@node01 ~]# cat /etc/salt/grains 
virtual: openstack
mysqlversion: 5.5
测试,发现存在报错信息
[root@master ~]# salt -G 'mysqlversion:5.5' test.ping
No minions matched the target. No command was sent, no jid was assigned.
ERROR: No return received
使用saltutil.sync_grains进行刷新测试
[root@master ~]# salt '*' saltutil.sync_grains
node02.saltstack.com:
node01.saltstack.com:
[root@master ~]# salt -G 'mysqlversion:5.5' test.ping
node01.saltstack.com:
    True

网站名称:saltstackgrains
文章地址:http://cxhlcq.com/article/pppjsd.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部