Saltstack学习-数据系统

Posted hujinzhong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Saltstack学习-数据系统相关的知识,希望对你有一定的参考价值。

saltstack主要有两种数据系统:

  • Grains
  • Pillar

一、数据系统-Grains

1.1、Grains简介

1)当minion启动后会收集自身的状态信息即grains信息,grains信息是静态的,存储在minion端,如操作系统版本,内核版本,CPU,内存,硬盘,设备型号等。这些信息可以作为master端的匹配目标

2)master端可以自定义grains设置,但需要执行命令推送到minion端

3)master端推送的数据会存放在minion端的/var/cache/salt

1.2、使用grains查询minion端相关信息

1)salt ‘*‘ grains.ls  ==>列出所有可打印的状态模块

[root@salt-master ~]# salt ‘salt-minion1-c7‘ grains.ls
salt-minion1-c7:
    - SSDs
    - biosreleasedate
    - biosversion
    - cpu_flags
    - cpu_model
    - cpuarch
    - disks
    - dns
    - domain
    - fqdn
    - fqdn_ip4
    - fqdn_ip6
    - fqdns
    - gid
    - gpus
    - groupname
    - host
    - hwaddr_interfaces
    - id
    - init
    - ip4_gw
    - ip4_interfaces
    - ip6_gw
    - ip6_interfaces
    - ip_gw
    - ip_interfaces
    - ipv4
    - ipv6
    - kernel
    - kernelrelease
    - kernelversion
    - locale_info
    - localhost
    - lsb_distrib_codename
    - lsb_distrib_id
    - machine_id
    - manufacturer
    - master
    - mdadm
    - mem_total
    - nodename
    - num_cpus
    - num_gpus
    - os
    - os_family
    - osarch
    - oscodename
    - osfinger
    - osfullname
    - osmajorrelease
    - osrelease
    - osrelease_info
    - path
    - pid
    - productname
    - ps
    - pythonexecutable
    - pythonpath
    - pythonversion
    - saltpath
    - saltversion
    - saltversioninfo
    - selinux
    - serialnumber
    - server_id
    - shell
    - swap_total
    - systemd
    - uid
    - username
    - uuid
    - virtual
    - zfs_feature_flags
    - zfs_support
    - zmqversion

2)salt ‘*‘ grains.items  ==>列出状态信息

[root@salt-master ~]# salt ‘salt-minion1-c7‘ grains.items
salt-minion1-c7:
    ----------
    SSDs:
    biosreleasedate:
        05/19/2017
    biosversion:
        6.00
    cpu_flags:
        - fpu
        - vme
        - de
        - pse
        - tsc
        - msr
        - pae
        - mce
        - cx8
        - apic
        - sep
        - mtrr
        - pge
        - mca
        - cmov
        - pat
        - pse36
        - clflush
        - mmx
        - fxsr
        - sse
        - sse2
        - ss
        - syscall
        - nx
        - pdpe1gb
        - rdtscp
        - lm
        - constant_tsc
        - arch_perfmon
        - nopl
        - xtopology
        - tsc_reliable
        - nonstop_tsc
        - eagerfpu
        - pni
        - pclmulqdq
        - ssse3
        - fma
        - cx16
        - pcid
        - sse4_1
        - sse4_2
        - x2apic
        - movbe
        - popcnt
        - tsc_deadline_timer
        - aes
        - xsave
        - avx
        - f16c
        - rdrand
        - hypervisor
        - lahf_lm
        - abm
        - 3dnowprefetch
        - fsgsbase
        - tsc_adjust
        - bmi1
        - avx2
        - smep
        - bmi2
        - invpcid
        - rdseed
        - adx
        - smap
        - xsaveopt
        - arat
    cpu_model:
        Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    cpuarch:
        x86_64
    disks:
        - sda
        - sr0
    dns:
        ----------
        domain:
        ip4_nameservers:
            - 223.5.5.5
        ip6_nameservers:
        nameservers:
            - 223.5.5.5
        options:
        search:
        sortlist:
    domain:
    fqdn:
        salt-minion1-c7
    fqdn_ip4:
        - 10.0.0.21
    fqdn_ip6:
        - fe80::20c:29ff:fe3e:9d2f
    fqdns:
    gid:
        0
    gpus:
        |_
          ----------
          model:
              SVGA II Adapter
          vendor:
              vmware
    groupname:
        root
    host:
        salt-minion1-c7
    hwaddr_interfaces:
        ----------
        eth0:
            00:0c:29:3e:9d:2f
        lo:
            00:00:00:00:00:00
    id:
        salt-minion1-c7
    init:
        systemd
    ip4_gw:
        10.0.0.254
    ip4_interfaces:
        ----------
        eth0:
            - 10.0.0.21
        lo:
            - 127.0.0.1
    ip6_gw:
        False
    ip6_interfaces:
        ----------
        eth0:
            - fe80::20c:29ff:fe3e:9d2f
        lo:
            - ::1
    ip_gw:
        True
    ip_interfaces:
        ----------
        eth0:
            - 10.0.0.21
            - fe80::20c:29ff:fe3e:9d2f
        lo:
            - 127.0.0.1
            - ::1
    ipv4:
        - 10.0.0.21
        - 127.0.0.1
    ipv6:
        - ::1
        - fe80::20c:29ff:fe3e:9d2f
    kernel:
        Linux
    kernelrelease:
        3.10.0-693.el7.x86_64
    kernelversion:
        #1 SMP Tue Aug 22 21:09:27 UTC 2017
    locale_info:
        ----------
        defaultencoding:
            UTF-8
        defaultlanguage:
            en_US
        detectedencoding:
            UTF-8
    localhost:
        salt-minion1-c7
    lsb_distrib_codename:
        CentOS Linux 7 (Core)
    lsb_distrib_id:
        CentOS Linux
    machine_id:
        6a95166986604960b8a690e6e5103d2f
    manufacturer:
        VMware, Inc.
    master:
        10.0.0.11
    mdadm:
    mem_total:
        976
    nodename:
        salt-minion1-c7
    num_cpus:
        1
    num_gpus:
        1
    os:
        CentOS
    os_family:
        RedHat
    osarch:
        x86_64
    oscodename:
        CentOS Linux 7 (Core)
    osfinger:
        CentOS Linux-7
    osfullname:
        CentOS Linux
    osmajorrelease:
        7
    osrelease:
        7.4.1708
    osrelease_info:
        - 7
        - 4
        - 1708
    path:
        /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
    pid:
        15941
    productname:
        VMware Virtual Platform
    ps:
        ps -efHww
    pythonexecutable:
        /usr/bin/python
    pythonpath:
        - /usr/bin
        - /usr/lib64/python27.zip
        - /usr/lib64/python2.7
        - /usr/lib64/python2.7/plat-linux2
        - /usr/lib64/python2.7/lib-tk
        - /usr/lib64/python2.7/lib-old
        - /usr/lib64/python2.7/lib-dynload
        - /usr/lib64/python2.7/site-packages
        - /usr/lib64/python2.7/site-packages/gtk-2.0
        - /usr/lib/python2.7/site-packages
    pythonversion:
        - 2
        - 7
        - 5
        - final
        - 0
    saltpath:
        /usr/lib/python2.7/site-packages/salt
    saltversion:
        2019.2.0
    saltversioninfo:
        - 2019
        - 2
        - 0
        - 0
    selinux:
        ----------
        enabled:
            False
        enforced:
            Disabled
    serialnumber:
        VMware-56 4d e6 d4 88 d2 ac 39-c3 e1 9b 64 a5 3e 9d 2f
    server_id:
        1333013820
    shell:
        /bin/sh
    swap_total:
        2047
    systemd:
        ----------
        features:
            +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN
        version:
            219
    uid:
        0
    username:
        root
    uuid:
        d4e64d56-d288-39ac-c3e1-9b64a53e9d2f
    virtual:
        VMware
    zfs_feature_flags:
        False
    zfs_support:
        False
    zmqversion:
        4.1.4

