Tips: 本文创建于2015年11月13日,已超过 2 年,内容或图片可能已经失效!

自动化运维mussh

mussh.jpg

mussh可以实现批量管理多台远程主机的功能。重点mussh执行脚本的功能

官网

tar zxvf mussh-1.0.tgz #解压出来直接可用  
  
./mussh --help  
Usage: mussh [OPTIONS] <-h host.. | -H hostfile> [-c cmd] [-C scriptfile]  
mussh --help        for full help text  
  
Send a command or list of commands to multiple hosts.  
  
OPTIONS:  
        --help          This text.  
        -d [n]          Verbose debug.  Prints each action, all hosts  
                        and commands to be executed to STDERR.  'n' can  
                        be from 0 to 2.  
        -v [n]          Ssh debug levels.  Can be from 0 to 3.  
        -m [n]          Run concurrently on 'n' hosts at a time (asynchronous). #用来开启mussh的并发执行操作。在管理的主机比较多时,建议设置此参数  
                        Use '0' (zero) for infinite. (default if -m)  
        -q              No output unless necessary.   
        -i <identity> [identity ..]  
                        Load an identity file.  May be used  
                        more than once.  
        -o <ssh-args>   Args to pass to ssh with -o option. #可以引入ssh参数的具体配置。eg: mussh -o StrictHostKeyChecking=no  
        -a              Force loading ssh-agent.  
        -A              Do NOT load ssh-agent.  
        -b              Print each hosts' output in a block without mingling  
                        with other hosts' output.  
        -B              Allow hosts' output to mingle. (default)  
        -u              Unique.  Eliminate duplicate hosts. (default)   #取出重复的主机名,mussh已经默认  
        -U              Do NOT make host list unique.   #不管主机名是否重复  
        -P              Do NOT fall back to passwords on any host.  This will  
                        skip hosts where keys fail.  
    -l <login>      Use 'login' when no other is specified with hostname.   #指定在远程主机上执行命令的用户  
    -L <login>      Force use of 'login' name on all hosts.  
        -s <shell>      Path to shell on remote host. (Default: bash)   #指定在远程主机上执行脚本的shell路径。eg: mussh -s /usr/bin/python -C mysql_check.py  
        -t <secs>       Timeout setting for e
ach session.  
                        (requires openssh 3.8 or newer)  
        -V              Print version info and exit.  
PROXY ARGS:  
        -p [[email protected]]<host>  
                        Host to use as proxy.  (Must have mussh installed)  
        -po <ssh-args>        Args to pass to ssh on proxy with -o option.  
HOST ARGS:  
        -h [[email protected]]<host> [[[email protected]]<host> ..] #指定远程主机,多个用空格隔开  
                        Add a host to list of hosts.  May be  
                        used more than once.  
        -H <file> [file ..]     #指定一组主机列表  
                        Add contents of file(s) to list of hosts.  
                        Files should have one host per line.  Use  
                        "#" for comments.  
COMMAND ARGS:  
If neither is specified, commands will be read from standard input.  
        -c <command>    Add a command or quoted list of commands and    #指定在远程主机上要执行的命令,多个命令用分号隔开  
                        args to list of commands to be executed on  
                        each host.  May be used more than once.  
        -C <file> [file ..]     #指定一个本机脚本,然后这个脚本会在多个远程主机上运行  
                        Add file contents to list of commands to be  
                        executed on each host.  May be used more  
                        than once.  
  
At least one host is required.  Arguments are in no particular order.  
  
EXAMPLES:  
mussh -H ./linuxhosts -C spfiles/testscript.sh  
mussh -c "cat /etc/hosts" -h myhost.mydomain.com  
  
Comments and Bug Reports: [email protected] 

应用

./mussh -h [email protected] [email protected] -c uptime  
[email protected]: 14:03:05 up  4:58,  2 users,  load average: 0.00, 0.00, 0.00  
[email protected]: 14:03:04 up 3 days,  5:43,  3 users,  load average: 0.00, 0.00, 0.00  
  
more /home/opsuser/myhosts  
  
192.168.1.100  
192.168.1.101  
192.168.1.102  
  
mussh -H myhosts -l opsuser -c uptime  
  
mussh -o "port=22" -H myhosts -s /usr/bin/python -C "/home/opsuser/checkos.py"