pssh -- parallel ssh program
pssh is a program for executing ssh in parallel on a number of hosts. It provides features such as sending input to all of the processes, passing a password to ssh, saving output to files, and timing out.
简单理解就是,可以通过ssh,去并行操作远程管理的服务器。
建议,最好可以免密码登录到所有远程管理的服务器,免去输入密码的麻烦。
网上有很多都是关于pssh的源码安装,我就不介绍了。下面介绍我的安装过程,很简单:
服务器操作系统:Centos 6.5 x64,本身yum源,可以直接安装 pssh。
# yum -y install pssh
pssh [options ...] comand ...
options:
-h host_file Read hosts from the given host_file. 格式为[user@]host[:port],默认是user为root,port为22,可省略
-H host host为[user@]host[:port],默认是user为root,port为22,可省略。可以后面接多个host
-l user 指定默认访问的用户
-t timeout 指定超时时间,单位为秒
-o outdir 指定标准输出信息的保存路径,注意是路径,不是文件
-i 显示标准输出和标准错误信息到终端
Command:shell脚本或者是linux的操作命令
Connect to host1 and host2, and print "hello, world" from each:
pssh -i -H "host1 host2" echo "hello, world"
Print "hello, world" from each host specified in the file hosts.txt:
pssh -i -h hosts.txt echo "hello, world"
Run a command as root with a prompt for the root password:
pssh -i -h hosts.txt -A -l root echo hi
Run a long command without timing out:
pssh -i -h hosts.txt -t 0 sleep 10000
pssh -h host_file -o out_start_log_directory-l user "export BASH_ENV=/etc/profile;项目升级脚本.sh"
nohup pssh -h host_file -lroot -t 0 -o out_log_directory "tail -f 项目日志路径" > out_nohup_log_directory &
本文出自 “Hades博客” 博客,请务必保留此出处http://hades02.blog.51cto.com/9768670/1722322
原文地址:http://hades02.blog.51cto.com/9768670/1722322