dsh:分布式 shell

[撰文/hmy]

dsh 简单说来就是可以同时通过 ssh 来控制多台机器。

在 dsh 的配置文件里面可以把机器分组,然后在 dsh 的选项里面指定对那个组进行操作,比如

dsh -g www -c “w”

将对所有输入 www 组的机器执行 w 命令。

执行命令可以并行执行,也可以串行执行。并行执行是把命令同时发给所有机器,串行执行是一个一个机器的执行。等上一个机器执行完了再执行下一个机器。

这个命令对维护多个机器的同学应该有用。不用老是用 for 循环了。

Read More:

  • No related posts

15 Comments

  1. 1 isun Commented @ 2008-08-20 19:35Reply to this comment

    好东西

  2. 2 iveney Commented @ 2008-08-21 0:46Reply to this comment

    我刚搞完…… 用for来弄的……very nasty toy早点介绍就好了……

  3. 3 slackcode Commented @ 2008-08-21 1:09Reply to this comment

    这个... 把机器的ssh功能打开,用xshell就可以实现这个功能了

    可以多部同时发送同一个命令

    xshell有home/free版本

  4. 4 hmy Commented @ 2008-08-21 6:33Reply to this comment

    @slackcode
    xshell 好像还没听说过,能提交一个文章详细推荐下吗,呵呵,有什么好东西别藏着揶着,借toy这个宝地推荐一下。帮助一些人少走弯路。

  5. 5 coneagoe Commented @ 2008-08-21 8:25Reply to this comment

    见识了,我用不到。

  6. 6 giv Commented @ 2008-08-21 10:50Reply to this comment

    dsh是怎么避免每台机器上的口令输入的呢? ssh-agent还是?

  7. 7 hmy Commented @ 2008-08-21 11:11Reply to this comment

    @giv ssh用证书登录,不用密码。证书登录比密码安全很多。

  8. 8 giv Commented @ 2008-08-21 11:24Reply to this comment

    @hmy 你的意思是说用无密码保护的证书? 是这样的, 我们一般都是用有密码保护的证书, 为了便于在机群上工作, 通常是开一个ssh-agent, 然后用ssh-add添加一个证书, 这样ssh到其他服务器时就不用再输入证书密码了 我想知道dsh是怎么做来保证安全性的?

  9. 9 hmy Commented @ 2008-08-21 11:51Reply to this comment

    恩,dsh是利用ssh,安全性还是ssh来保障,我也是用的ssh-agent,不过加了一个keychian软件,这个软件可以避免重复输入ssh证书的密码。

  10. 10 giv Commented @ 2008-08-21 12:59Reply to this comment

    @hmy 噢, 这样, 谢谢

  11. 11 cssh:cluster 管理工具 (ssh) | 搜我收藏 Pingbacked @ 2008-08-22 11:48Reply to this comment

    [...] 同 dsh 类似,通过 ssh 同时给多台机器发命令,不过 cssh [...]

  12. 12 可冰 Commented @ 2008-08-26 19:05Reply to this comment

    请问知不知道有没有反向的SSH? 通常是在内网用ssh连外网机器,假如现在在外网,需要登录到内网机器上测试一些东西,就不行了。想过自己实现一个反向的ssh,在外网机器上开一个服务器,在内网开一个客户端,连上外网的服务器,如果要控制的话,就在外网机器上的服务器shell中执行。如果有现成的话就好了。

  13. 13 hmy Commented @ 2008-08-26 20:01Reply to this comment

    @可冰 假设外网ip 2.2.2.2,内部ip 192.168.0.1 内部机器先 ssh -R 222:127.0.0.1:22 root@2.2.2.2 然后在2.2.2.2这个机器上执行 ssh -p 222 root@127.0.0.1 就ok了 如果你外部机器不是常开着,你可以让需要在内部机器执行的哪个命令一直循环执行.

  14. 14 可冰 Commented @ 2008-08-29 15:00Reply to this comment

    谢谢hmy! 不过我没有成功。 我在我的机器上以root用户执行 ssh -R 20081:127.0.0.1:20083 username@servername 会有提示Warning: remote port forwarding failed for listen port 20081 我想可能是在外网机上的权限不够吧。

    然后用内网机试了一下 ssh -R 20081:127.0.0.1:20083 username@localservername 好像是成功了,但在localservername上执行 ssh -p 20081 root@127.0.0.1 -v 会有如下提示 OpenSSH3.9p1, OpenSSL 0.9.7a Feb 19 2003 debug1: Reading configuration data /etc/ssh/sshconfig debug1: Applying options for * debug1: Connecting to 127.0.0.1 [127.0.0.1] port 20081. debug1: Connection established. debug1: permanentlysetuid: 0/0 debug1: identity file /root/.ssh/identity type -1 debug1: identity file /root/.ssh/idrsa type -1 debug1: identity file /root/.ssh/iddsa type -1 sshexchangeidentification: Connection closed by remote host

    上网查了下,也没能解决这个问题,它是否需要其它额外的设置?

  15. 15 Eric Commented @ 2009-01-29 23:44Reply to this comment

    还有 pssh(比较成熟的项目) http://www.theether.org/pssh/

    erlyssh(Erlang实现的,支持交互式的shell,可cd切换目录) http://code.google.com/p/erlyssh/

    都是很好的分布式ssh shell工具。:D