分布式机器管理小结
时间:2009-07-02 来源:CUDev
最近一直在忙项目验收,没有写多少blog,现在补上。
现在项目中需要大量的机器一起跑实验,以前师兄是写了一个expect脚本来串行的登录到各个机器,然后执行相应的命令,但是这么下来,下发实验开始的命令就要10几分钟。实在,忍不了,便开始寻找一些分布式机器管理软件。
软件一:omnitty
缺点:
1. 所有的操作都是手动完成,不能自动完成
2. 不能指定登录用户名,但是可以在host指定上使用一些技巧,例如 [email protected]
3. 不能指定端口
注意:实际上是omnitty在读取文件有问题,可以使用下面的patch解决问题,patch针对omnitty-0.3.0:
可以直接下载打过patch的源码包:
优点:
1. 广播模式非常方便
2. 支持密码登录,在广播模式下,所有机器密码一样的情况下,登录非常方便;如果密码不一样,只能挨个敲密码了;-(
软件二:dsh
缺点:
1.不能指定登录用户名,但是可以在host指定上使用一些技巧,例如 [email protected]
2.必须使用密钥登录
3.只有ssh的功能,没有scp的功能
注意:dsh指定端口的方法
优点:
1. 输出到标准输出上,看起来比较方便
一个在分布式机器上运行一条命令的shell脚本RunCmd.sh:
软件三: pssh
缺点:
1. 在执行命令的时候,所有的输出只能够存放到一个文件中,有些不方便
2. 必须使用密钥登录
优点:
1. 可以指定不同的登录用户
2. 支持scp功能,包括从本地拷贝文件到远端,从远端拷贝文件到本地
脚本scpl2r.sh,将文件从本地拷贝道远端
脚本scpr2l.sh,将文件从远端拷贝到本地
参考:
http://omnitty.sourceforge.net/
http://www.netfort.gr.jp/~dancer/software/dsh.html.en
http://www.theether.org/pssh/
现在项目中需要大量的机器一起跑实验,以前师兄是写了一个expect脚本来串行的登录到各个机器,然后执行相应的命令,但是这么下来,下发实验开始的命令就要10几分钟。实在,忍不了,便开始寻找一些分布式机器管理软件。
软件一:omnitty
缺点:
1. 所有的操作都是手动完成,不能自动完成
2. 不能指定登录用户名,但是可以在host指定上使用一些技巧,例如 [email protected]
3. 不能指定端口
注意:实际上是omnitty在读取文件有问题,可以使用下面的patch解决问题,patch针对omnitty-0.3.0:
diff -uNr omnitty-0.3.0/main.c omnitty-0.3.0-patched/main.c --- omnitty-0.3.0/main.c 2005-10-26 06:08:25.000000000 +0800 +++ omnitty-0.3.0-patched/main.c 2009-07-03 16:44:03.000000000 +0800 @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Copyright (c) 2002 Bruno T. C. de Oliveira */ +#define _GNU_SOURCE +#include <stdio.h> #include <ncurses.h> #include <sys/types.h> @@ -243,10 +245,19 @@ } static void add_machines_from_file(const char *file) { - static char buf[128]; + //Fixed by WangYao 09-07-03 + //static char buf[128]; + char *buf = NULL; bool pipe = false; FILE *f; + buf = (char *)malloc(128); + if(buf == NULL) + { + perror("malloc"); + exit(-1); + } + if (getenv("OMNITTY_AT_COMMAND")) { /* popen() a command */ pipe = true; @@ -268,7 +279,19 @@ minibuf_put(minibuf, pipe ? "Adding machines supplied by command..." : "Adding machines from file...", 0x70); - while (1 == fscanf(f, "%s", buf)) machmgr_add(buf); + //Fixed by WangYao 09-07-03 + //-p 10000 [email protected] + //while (1 == fscanf(f, "%s", buf)) machmgr_add(buf); + ssize_t nread=0; + size_t len=127; + while ((nread = getline(&buf, &len, f)) != -1) + { + machmgr_add(buf); + memset(buf, 0, sizeof(buf)); + } + + if(buf) + free(buf); if (pipe) { if (0 != pclose(f)) |
|
优点:
1. 广播模式非常方便
2. 支持密码登录,在广播模式下,所有机器密码一样的情况下,登录非常方便;如果密码不一样,只能挨个敲密码了;-(
软件二:dsh
缺点:
1.不能指定登录用户名,但是可以在host指定上使用一些技巧,例如 [email protected]
2.必须使用密钥登录
3.只有ssh的功能,没有scp的功能
注意:dsh指定端口的方法
$ dsh -M -c -f host -o -p10000 uname |
优点:
1. 输出到标准输出上,看起来比较方便
一个在分布式机器上运行一条命令的shell脚本RunCmd.sh:
#!/bin/sh DSH=/usr/bin/dsh #$DSH -M -c -f hosts/root@host "$@" $DSH -M -c -f hosts/root@host $* |
软件三: pssh
缺点:
1. 在执行命令的时候,所有的输出只能够存放到一个文件中,有些不方便
2. 必须使用密钥登录
优点:
1. 可以指定不同的登录用户
2. 支持scp功能,包括从本地拷贝文件到远端,从远端拷贝文件到本地
脚本scpl2r.sh,将文件从本地拷贝道远端
#!/bin/sh if [ $# -ne 2 ];then echo "Usage: scpl2r.sh localfile remotefile" exit fi srcfile=$1 dstfile=$2 PSCP=/usr/bin/parallel-scp $PSCP -h hosts/host -l root $srcfile $dstfile |
脚本scpr2l.sh,将文件从远端拷贝到本地
#!/bin/sh if [ $# -ne 2 ];then echo "Usage: scpl2r.sh localfile remotefile" exit fi srcfile=$1 dstfile=$2 PSLURP=/usr/bin/parallel-slurp $PSLURP -h hosts/host -l root -L log/ $srcfile $dstfile |
参考:
http://omnitty.sourceforge.net/
http://www.netfort.gr.jp/~dancer/software/dsh.html.en
http://www.theether.org/pssh/
相关阅读 更多 +