Chinaunix首页 | 论坛 | 博客
  • 博客访问: 154314
  • 博文数量: 13
  • 博客积分: 45
  • 博客等级: 民兵
  • 技术积分: 871
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-02 10:59
个人简介

Nobody.

文章分类

全部博文(13)

文章存档

2013年(13)

分类: 系统运维

2013-06-24 11:16:06

服务器批量管理工具一文中,提到了几款服务器批量管理工具,本文就其中的mussh、pdsh、pssh简单介绍其使用方法。

1、mussh
mussh的安装过程不再赘述,要使用mussh要先做好主机间的信任(方法自己查询)
mussh的使用较简单,要查询mussh的使用方法,可以

  1. mussh --help
常用的方法如下:

  1. mussh -m -u -b -t 6 -h user@x.x.x.x.. -c cmd
  2. mussh -m -u -b -t 6 -h user@x.x.x.x.. -C scriptfile
  3. mussh -m -u -b -t 6 -H hostlist -c cmd
  4. mussh -m -u -b -t 6 -H hostlist -C scriptfile
其中hostlist的格式为:

  1. user@x.x.x.x
  2. user@x.x.x.x
  3. user@x.x.x.x
  4. ..
常见命令行参数意义:

  1. -m [n] Run concurrently on 'n' hosts at a time (asynchronous).
  2. Use '0' (zero) for infinite. (default if -m)
  3. -b Print each hosts' output in a block without mingling
  4. with other hosts' output.
  5. -B Allow hosts' output to mingle. (default)
  6. -u Unique. Eliminate duplicate hosts. (default)
  7. -U Do NOT make host list unique.
  8. -t Timeout setting for each session.
  9. (requires openssh 3.8 or newer)

2、pdsh
pdsh的安装过程不再赘述,要使用pdsh有两个前提:
1、做好主机间的信任(方法自己查询)
2、管理机和目标机均安装pdsh(不然无法使用pdcp和rpdcp)

可以通过

  1. man pdsh 或 pdsh -h
  2. man pdcp 或 pdcp -h
  3. man rpdcp 或 rpdcp -h
来查询使用方法
常用的方法如下:

  1. pdsh -R ssh -l root -w x.x.x.x cmd
  2. pdsh -R ssh -l root -w hostname cmd
  3. pdsh -R ssh -l root -w ^hostlist cmd
其中hostlist的格式为:

  1. x.x.x.x
  2. hostname
  3. ..
若不加cmd,则进入交互模式,我觉得这个是pdsh的亮点。

3、pssh
pssh的安装不再赘述,要使用pssh要先做好主机间的信任(方法自己查询)

pssh安装完成,会出现一下五个命令:

  1. pssh parallel-ssh 在多个主机上并行地运行命令。
  2. pscp parallel-scp 把文件并行地复制到多个主机上。
  3. prsync parallel-rsync 通过 rsync 协议把文件高效地并行复制到多个主机上。
  4. pslurp parallel-slurp 把文件并行地从多个远程主机复制到中心主机上。
  5. pnuke parallel-nuke 并行地在多个远程主机上杀死进程。
要查各个命令的使用方法,可以不加任何参数运行该命令,这样就会出现各选项的意义。如:

  1. [winway@winway test]$ pssh
  2. Usage: pssh [OPTIONS] -h hosts.txt prog [arg0] ..
  3. -h --hosts hosts file (each line "host[:port] [user]")
  4. -l --user username (OPTIONAL)
  5. -p --par max number of parallel threads (OPTIONAL)
  6. -o --outdir output directory for stdout files (OPTIONAL)
  7. -e --errdir output directory for stderr files (OPTIONAL)
  8. -t --timeout timeout (secs) (-1 = no timeout) per host (OPTIONAL)
  9. -O --options SSH options (OPTIONAL)
  10. -v --verbose turn on warning and diagnostic messages (OPTIONAL)
  11. -P --print print output as we get it (OPTIONAL)
  12. -i --inline inline aggregated output for each server (OPTIONAL)
  13. Example: pssh -h nodes.txt -l irb2 -o /tmp/foo uptime
常用的方法如下:

  1. pssh -h hostlist -i cmd
  2. pscp -h hostlist src dest
  3. pslurp -h hostlist -L . dest src

4、总结
综上所述,mussh、pdsh、pssh各有优缺点,我的选择是:
批量在远程主机上执行比较固定的操作时,用mussh,特别是它支持本机脚本远程执行;
批量在远程主机上执行不确定的操作时,用pdsh,因为它支持交互模式;
批量在远程主机上上传、下载文件时用pssh的pscp或prsync、pslurp;
个人愚见,欢迎指正。
阅读(8345) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~