Saltstack基本指令

网友投稿 294 2022-10-30


Saltstack基本指令

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。如:

简单其它测试:

2.1.1  运行函数

[root@node2 ~]# salt 'node4' disk.usage node4:     ----------     /:         ----------         1K-blocks:             18003272         available:             8076744         capacity:             53%         filesystem:             /dev/mapper/vg_node4-lv_root         used:             9005340     /boot:         ----------         1K-blocks:             487652         available:             436616         capacity:             6%         filesystem:             /dev/sda1         used:             25436     /dev/shm:         ----------         1K-blocks:             236964         available:             236952         capacity:             1%         filesystem:             tmpfs         used:             12     /opt/ren:         ----------         1K-blocks:             4523182         available:             0         capacity:             100%         filesystem:             /dev/sr0         used:             4523182 [root@node2 ~]#

2.1.2 运行shell命令

[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.1.3 安装一个包

master:

[root@node2 ~]# salt 'node4'  pkg.install httpd node4:     ----------     apr:         ----------         new:             1.3.9-5.el6_2         old:     apr-util:         ----------         new:             1.3.9-3.el6_0.1         old:     apr-util-ldap:         ----------         new:             1.3.9-3.el6_0.1         old:     httpd:         ----------         new:             2.2.15-54.el6.centos         old:     httpd-tools:         ----------         new:             2.2.15-54.el6.centos         old:     mailcap:         ----------         new:             2.1.31-2.el6         old: [root@node2 ~]#

minion查看:

[root@node4 ~]# /etc/init.d/httpd start 正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.223 for ServerName                                                            [确定] [root@node4 ~]# netstat -atupn|grep 80 tcp        0      0 192.168.1.223:36333         218.145.173.89:80           TIME_WAIT   -                    tcp        0      0 192.168.1.223:34724         124.202.159.69:80           TIME_WAIT   -                    tcp        0      0 192.168.1.223:38747         210.32.158.231:80           TIME_WAIT   -                    tcp        0      0 192.168.1.223:34713         124.202.159.69:80           TIME_WAIT   -                    tcp        0      0 :::80                       :::*                        LISTEN      3521/httpd           [root@node4 ~]#

2.1.4 网络接口列表:

[root@node2 ~]# salt 'node4' network.interfaces node4:     ----------     eth0:         ----------         hwaddr:             00:0c:29:5a:9b:81         inet:             |_               ----------               address:                   192.168.1.223               broadcast:                   192.168.1.255               label:                   eth0               netmask:                   255.255.255.0         inet6:             |_               ----------               address:                   fe80::20c:29ff:fe5a:9b81               prefixlen:                   64               scope:                   link         up:             True     lo:         ----------         hwaddr:             00:00:00:00:00:00         inet:             |_               ----------               address:                   127.0.0.1               broadcast:                   None               label:                   lo               netmask:                   255.0.0.0         inet6:             |_               ----------               address:                   ::1               prefixlen:                   128               scope:                   host         up:             True [root@node2 ~]#

2 .2  内置执行模块

官方模块地址:~]# salt 'node4' disk.usage

具体的用法可查看帮助 salt --help或者man salt(比如执行一些脚本等,后续再写。)

继续学习: Saltstack学习笔记(3)


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:内存治理常识点总结
下一篇:输出/输入(I/O)常识点汇总
相关文章

 发表评论

暂时没有评论,来抢沙发吧~