实例演示

   启动和关闭,重启master,client

   python环境根据实际编译情况设置

   /oaos/python/bin/python os_server1.3.py start/stop/restart

   /oaos/python/bin/python os_client1.3.py start/stop/restart

   客户端只需要部署client就行了

   任务增加和报告命令

   任务增加程序和master运行程序放在同一个目录,因为需要读取任务报告,例如,其中报告接口暂时只能在master端客户使用,否则无法获取到任务信息。

[root@salt-master-194 oaos]# ls
add_job1.3.py  job  log  os_client1.3.py  os_server1.3.py  run  task.ini


task.ini的内容如下,任务类别是直接执行命令,其中cmdtimeout因该小于jobtimeout的超时,否则会有客户端执行成功了,但是master监控job的时候超时的情况发送后续改进下。

[master]
sock=tcp://192.168.4.194:7777
[ip_list]
ip=192.168.4.195,192.168.4.196,192.168.4.197,192.168.4.198
[job_info]
type=c
task=ls -rlt
cmdtimeout=8
jobtimeout=10
env=sh
fileserver=http://192.168.0.227/ser/
rundir=/root/

增加该任务运行和返回结果如下。

[root@salt-master-194 oaos]# python add_job1.3.py
job add ok,job log job/1425270675.log
----------------------job report start--------------------------
job 1425270675 start
192.168.4.195 code:0
total 114
drwxr-xr-x.   2 root root  4096 Sep 23  2011 srv
drwxr-xr-x.   2 root root  4096 Sep 23  2011 mnt
drwxr-xr-x.   2 root root  4096 Feb 21  2013 cgroup
dr-xr-xr-x    7 root root  4096 Mar  5  2013 media
drwx------.   2 root root 16384 Sep  3 04:20 lost+found
drwxr-xr-x.   2 root root  4096 Sep  3 04:20 selinux
drwxr-xr-x.  13 root root  4096 Sep  3 04:20 usr
drwxr-xr-x.  20 root root  4096 Sep  3 04:24 var
drwxr-xr-x.   3 root root  4096 Sep  3 04:24 opt
dr-xr-xr-x.   5 root root  1024 Sep  3 04:36 boot
drwxr-xr-x.   3 root root  4096 Sep  3 04:53 home
dr-xr-xr-x.   2 root root 12288 Sep  3 05:26 sbin
dr-xr-xr-x  103 root root     0 Feb 13 08:52 proc
drwxr-xr-x   13 root root     0 Feb 13 08:52 sys
drwxr-xr-x    2 root root     0 Feb 13 08:53 misc
drwxr-xr-x    2 root root     0 Feb 13 08:53 net
drwxr-xr-x   16 root root  3660 Feb 13 08:53 dev
dr-xr-xr-x.  11 root root  4096 Feb 13 09:11 lib
dr-xr-xr-x.   9 root root 12288 Feb 13 09:21 lib64
dr-xr-x---.   5 root root  4096 Feb 14 07:10 root
drwxr-xr-x    8 root root  4096 Feb 14 10:31 app
drwxr-xr-x    5 root root  4096 Feb 28 01:21 oaos
dr-xr-xr-x.   2 root root  4096 Feb 28 03:06 bin
drwxr-xr-x.  99 root root 12288 Feb 28 03:06 etc
drwxrwxrwt.   4 root root  4096 Mar  1 03:43 tmp
192.168.4.194 code:0
total 5847912
drwxr-xr-x   7  201   201       4096 Nov 17  2012 vmware-tools-distrib
-rw-r--r--.  1 root root        7572 Sep  3 04:24 install.log.syslog
-rw-r--r--.  1 root root       26505 Sep  3 04:25 install.log
-rw-------.  1 root root        1249 Sep  3 04:25 anaconda-ks.cfg
-r--r--r--   1 root root    66611473 Sep  3 04:43 VMwareTools-8.6.10-913593.tar.gz
-rwx------   1 root root  4353378304 Sep  3 04:58 CentOS-6.4-x86_64-bin-DVD1.iso
-rwx------   1 root root  1452388352 Sep  3 04:59 CentOS-6.4-x86_64-bin-DVD2.iso
-rw-r--r--   1 root root    32979820 Sep  3 05:17 mysql-5.6.20.tar.gz
-rw-r--r--   1 root root    34601551 Sep  3 05:17 percona-xtrabackup-2.2.3.tar.gz
-rwxr-xr-x   1 root root       58069 Sep  3 05:17 orzdba.pl
-rw-r--r--   1 root root    16657930 Feb 12 21:42 Python-2.7.9.tgz
drwxr-xr-x  18 1000  1000       4096 Feb 13 01:45 Python-2.7.9
-rw-r--r--   1 root root      634944 Feb 13 01:46 setuptools-12.1.tar.gz
drwxrwxrwx  10 root root        4096 Feb 13 01:46 setuptools-12.1
-rw-r--r--   1 root root     1200024 Feb 13 01:47 pip-6.0.8.tar.gz
drwxr-xr-x   7 salt games       4096 Feb 13 01:47 pip-6.0.8
-rw-r--r--   1 root root    29650115 Feb 14 04:28 salt_stack.tar.gz
drwxrwxr-x  23 salt salt        4096 Feb 14 04:35 stack
drwxr-xr-x   2 root root        4096 Feb 28 10:19 run
drwxr-xr-x   2 root root        4096 Feb 28 10:19 log
drwxr-xr-x   2 root root        4096 Mar  1 23:28 bak
192.168.0.61 code:0
total 178
drwxrwxr-x   4 oracle dba   4096 Nov 24  2010 oracle
drwxr-xr-x   2 root   root  4096 May 11  2011 srv
drwxr-xr-x   2 root   root  4096 May 11  2011 mnt
drwx------   2 root   root 16384 Sep 20  2012 lost+found
drwxr-xr-x   2 root   root  4096 Sep 20  2012 selinux
drwxr-xr-x  15 root   root  4096 Sep 20  2012 usr
drwxr-xr-x   4 root   root  1024 Sep 20  2012 boot
drwxr-xr-x  23 root   root  4096 Sep 20  2012 var
drwxr-xr-x   3 root   root  4096 Sep 20  2012 opt
drwxr-xr-x   9 root   root 12288 Sep 20  2012 lib64
drwxr-xr-x  11 root   root  4096 Sep 20  2012 lib
drwxr-xr-x   2 root   root 12288 Sep 20  2012 sbin
drwxr-x---  16 root   root  4096 Nov 22  2012 root
drwxr-xr-x   4 wls    bea   4096 Dec 26  2012 bea
dr-xr-xr-x 138 root   root     0 Jan  7  2013 proc
drwxr-xr-x  11 root   root     0 Jan  7  2013 sys
drwxr-xr-x   2 root   root  4096 Jan  7  2013 media
drwxr-xr-x   2 root   root     0 Jan  7  2013 misc
drwxr-xr-x   2 root   root     0 Jan  7  2013 net
drwxr-xr-x  11 root   root  4096 Jul 24  2014 home
drwxr-xr-x  18 root   root  4096 Aug 19  2014 app
drwxr-xr-x   2 root   root  4096 Oct 24 04:02 bin
drwxr-xr-x  10 root   root  3840 Feb 21 04:02 dev
drwxr-xr-x  94 root   root 12288 Feb 28 04:02 etc
drwxr-xr-x   5 root   root  4096 Feb 28 14:20 oaos
drwxrwxrwt   8 root   root  4096 Mar  2 04:02 tmp
192.168.4.196 code:0
total 5829828
drwxr-xr-x   7  201  201       4096 Nov 17  2012 vmware-tools-distrib
-rw-r--r--.  1 root root       7572 Sep  3 04:24 install.log.syslog
-rw-r--r--.  1 root root      26505 Sep  3 04:25 install.log
-rw-------.  1 root root       1249 Sep  3 04:25 anaconda-ks.cfg
-r--r--r--   1 root root   66611473 Sep  3 04:43 VMwareTools-8.6.10-913593.tar.gz
-rwx------   1 root root 4353378304 Sep  3 04:58 CentOS-6.4-x86_64-bin-DVD1.iso
-rwx------   1 root root 1452388352 Sep  3 04:59 CentOS-6.4-x86_64-bin-DVD2.iso
-rw-r--r--   1 root root   32979820 Sep  3 05:17 mysql-5.6.20.tar.gz
-rw-r--r--   1 root root   34601551 Sep  3 05:17 percona-xtrabackup-2.2.3.tar.gz
-rwxr-xr-x   1 root root      58069 Sep  3 05:17 orzdba.pl
-rw-r--r--   1 root root   29650115 Feb 13 08:55 salt_stack.tar.gz
-rw-r--r--   1 root root        116 Feb 13 09:03 setup.cfg
drwxrwxr-x  23  501  501       4096 Feb 13 10:02 stack
job 1425270675 end
----------------------job report end---------------------------
You have new mail in /var/spool/mail/root




