1.5 Salt 命令介绍(常用的这些一定要多练习)
命令 功能描述
salt Salt 主命令,比如执行命令模块
satl-cp 复制文件到指定的系统上去
salt-key 和 Minion 之间进行身份验证
salt-master Master 主守护进程,用于控制 Minion
salt-run 前端命令执行
salt-syndic Salt syndic 守护进程,用于多级 salt-master 使用
备注:具体命令的详细内容,可以查看 man 手册。
master:(只开启ssh和saltstack相关服务)
[root@node2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.223 node4
192.168.1.221 node2
[root@node2 ~]#
[root@node2 ~]# netstat -atupn
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:4505 0.0.0.0:* LISTEN 2897/python2.6
tcp 0 0 0.0.0.0:4506 0.0.0.0:* LISTEN 2915/python2.6
tcp 0 0 0.0.0.0:21386 0.0.0.0:* LISTEN 1087/sshd
tcp 0 52 192.168.1.221:21386 192.168.1.243:61308 ESTABLISHED 8108/sshd
tcp 0 0 192.168.1.221:4505 192.168.1.223:58448 ESTABLISHED 2897/python2.6
tcp 0 0 192.168.1.221:4506 192.168.1.223:53912 ESTABLISHED 2915/python2.6
tcp 0 0 :::21386 :::* LISTEN 1087/sshd
[root@node2 ~]#
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
minion:(只开启ssh和saltstack相关服务)
[root@node4 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.223 node4
192.168.1.221 node2
[root@node4 ~]#
[root@node4 ~]# netstat -atupn
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2458/sshd
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 3058/sshd
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 3111/sshd
tcp 0 0 127.0.0.1:6014 0.0.0.0:* LISTEN 2423/sshd
tcp 0 0 192.168.1.223:22 192.168.1.243:61309 ESTABLISHED 3058/sshd
tcp 0 52 192.168.1.223:22 192.168.1.243:61742 ESTABLISHED 3111/sshd
tcp 0 0 192.168.1.223:53912 192.168.1.221:4506 ESTABLISHED 2846/python2.6
tcp 0 0 192.168.1.223:22 192.168.1.243:62260 ESTABLISHED 2423/sshd
tcp 0 0 192.168.1.223:58448 192.168.1.221:4505 ESTABLISHED 2846/python2.6
tcp 0 0 :::22 :::* LISTEN 2458/sshd
tcp 0 0 ::1:6010 :::* LISTEN 3058/sshd
tcp 0 0 ::1:6011 :::* LISTEN 3111/sshd
tcp 0 0 ::1:6014 :::* LISTEN 2423/sshd
[root@node4 ~]#
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 Saltstack 命令执行
2 .1 cmd.run(比如我在node4执行两个伪终端)
Saltstack 可以远程执行 shell 命令,使用 cmd.run。如:
[root@node2 ~]# salt ‘node4‘ cmd.run ‘w‘
node4:
15:14:17 up 5:26, 4 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 - 09:48 4:48m 0.06s 0.06s -bash
root pts/0 192.168.1.243 15:03 39.00s 0.03s 0.03s -bash
root pts/1 192.168.1.243 15:13 36.00s 0.00s 0.00s -bash
root pts/4 192.168.1.243 10:25 2:17m 0.15s 0.15s -bash
[root@node2 ~]#
测试:
1、查看内存,磁盘,cpu等信息
[root@node2 ~]# salt ‘node4‘ cmd.run ‘free -m&& df -TH && uptime‘
node4:
total used free shared buffers cached
Mem: 462 360 102 0 11 231
-/+ buffers/cache: 117 345
Swap: 1983 0 1983
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_node4-lv_root
ext4 19G 9.3G 8.3G 53% /
tmpfs tmpfs 243M 13k 243M 1% /dev/shm
/dev/sda1 ext4 500M 27M 448M 6% /boot
/dev/sr0 iso9660 4.7G 4.7G 0 100% /opt/ren
15:26:43 up 5:39, 3 users, load average: 0.03, 0.02, 0.00
[root@node2 ~]#
由于 cmd.run 可以执行所有的命令,所以不建议在生产环境中使用 cmd.run,同时,saltstack 提
供了大量的命令模块可以使用。
2 .2 内置执行模块
官方模块地址:http://docs.saltstack.com/ref/modules/all/index.html
下面介绍几个常用的内置命令模块
[root@master ~]# salt ‘node4‘ disk.usage
具体的用法可查看帮助 salt --help或者man salt(比如执行一些脚本等,后续再写。)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
继续学习: Saltstack学习笔记(3)
本文出自 “renzhiyuan@chinacfsc.com” 博客,谢绝转载!
原文地址:http://renzhiyuan.blog.51cto.com/10433137/1843698