标签:mmx stack pam vim pytho failed BMI swa disabled
1. 主机规划服务器名称 | 操作系统版本 | 内网IP | 外网IP(模拟) | Hostname | 部署模块 |
---|---|---|---|---|---|
salt100 | CentOS7.5 | 172.16.1.100 | 10.0.0.100 | salt100 | salt-master、salt-minion |
salt01 | CentOS7.5 | 172.16.1.11 | 10.0.0.11 | salt01 | salt-minion |
salt02 | CentOS7.5 | 172.16.1.12 | 10.0.0.12 | salt02 | salt-minion |
salt03 | CentOS7.5 | 172.16.1.13 | 10.0.0.13 | salt03 | salt-minion |
https://docs.saltstack.com/en/latest/topics/grains/index.html
修改了master或者minion的配置文件,那么必须重启对应的服务。
Saltstack 数据系统
Grains (谷粒)
Pillar (柱子)
Grains:静态数据 当Minion启动的时候收集的Minion本地的相关信息
如:操作系统版本,内核版本,CPU,内存,硬盘,设备型号,序列号
1、信息查询 【资产管理】★★★★★
2、用于目标选择 salt -G ‘os:CentOS‘ test.ping ★★★★★
3、配置管理中使用
刷新grains 【这样修改grains信息不用重启salt-minion 也能刷新】
不然需要重启salt-minion
salt ‘*‘ saltutil.sync_grains
开发一个Grains:
Python:写一个Python脚本,返回一个字典就可以了。
可以通过
salt ‘salt01‘ saltutil.sync_grains 【推荐】
或salt ‘salt01‘ saltutil.sync_all 【范围太广,不推荐使用】
或salt ‘salt01‘ state.highstate 【执行高级状态时同步,不建议使用】
或salt ‘salt01‘ saltutil.refresh_modules 【只刷新客户端,服务端向客户端分发的不刷新,比如修改了grains的py脚本时,不会推送到minion端 不建议使用】
或salt ‘salt01‘ saltutil.refresh_grains 【只刷新客户端,服务端向客户端分发的不刷新,比如修改了grains的py脚本时,不会推送到minion端 不建议使用】
将配置同步到minion端
如果做了更改也可以使用
salt ‘salt01‘ sys.reload_modules
经验证优先级如下:
1、salt系统自带信息 【优先级最低】
2、自编写Python脚本 备注:在指定目录下存放py脚本
3、/etc/salt/grains 备注:该文件不存在,需要自己创建
4、/etc/salt/minion 【优先级最高】
推荐使用 自编写py脚本定义,这样自定义的grains只需要在master端维护即可,减少后期维护成本。
[root@salt100 salt]# salt ‘salt01‘ grains.ls # 查看salt01机器有哪些grains条目项信息
………………
[root@salt100 salt]# salt ‘salt01‘ grains.items # 查看salt01机器有哪些grains信息
salt01:
----------
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
- ht
- 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
- mpx
- rdseed
- adx
- smap
- clflushopt
- xsaveopt
- xsavec
- arat
cpu_model:
Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
cpuarch:
x86_64
disks:
- sda
- sr0
dns:
----------
domain:
ip4_nameservers:
- 10.0.0.2
- 223.5.5.5
ip6_nameservers:
nameservers:
- 10.0.0.2
- 223.5.5.5
options:
search:
sortlist:
domain:
fqdn:
salt01
fqdn_ip4:
- 172.16.1.11
fqdn_ip6:
- fe80::20c:29ff:fe95:1b84
- fe80::20c:29ff:fe95:1b7a
gid:
0
gpus:
|_
----------
model:
SVGA II Adapter
vendor:
unknown
groupname:
root
host:
salt01
hwaddr_interfaces:
----------
eth0:
00:0c:29:95:1b:7a
eth1:
00:0c:29:95:1b:84
lo:
00:00:00:00:00:00
id:
salt01
init:
systemd
ip4_gw:
10.0.0.2
ip4_interfaces:
----------
eth0:
- 172.16.1.11
eth1:
- 10.0.0.11
lo:
- 127.0.0.1
ip6_gw:
False
ip6_interfaces:
----------
eth0:
- fe80::20c:29ff:fe95:1b7a
eth1:
- fe80::20c:29ff:fe95:1b84
lo:
- ::1
ip_gw:
True
ip_interfaces:
----------
eth0:
- 172.16.1.11
- fe80::20c:29ff:fe95:1b7a
eth1:
- 10.0.0.11
- fe80::20c:29ff:fe95:1b84
lo:
- 127.0.0.1
- ::1
ipv4:
- 10.0.0.11
- 127.0.0.1
- 172.16.1.11
ipv6:
- ::1
- fe80::20c:29ff:fe95:1b7a
- fe80::20c:29ff:fe95:1b84
kernel:
Linux
kernelrelease:
3.10.0-862.el7.x86_64
kernelversion:
#1 SMP Fri Apr 20 16:44:24 UTC 2018
locale_info:
----------
defaultencoding:
UTF-8
defaultlanguage:
en_US
detectedencoding:
UTF-8
localhost:
salt01
lsb_distrib_codename:
CentOS Linux 7 (Core)
lsb_distrib_id:
CentOS Linux
machine_id:
5ae5f27014ee438780bf37ae68889471
manufacturer:
VMware, Inc.
master:
salt100
mdadm:
mem_total:
1821
nodename:
salt01
num_cpus:
2
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.5.1804
osrelease_info:
- 7
- 5
- 1804
path:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
pid:
1598
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:
2018.3.3
saltversioninfo:
- 2018
- 3
- 3
- 0
selinux:
----------
enabled:
False
enforced:
Disabled
serialnumber:
VMware-56 4d 32 86 98 5c a8 3c-50 92 82 be 30 95 1b 7a
server_id:
2097601471
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:
86324d56-5c98-3ca8-5092-82be30951b7a
virtual:
VMware
zfs_feature_flags:
False
zfs_support:
False
zmqversion:
4.1.4
[root@salt100 ~]# salt ‘salt01‘ grains.item roles # 没有该项信息,因此只显示key 不显示value
salt01:
----------
roles:
[root@salt100 ~]# salt ‘salt01‘ grains.item os
salt01:
----------
os:
CentOS
该脚本在salt master端,然后推送到minion端。
[root@salt100 salt]# pwd
/srv/salt
[root@salt100 salt]# mkdir _grains # salt指定的位置
[root@salt100 salt]# cd _grains/
[root@salt100 _grains]# vim my_grains.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def grains_define():
# initialize a grains dictionary
grains = {}
# 填充信息
grains[‘roles‘] = ["webserver01","memcache01"],
grains[‘os‘] = ‘redhat01‘
# 返回这个字典
return grains
[root@salt100 ~]# salt ‘salt01‘ saltutil.sync_grains # 会推送py脚本到minion端,并刷新grains信息
salt01:
- grains.my_grains
[root@salt100 ~]# salt ‘salt01‘ grains.item roles
salt01:
----------
roles:
|_
- webserver01
- memcache01
[root@salt100 ~]# salt ‘salt01‘ grains.item os
salt01:
----------
os:
redhat01
[root@salt01 minion]# pwd
/var/cache/salt/minion
[root@salt01 minion]# tree
.
├── accumulator
├── extmods
│ └── grains # 在这个目录下
│ ├── my_grains.py
│ └── my_grains.pyc
├── files
│ └── base
│ ├── _grains
│ │ └── my_grains.py
│ ├── top.sls
│ └── web
│ └── apache.sls
├── highstate.cache.p
├── module_refresh
├── pkg_refresh
├── proc
└── sls.p
8 directories, 9 files
该文件默认不存在,需要自己创建。
在salt01上操作
[root@salt01 salt]# cat /etc/salt/grains
roles:
- webserver02
- memcache02
os: redhat02
在salt100上操作
[root@salt100 ~]# salt ‘salt01‘ saltutil.sync_grains # 刷新grains信息
salt01:
[root@salt100 ~]# salt ‘salt01‘ grains.item roles
salt01:
----------
roles:
- webserver02
- memcache02
[root@salt100 ~]# salt ‘salt01‘ grains.item os
salt01:
----------
os:
redhat02
minion端salt01机器上配置修改
[root@salt01 salt]# pwd
/etc/salt
[root@salt01 salt]# vim minion
………………
# Custom static grains for this minion can be specified here and used in SLS
# files just like all other grains. This example sets 4 custom grains, with
# the ‘roles‘ grain having two values that can be matched against.
grains:
roles:
- webserver03
- memcache03
os: redhat03
# deployment: datacenter4
# cabinet: 13
# cab_u: 14-15
在master端刷新grains信息,并查看
[root@salt100 ~]# salt ‘salt01‘ saltutil.sync_grains # 刷新指定minion的grains信息
salt01:
[root@salt100 ~]# salt ‘salt01‘ grains.item roles
salt01:
----------
roles:
- webserver03
- memcache03
[root@salt100 ~]# salt ‘salt01‘ grains.item os
salt01:
----------
os:
redhat03
[root@salt100 salt]# salt ‘salt0*‘ grains.item os # 通过通配符匹配salt0* minion端的操作系统信息
salt01:
----------
os:
CentOS
salt03:
----------
os:
CentOS
salt02:
----------
os:
CentOS
[root@salt100 salt]# salt ‘salt0*‘ grains.item ip4_interfaces:eth0 # 多级查询
salt03:
----------
ip4_interfaces:eth0:
- 172.16.1.13
salt01:
----------
ip4_interfaces:eth0:
- 172.16.1.11
salt02:
----------
ip4_interfaces:eth0:
- 172.16.1.12
[root@salt100 salt]# salt ‘salt0*‘ grains.item ip4_interfaces:eth0:0 # 取列表中的第一个值★★★★★
salt01:
----------
ip4_interfaces:eth0:0:
172.16.1.11
salt03:
----------
ip4_interfaces:eth0:0:
172.16.1.13
salt02:
----------
ip4_interfaces:eth0:0:
172.16.1.12
[root@salt100 salt]# salt ‘salt01‘ grains.item os
salt01:
----------
os:
CentOS
[root@salt100 salt]# salt -G ‘os:CentOS‘ cmd.run ‘echo "zhangliang $(date +%Y)"‘ # 指定操作系统为CentOS的
salt03:
zhangliang 2018
salt02:
zhangliang 2018
salt01:
zhangliang 2018
salt100:
zhangliang 2018
[root@salt100 salt]# salt ‘salt01‘ grains.item ip_interfaces
salt01:
----------
ip_interfaces:
----------
eth0:
- 172.16.1.11
- fe80::20c:29ff:fe95:1b7a
eth1:
- 10.0.0.11
- fe80::20c:29ff:fe95:1b84
lo:
- 127.0.0.1
- ::1
[root@salt100 salt]# salt -G ‘ip_interfaces:eth0:172.16.1.11‘ cmd.run ‘whoami‘
salt01:
root
[root@salt100 salt]# salt -G ‘ip_interfaces:eth1:10.0.0.11‘ cmd.run ‘whoami‘
salt01:
root
[root@salt100 salt]# pwd
/srv/salt
[root@salt100 salt]# cat top.sls
base:
# 使用通配符 暂时注释掉
# ‘salt0*‘:
# - web.apache
# - web.nginx # 可以有多个
# 指定具体minion
‘salt03‘:
- web.apache
# 使用grains匹配,添加如下几行
‘roles:webserver03‘:
- match: grain
- web.apache
首先通过grains查看salt01和salt02 的roles信息
[root@salt100 salt]# salt ‘salt01‘ grains.item roles
salt01:
----------
roles:
- webserver03
- memcache03
[root@salt100 salt]# salt ‘salt02‘ grains.item roles
salt02:
----------
roles:
[root@salt100 salt]# salt ‘salt01‘ state.highstate test=True # 执行正常
………………
[root@salt100 salt]# salt ‘salt01‘ state.highstate # 执行正常
………………
[root@salt100 salt]# salt ‘salt02‘ state.highstate test=True # 执行异常【top.file 中没有该匹配】
salt02:
----------
ID: states
Function: no.None
Result: False
Comment: No Top file or master_tops data matches found.
Changes:
Summary for salt02
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 0.000 ms
标签:mmx stack pam vim pytho failed BMI swa disabled
原文地址:https://blog.51cto.com/9410445/2371492