saltstack之service/cp/get/file模块初探

2023年 7月 15日 66.5k 0

模块salt -d 所有的模块参数

disk.usage 磁盘模块

[root@master ~]# salt '*' disk.usage
minion-node07.10.0.0.07.com:
    ----------
    /:
        ----------
        1K-blocks:
            18208184
        available:
            14663688
        capacity:
            16%
        filesystem:
            /dev/sda2
        used:
            2612912
    /boot:
        ----------
        1K-blocks:
            289293
        available:
            245456
        capacity:
            11%
        filesystem:
            /dev/sda1
        used:
            28477
    /dev/shm:
        ----------
        1K-blocks:
            502176
        available:
            502160
        capacity:
            1%
        filesystem:
            tmpfs
        used:
            16
minios.10.0.0.8.com:
    ----------
    /:
        ----------
        1K-blocks:
            18208184
        available:
            14605476
        capacity:
            16%
        filesystem:
            /dev/sda2
        used:
            2671124
    /boot:
        ----------
        1K-blocks:
            289293
        available:
            245456
        capacity:
            11%
        filesystem:
            /dev/sda1
        used:
            28477
    /dev/shm:
        ----------
        1K-blocks:
            502176
        available:
            502164
        capacity:
            1%
        filesystem:
            tmpfs
        used:
            12
minion-node11.10.0.0.11.com:
    ----------
    /:
        ----------
        1K-blocks:
            18208184
        available:
            14665968
        capacity:
            16%
        filesystem:
            /dev/sda2
        used:
            2610632
    /boot:
        ----------
        1K-blocks:
            289293
        available:
            245456
        capacity:
            11%
        filesystem:
            /dev/sda1
        used:
            28477
    /dev/shm:
        ----------
        1K-blocks:
            243112
        available:
            243100
        capacity:
            1%
        filesystem:
            tmpfs
        used:
            12
[root@master ~]# 



hosts,需要主机名能够ping通

[root@master ~]# salt '*' hosts.get_ip master.com
minion-node07.10.0.0.07.com:
minios.10.0.0.8.com:
minion-node11.10.0.0.11.com:
[root@master ~]# 

service模块,远程查看服务

[root@master ~]# salt '*' service.get_all
minios.10.0.0.8.com:
    - NetworkManager
    - abrt-ccpp
    - abrt-oops
    - abrtd
    - acpid
    - atd
    - auditd
    - blk-availability
    - bluetooth
    - control-alt-delete
    - cpuspeed
    -省略一千字
minion-node11.10.0.0.11.com:
    - NetworkManager
    - abrt-ccpp
    - abrt-oops
    - abrtd
    - acpid
    - atd
    - auditd
    - blk-availability
    - bluetooth
    - control-alt-delete
    - cpuspeed
    - crond
    -省略一千字
minion-node07.10.0.0.07.com:
    - NetworkManager
    - abrt-ccpp
    - abrt-oops
    - abrtd
    - acpid
    - atd
    - auditd
    -省略一千字
[root@master ~]#



service.restart重启某服务

1,查看状态
[root@master ~]# salt '*' service.status nginx
minios.10.0.0.8.com:
    False
minion-node07.10.0.0.07.com:
    False
minion-node11.10.0.0.11.com:
    False
2,启动服务
[root@master ~]# salt '*' service.start nginx
minios.10.0.0.8.com:
    True
minion-node07.10.0.0.07.com:
    True
minion-node11.10.0.0.11.com:
    True
3,停止服务
[root@master ~]# salt '*' service.stop nginx
minios.10.0.0.8.com:
    True
minion-node07.10.0.0.07.com:
    True
minion-node11.10.0.0.11.com:
    True
4,再来查看已经被停止
[root@master ~]# salt '*' service.status nginx
minios.10.0.0.8.com:
    False
minion-node11.10.0.0.11.com:
    False
minion-node07.10.0.0.07.com:
    False
[root@master ~]# 


file模块hash对比,salt '*' file.check_hash /etc/issue.net md5:对比值如,我随便输入,则false

[root@master ~]# salt '*' file.check_hash /etc/issue.net md5:111
minion-node07.10.0.0.07.com:
    False
minion-node11.10.0.0.11.com:
    False
minios.10.0.0.8.com:
    False
[root@master ~]# 

判断/etc/passwd文件是否存在

[root@master ~]# salt '*' file.file_exists /etc/passwd
minios.10.0.0.8.com:
    True
minion-node07.10.0.0.07.com:
    True
minion-node11.10.0.0.11.com:
    True
[root@master ~]# 

salt-cp复制,把master的文件cp到客户端例如:1,将/etc/hosts文件复制到/etc/hosts

[root@master ~]# salt-cp '*' /etc/hosts /etc/hosts
{'minion-node07.10.0.0.07.com': {'/etc/hosts': True},
 'minion-node11.10.0.0.11.com': {'/etc/hosts': True},
 'minios.10.0.0.8.com': {'/etc/hosts': True}}

2,将/etc/hosts文件复制到/tmp/hosts

[root@master ~]# salt-cp '*' /etc/hosts /tmp/hosts
{'minion-node07.10.0.0.07.com': {'/tmp/hosts': True},
 'minion-node11.10.0.0.11.com': {'/tmp/hosts': True},
 'minios.10.0.0.8.com': {'/tmp/hosts': True}}

3,查看

[root@master ~]# ll /tmp/hosts 
-rw-r--r-- 1 root root 198 12月 11 09:17 /tmp/hosts
[root@master ~]# 

saltstack之service/cp/get/file模块初探-1

相关文章

对接alertmanager创建钉钉卡片(1)
手把手教你搭建OpenFalcon监控系统
无需任何魔法即可使用 Ansible 的神奇变量“hostvars”
openobseve HA本地单集群模式
基于k8s上loggie/vector/openobserve日志收集
openobseve单节点和查询语法

发布评论