task.ini的内容如下,任务类别是运行脚本,脚本名为chgpass.sh,作用是变更某个用户的密码

[master]
sock=tcp://192.168.4.194:7777
[ip_list]
ip=192.168.4.195,192.168.4.196,192.168.4.197,192.168.4.198
[job_info]
type=s
task=chgpass.sh
cmdtimeout=8
jobtimeout=10
env=sh
fileserver=http://192.168.0.227/ser/
rundir=/root/


执行和输出如下

[root@salt-master-194 oaos]# python add_job1.3.py
job add ok,job log job/1425270947.log
----------------------job report start--------------------------
job 1425270947 start
192.168.4.195 code:252
passwd: Unknown user name 'oracle'.
192.168.0.61 code:0
Changing password for user oracle.
passwd: all authentication tokens updated successfully.
192.168.4.196 code:252
passwd: Unknown user name 'oracle'.
192.168.4.194 code:252
passwd: Unknown user name 'oracle'.
job 1425270947 end
----------------------job report end---------------------------



大概就这么个简单的小东西了,时间比较紧只是简单的弄了下有兴趣或疑问可以留言。


One Response


    还没有评论!
1  

Leave your comment

请留下您的姓名(*)

请输入正确的邮箱地址(*)

请输入你的评论(*)


感谢开源 © 2016. All rights reserved.&3Q Open Source&^_^赣ICP备15012863^_^
乐于分享共同进步 KreativeThemes