爱奇艺花样滑冰教程:批量管理服务器工具:pssh

来源:百度文库 编辑:偶看新闻 时间:2024/05/07 01:39:06

pssh是一个可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的。使用是必须在各个服务器上配置好密钥认证访问。

pssh 包安装 5 个实用程序:
parallel-ssh 在多个主机上并行地运行命令。
parallel-scp 把文件并行地复制到多个主机上。
parallel-rsync 通过 rsync 协议把文件高效地并行复制到多个主机上。
parallel-slurp 把文件并行地从多个远程主机复制到中心主机上。
parallel-nuke 并行地在多个远程主机上杀死进程。

1、安装

view plaincopy to clipboardprint?
  1. #debain系列
  2. apt-get install pssh
  3. #redhat系列
  4. yum -y install pssh

2、简单使用

view plaincopy to clipboardprint?
  1. Usage: pssh [OPTIONS] -h hosts.txt prog [arg0] ..
  2. -h --hosts hosts file (each line "host[:port] [user]")
  3. -l --user username (OPTIONAL)
  4. -p --par max number of parallel threads (OPTIONAL)
  5. -o --outdir output directory for stdout files (OPTIONAL)
  6. -e --errdir output directory for stderr files (OPTIONAL)
  7. -t --timeout timeout in seconds to do ssh to a host (OPTIONAL)
  8. -v --verbose turn on warning and diagnostic messages (OPTIONAL)
  9. -O --options SSH options (OPTIONAL)
  10. -P --print print output as we get it (OPTIONAL)
  11. -i --inline inline aggregated output for each server (OPTIONAL)
  12. Example: pssh -h nodes.txt -l irb2 -o /tmp/foo uptime

创建主机名列表:

view plaincopy to clipboardprint?
  1. vi nodes.txt
  2. 192.168.1.101
  3. 192.168.1.102
  4. 192.168.1.103
  5. 192.168.1.104

在各主机执行命令:w

  1. parallel-ssh -h nodes.txt -l root -P w

复制文件到各主机

  1. parallel-scp -h nodes.txt -l root test.txt /tmp/test.txt-scp