💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
一)查看帮助 [admin@master ~]$ sudo salt "huancun03*" sys.list_modules (查看有哪些模块) [admin@master ~]$ sudo salt 'node2.51yuki.cn' sys.list_functions cmd node2.51yuki.cn: - cmd.exec_code - cmd.exec_code_all - cmd.has_exec - cmd.powershell - cmd.retcode - cmd.run - cmd.run_all - cmd.run_bg - cmd.run_chroot - cmd.run_stderr - cmd.run_stdout - cmd.script - cmd.script_retcode - cmd.sdecode - cmd.shell - cmd.shell_info - cmd.shells - cmd.tty - cmd.which - cmd.which_bin (查看模块支持哪些种方法) [admin@master ~]$ sudo salt 'node2.51yuki.cn' sys.doc cmd.run (查看每个模块具体的用法) 2)案例1 [admin@master ~]$ sudo salt "*" test.ping node2.51yuki.cn: True node3.51yuki.cn: True [admin@master ~]$ sudo salt "*" cmd.run 'df -h' node3.51yuki.cn: Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 13G 1.5G 11G 12% / devtmpfs 486M 0 486M 0% /dev tmpfs 497M 12K 497M 1% /dev/shm tmpfs 497M 6.6M 490M 2% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup /dev/vda1 1014M 121M 894M 12% /boot tmpfs 100M 0 100M 0% /run/user/0 tmpfs 100M 0 100M 0% /run/user/1000 node2.51yuki.cn: Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 13G 1.6G 11G 13% / devtmpfs 486M 0 486M 0% /dev tmpfs 497M 12K 497M 1% /dev/shm tmpfs 497M 6.5M 490M 2% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup /dev/vda1 1014M 121M 894M 12% /boot tmpfs 100M 0 100M 0% /run/user/1000 tmpfs 100M 0 100M 0% /run/user/0 [admin@master ~]$ sudo salt "*" cmd.run 'w' node3.51yuki.cn: 14:30:11 up 2:26, 1 user, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT admin pts/1 10.2.18.231 13:04 8:19 0.06s 0.06s -bash node2.51yuki.cn: 14:30:12 up 2:21, 1 user, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT admin pts/0 10.2.18.231 13:05 1:48 0.12s 0.12s -bash 说明: cmd:模块 run: 方法 'w' 参数 3)案例2 远程执行,创建目录 [admin@master ~]$ sudo salt "*" cmd.run "mkdir /server/scripts/ -p" node3.51yuki.cn: node2.51yuki.cn: [admin@master ~]$ sudo salt "*" cmd.run "ls -ld /server/scripts/" node2.51yuki.cn: drwxr-xr-x. 2 root root 6 Jan 13 14:31 /server/scripts/ node3.51yuki.cn: drwxr-xr-x. 2 root root 6 Jan 13 14:31 /server/scripts/ 4) [admin@master ~]$ sudo salt --summary "*" cmd.run "uptime" node3.51yuki.cn: 14:55:36 up 2:51, 1 user, load average: 0.00, 0.01, 0.05 node2.51yuki.cn: 14:55:37 up 2:46, 1 user, load average: 0.00, 0.01, 0.05 ------------------------------------------- Summary ------------------------------------------- # of minions targeted: 2 # of minions returned: 2 # of minions that did not return: 0 # of minions with errors: 0 ------------------------------------------- 5) 采用yaml格式输出执行结果 [admin@master ~]$ sudo salt --out=yaml "*" cmd.run "uptime" node2.51yuki.cn: ' 14:56:38 up 2:47, 1 user, load average: 0.00, 0.01, 0.05' node3.51yuki.cn: ' 14:56:38 up 2:52, 1 user, load average: 0.00, 0.01, 0.05' 以上说明: 第一部分: salt命令本身 第二部分: 命令行选项 第三部分: 目标定位字符串 第四部分: salt模块 第五部分: 远程执行函数的参数