pssh是一个python编写的工具,它比ansible更轻量级。支持命令的批量执行、文件批量拷贝。
- pssh 在多个主机上并行运行命令
- pscp 把文件并行复制到多个主机上
- prsync 通过rsync协议把文件高效并行复制到多个主机上
- pslurp 把文件并行地从多个远程主机复制到中心主机上
- pnuke 并行地在多个远程主机上杀死进程
1、pssh安装
# 安装setuptools包,如果安装了跳过 wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz --no-check-certificate tar -xf setuptools-0.6c11.tar.gz cd setuptools-0.6c11 python setup.py build python setup.py install # 安装pssh cd - wget http://www.theether.org/pssh/pssh-1.4.3.tar.gz cd pssh-1.4.3/ python setup.py install
2、pssh
[root@node1]# pssh Usage: pssh [OPTIONS] -h hosts.txt prog [arg0] .. -h --hosts hosts file (each line "host[:port] [user]") -l --user username (OPTIONAL) -p --par max number of parallel threads (OPTIONAL) -o --outdir output directory for stdout files (OPTIONAL) -e --errdir output directory for stderr files (OPTIONAL) -t --timeout timeout (secs) (-1 = no timeout) per host (OPTIONAL) -O --options SSH options (OPTIONAL) -v --verbose turn on warning and diagnostic messages (OPTIONAL) -P --print print output as we get it (OPTIONAL) -i --inline inline aggregated output for each server (OPTIONAL) Example: pssh -h nodes.txt -l irb2 -o /tmp/foo uptime
3、pscp
[root@node1 ~]# pscp Usage: pscp [OPTIONS] -h hosts.txt local remote -r --recursive recusively copy directories (OPTIONAL) -h --hosts hosts file (each line "host[:port] [login]") -l --user username (OPTIONAL) -p --par max number of parallel threads (OPTIONAL) -o --outdir output directory for stdout files (OPTIONAL) -e --errdir output directory for stderr files (OPTIONAL) -t --timeout timeout (secs) (-1 = no timeout) per host (OPTIONAL) -v --verbose turn on warning and diagnostic messages (OPTIONAL) -O --options SSH options (OPTIONAL) Example: pscp -h hosts.txt -l irb2 foo.txt /home/irb2/foo.txt
4、prsync
要使用此命令,主机上必须要有rsync命令,否则执行不成功。
[root@node1 ~]# prsync Usage: prsync [OPTIONS] -h hosts.txt local remote -r --recursive recusively copy directories (OPTIONAL) -a --archive use rsync -a (archive mode) (OPTIONAL) -z --compress use rsync compression (OPTIONAL) -h --hosts hosts file (each line "host[:port] [login]") -l --user username (OPTIONAL) -p --par max number of parallel threads (OPTIONAL) -o --outdir output directory for stdout files (OPTIONAL) -e --errdir output directory for stderr files (OPTIONAL) -t --timeout timeout (secs) (-1 = no timeout) per host (OPTIONAL) -v --verbose turn on warning and diagnostic messages (OPTIONAL) -O --options SSH options (OPTIONAL) Example: prsync -r -h hosts.txt -l irb2 foo /home/irb2/foo
5、pslurp
[root@node1 ~]# pslurp Usage: pslurp [OPTIONS] -h hosts.txt -o outdir remote local -r --recursive recusively copy directories (OPTIONAL) -L --localdir output directory for remote file copies -h --hosts hosts file (each line "host[:port] [login]") -l --user username (OPTIONAL) -p --par max number of parallel threads (OPTIONAL) -o --outdir output directory for stdout files (OPTIONAL) -e --errdir output directory for stderr files (OPTIONAL) -t --timeout timeout (secs) (-1 = no timeout) per host (OPTIONAL) -v --verbose turn on warning and diagnostic messages (OPTIONAL) -O --options SSH options (OPTIONAL) Example: pslurp -h hosts.txt -L /tmp/outdir -l irb2 /home/irb2/foo.txt foo.txt
6、pnuke
[root@node1 ~]# pnuke Usage: pnuke [OPTIONS] -h hosts.txt pattern -h --hosts hosts file (each line "host[:port] [user]") -l --user username (OPTIONAL) -p --par max number of parallel threads (OPTIONAL) -o --outdir output directory for stdout files (OPTIONAL) -e --errdir output directory for stderr files (OPTIONAL) -t --timeout timeout (secs) (-1 = no timeout) per host (OPTIONAL) -v --verbose turn on warning and diagnostic messages (OPTIONAL) -O --options SSH options (OPTIONAL) Example: pnuke -h hosts.txt -l irb2 java
参考博客: