zoukankan      html  css  js  c++  java
  • SaltStack salt 命令

    salt 是服务端远程批量操作多台客户端需要使用到的命令,常见用法如下:

    salt '*'                             # 指定对所有客户端主机进行操作
    salt 'minion01'                      # 指定对单台客户端主机进行操作
    salt 'minion0[12]'                   # 指定对多台客户端主机进行操作,支持通配
    salt 'minion0*'                      # 指定对多台客户端主机进行操作,支持通配
    salt -E 'minion0(1|2)'               # 以正则(pcre)的形式指定对多台客户端主机进行操作
    salt -L 'minion01, minion02, ...'    # 以列表(list)的形式指定对多台客户端主机进行操作,中间用逗号隔开
    salt -G 'os:CentOS'                  # 根据Grains信息对符合条件的客户端主机进行操作
    salt -I 'role:nginx'                 # 根据Pillar信息对符合条件的客户端主机进行操作
    salt -C 'E@^m or G@os:CentOS'        # 以混合(compound)模式进行匹配,这里 E@^m 相当于 -E '^m', G@os:CentOS 相当于 -G 'os:CentOS'
    salt -N <group_name>                 # 根据组名对一组主机进行操作,需要先在 /etc/salt/master 定义 nodegroups


    常用的执行模块:

    [root@localhost ~]$ salt '*' test.ping                              # test.ping 用于测试是否存活
    [root@localhost ~]$ salt '*' pkg.install httpd                      # pkg.install 用于远程安装软件
    [root@localhost ~]$ salt '*' cmd.run 'hostname'                     # cmd.run 用于远程执行命令,这里表示远程执行hostname命令
    [root@localhost ~]$ salt '*' cmd.script salt://1.sh                 # cmd.script 用于远程执行脚本,这里表示远程执行1.sh脚本,这个脚本放在master的/srv/salt/1.sh路径下
    [root@localhost ~]$ salt '*' cp.get_file salt://1.txt /tmp/1.txt    # cp.get_file 用于远程拷贝文件,这里表示拷贝master的/srv/salt/1.txt文件到远程的/tmp/1.txt文件
    [root@localhost ~]$ salt '*' cp.get_dir salt://test /tmp/test       # cp.get_dir 用于远程拷贝目录,这里表示拷贝master的/srv/salt/test目录到远程的/tmp/test目录
    [root@localhost ~]$ salt '192.168.216.130' sys.doc            # 查看所有模块的帮助文档
    [root@localhost ~]$ salt '192.168.216.130' sys.doc cmd        # 查看指定模块的帮助文档
    [root@localhost ~]$ salt '192.168.216.130' sys.doc cmd.run    # 查看指定模块下的具体方法的帮助文档


    也可以指定输出格式:

    [root@localhost ~]$ salt --out=yaml '*' cmd.run 'date'
    [root@localhost ~]$ salt --out=grains '*' cmd.run 'date'   
    [root@localhost ~]$ salt --out=json '*' cmd.run 'date'      
    其他可选的格式:grains, highstate, json, key, overstatestage, pprint, raw, txt, yaml

        

  • 相关阅读:
    【Leetcode】【Easy】Remove Duplicates from Sorted List
    【Leetcode】【Easy】Pascal's Triangle II
    【Leetcode】【Easy】Pascal's Triangle
    【Leetcode】【Easy】Binary Tree Level Order Traversal II
    【Leetcode】【Easy】Binary Tree Level Order Traversal
    【Leetcode】【Easy】Maximum Depth of Binary Tree
    【Leetcode】【Easy】Minimum Depth of Binary Tree
    【Leetcode】【Easy】Balanced Binary Tree
    【Leetcode】【Easy】Symmetric Tree
    如何使用Action.Invoke()触发一个Storyboard
  • 原文地址:https://www.cnblogs.com/pzk7788/p/10271689.html
Copyright © 2011-2022 走看看