3)salt ‘*‘ grains.item fqdn_ip4  ==>列出特定的状态项,如获取minion的ip地址

[root@salt-master ~]# salt ‘*‘ grains.item fqdn_ip4
salt-minion1-c7:
    ----------
    fqdn_ip4:
        - 10.0.0.21
salt-minion2-c7:
    ----------
    fqdn_ip4:
        - 10.0.0.22
salt-minion3-c7:
    ----------
    fqdn_ip4:
        - 10.0.0.23
salt-minion4-c6:
    ----------
    fqdn_ip4:
[root@salt-master ~]# salt ‘salt-minion4-c6‘ grains.item ip4_interfaces:eth0
salt-minion4-c6:
    ----------
    ip4_interfaces:eth0:
        - 10.0.0.24

4)salt ‘*‘ grains.get [key]  ==>获取相关信息

[root@salt-master ~]# salt ‘*‘ grains.get saltversion
salt-minion2-c7:
    2019.2.0
salt-minion1-c7:
    2019.2.0
salt-minion3-c7:
    2019.2.0
salt-minion4-c6:
    2019.2.0

[root@salt-master ~]# salt ‘*‘ grains.get ip4_interfaces:eth0
salt-minion1-c7:
    - 10.0.0.21
salt-minion2-c7:
    - 10.0.0.22
salt-minion3-c7:
    - 10.0.0.23
salt-minion4-c6:
    - 10.0.0.24

5)salt –G   ==>指定匹配目标的主机执行命令

[root@salt-master ~]# salt -G ‘osmajorrelease:7‘ cmd.run ‘uptime‘   #在centos7上执行,centos6不执行
salt-minion1-c7:
     00:10:36 up  5:30,  2 users,  load average: 0.00, 0.01, 0.05
salt-minion2-c7:
     00:10:36 up  5:30,  2 users,  load average: 0.08, 0.05, 0.05
salt-minion3-c7:
     00:10:36 up  5:30,  2 users,  load average: 0.04, 0.03, 0.05
[root@salt-master ~]# salt -G ‘os:CentOS‘ cmd.run ‘uptime‘    #在系统是centos的主机上执行
salt-minion3-c7:
     00:10:56 up  5:30,  2 users,  load average: 0.03, 0.03, 0.05
salt-minion2-c7:
     00:10:56 up  5:30,  2 users,  load average: 0.05, 0.05, 0.05
salt-minion4-c6:
     08:09:26 up  5:28,  2 users,  load average: 0.00, 0.00, 0.00
salt-minion1-c7:
     00:10:56 up  5:30,  2 users,  load average: 0.00, 0.01, 0.05

以上是关于Saltstack学习-数据系统的主要内容,如果未能解决你的问题,请参考以下文章

SaltStack实战之数据系统-Grains

SaltStack实战之数据系统-Pillar

SaltStack之数据系统

SaltStack之数据系统

SaltStack之数据系统

SaltStack实战之数据系统 Grains VS Pillar