• 安装ssh-batch工具


    关于sshbatch

    sshbatch是用perl写了非常方便操作管理集群的一个工具,项目的源码在GitHub托管。

    关于sshbatch以及其详细的使用方法,春哥在GitHub上介绍的非常详细了,详情可以前往sshbatch主页查询。

    安装

    源码安装

    可以在从GitHub下载源码,并使用源码安装,安装步骤如下

    perl Makefile.PL
    make
    make test
    sudo make install

    cpan安装

    sshbatch是perl语言写,在Perl程序库CPAN里也存在,我们也可以使用cpan命令来快速安装

    首先你要确定下你机器上是否有安装了cpan,可以在命令行中直接输入cpan来查看是安装

    1 $ cpan
    2 -bash: cpan: command not found

    若果出现上面提示,说明机器上还没有安装cpan命令

    你可以使用  sudo yum install cpan 进行安装cpan(centos机器安装命令,其他机器使用相应命令下载)

    1 ➜  ~ cpan
    2 Terminal does not support AddHistory.
    3 
    4 cpan shell -- CPAN exploration and modules installation (v2.00)
    5 Enter 'h' for help.
    6 
    7 cpan[1]>

    如果出现以上提示,证明机器上安装了cpan

    这时我们就可以使用 sudo cpan SSH::Batch 进行安装sshbatch了

    若果sshbatch所以来的包都存在,此时都会出现以下提示

     1 Running make install
     2 Installing /usr/local/share/perl5/SSH/Batch.pm
     3 Installing /usr/local/share/perl5/SSH/Batch/ForNodes.pm
     4 Installing /usr/local/share/man/man1/fornodes.1
     5 Installing /usr/local/share/man/man1/key2nodes.1
     6 Installing /usr/local/share/man/man1/tonodes.1
     7 Installing /usr/local/share/man/man1/atnodes.1
     8 Installing /usr/local/share/man/man3/SSH::Batch::ForNodes.3pm
     9 Installing /usr/local/share/man/man3/SSH::Batch.3pm
    10 Installing /usr/local/bin/fornodes
    11 Installing /usr/local/bin/key2nodes
    12 Installing /usr/local/bin/tonodes
    13 Installing /usr/local/bin/atnodes
    14 Appending installation info to /usr/lib64/perl5/perllocal.pod
    15   AGENT/SSH-Batch-0.030.tar.gz
    16   /bin/make install  -- OK

    说明我们已经安装成功了,可以拿我们最常用的atnodes命令来测试下是否正确安装(可能由于某种原因你还需要使用绝对路径/usr/local/bin/atnodes来使用atnodes)

     1 atnodes -h
     2 USAGE:
     3 
     4     atnodes [OPTIONS] COMMAND... -- HOST_PATTERN... [OPTIONS]
     5     atnodes [OPTIONS] COMMAND HOST_PATTERN... [OPTIONS]
     6 
     7 OPTIONS:
     8     -c <num>      Set SSH concurrency limit. (default: 20,
     9                   when -tty is on, this setting will no use)
    10     -h            Print this help.
    11     -l            List the hosts and do nothing else.
    12     -L            Use the line-mode output format, i.e., prefixing
    13                   every output line with the machine name.
    14                   (could be controlled by the env SSH_BATCH_LINE_MODE)
    15     -p <port>     Port for the remote SSH service.
    16     -ssh <path>   Specify an alternate ssh program.
    17                   (This overrides the SSH_BATCH_SSH_CMD environment.)
    18     -t <timeout>  Specify timeout for net traffic.
    19     -u <user>     User account for SSH login.
    20     -v            Be verbose.
    21     -w            Prompt for password (used for both login and sudo,
    22                   could be privided by SSH_BATCH_PASSWORD).
    23     -W            Prompt for password (just for sudo),
    24                   should not be used with -w.
    25     -P            Prompt for passphrase (used for login,
    26                   could be privided by SSH_BATCH_PASSPHRASE).
    27     -tty          Pseudo-tty.
    28     -q            Run SSH in quiet mode

    可见现在我们已经可以正常使用atnodes了

    问题列表

    可是现实往往不是这样的,无论你是用源码安装还是用cpan安装,你都有可能遇到各种各样的问题,不然你也不会看到这篇文章,下面是我安装时遇到的一些问题,记录下来,方便自己以后安装此工具

    问题1

    命令

    sudo cpan SSH::Batch

    问题

     1 Test Summary Report
     2 -------------------
     3 t/atnodes.t        (Wstat: 2560 Tests: 24 Failed: 10)
     4   Failed tests:  2, 5, 8, 11, 13-14, 17, 19-20, 23
     5   Non-zero exit status: 10
     6 t/fornodes.t       (Wstat: 28160 Tests: 126 Failed: 110)
     7   Failed tests:  2, 5, 7-11, 13-24, 26, 28-32, 34-41, 43-68
     8                 70-93, 95, 98, 101, 103-126
     9   Non-zero exit status: 110
    10 t/tonodes.t        (Wstat: 5888 Tests: 45 Failed: 23)
    11   Failed tests:  2, 5, 8, 11, 14, 16-17, 19-20, 23, 25-27
    12                 29, 31-32, 35, 37-38, 40-41, 43-44
    13   Non-zero exit status: 23
    14 Files=6, Tests=195,  1 wallclock secs ( 0.06 usr  0.01 sys +  0.94 cusr  0.29 csys =  1.30 CPU)
    15 Result: FAIL
    16 Failed 3/6 test programs. 143/195 subtests failed.
    17 make: *** [test_dynamic] Error 23
    18   AGENT/SSH-Batch-0.030.tar.gz
    19 2 dependencies missing (File::HomeDir,Net::OpenSSH); additionally test harness failed
    20   /bin/make test -- NOT OK
    21 //hint// to see the cpan-testers results for installing this module, try:
    22   reports AGENT/SSH-Batch-0.030.tar.gz
    23 Running make install
    24   make test had returned bad status, won't install without force

    从第19行可以看出,sshbatch依赖的两个包不存在,安装失败,那我们只能缺什么安装什么了,

    解决方法

    1 sudo cpan File::HomeDir
    2 sudo cpan Net::OpenSSH

    问题2

    安装File::HomeDir时,提示依赖包File::Which不存在,使用cpan安装File::Which

    命令

    sudo cpan File::Which

    问题

     1 t/00_diag.t ..... ok
     2 t/01_compile.t .. ok
     3 t/02_all.t ...... Can't locate Env.pm in @INC (@INC contains: /root/.cpan/build/File-Which-1.22-7sw4CO/blib/lib /root/.cpan/build/File-Which-1.22-7sw4CO/blib/arch /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at t/02_all.t line 3.
     4 BEGIN failed--compilation aborted at t/02_all.t line 3.
     5 t/02_all.t ...... Dubious, test returned 2 (wstat 512, 0x200)
     6 No subtests run
     7 t/03_simple.t ... Can't locate Env.pm in @INC (@INC contains: /root/.cpan/build/File-Which-1.22-7sw4CO/blib/lib /root/.cpan/build/File-Which-1.22-7sw4CO/blib/arch /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at t/03_simple.t line 6.
     8 BEGIN failed--compilation aborted at t/03_simple.t line 6.
     9 # Looks like your test exited with 2 before it could output anything.
    10 t/03_simple.t ... Dubious, test returned 2 (wstat 512, 0x200)
    11 Failed 10/10 subtests
    12 t/04_pwhich.t ... ok
    13 
    14 Test Summary Report
    15 -------------------
    16 t/02_all.t    (Wstat: 512 Tests: 0 Failed: 0)
    17   Non-zero exit status: 2
    18   Parse errors: No plan found in TAP output
    19 t/03_simple.t (Wstat: 512 Tests: 0 Failed: 0)
    20   Non-zero exit status: 2
    21   Parse errors: Bad plan.  You planned 10 tests but ran 0.
    22 Files=5, Tests=5,  1 wallclock secs ( 0.02 usr  0.01 sys +  0.28 cusr  0.03 csys =  0.34 CPU)
    23 Result: FAIL
    24 Failed 2/5 test programs. 0/5 subtests failed.
    25 make: *** [test_dynamic] Error 255
    26   PLICEASE/File-Which-1.22.tar.gz
    27   /bin/make test -- NOT OK
    28 //hint// to see the cpan-testers results for installing this module, try:
    29   reports PLICEASE/File-Which-1.22.tar.gz
    30 Running make install
    31   make test had returned bad status, won't install without force

    解决方法

    从Test Summary Report中可以看到(16~21行),这次是由于安装前的test没有全部成功导致的,其中t/02_all.t和t/03_simple.t两个test失败。

    从第3行和第7行可以看出我们机器上还是少了点什么?虽然少什么我看不明白,但我会google啊,原来获取Env.pm需要使用perl-Env包

    解决办法

    sudo yum install perl-Env -y

    问题总结

    以前没有用过perl也没有使用cpan安装过perl程序,在遇到这个问题时,自己根本没有认真看错误的原因,扫了眼看到了

    Parse errors: No plan found in TAP output

    以为是这就是根本原因,就使用这个关键字在使用google,自然白忙活一阵,也没有找到解决办法。所以以后要认真看下错误提示,找到根本原因。

    问题3

    安装完perl-Env后,我们就可以很顺利的把File::HomeDir以及他的依赖程序安装完成,在安装Net::OpenSSH时,又出现一下问题

    问题

     1 t/1_run.t .... Can't locate Digest/MD5.pm in @INC (@INC contains: ./t /root/.cpan/build/Net-OpenSSH-0.77-rRapXd/blib/lib /root/.cpan/build/Net-OpenSSH-0.77-rRapXd/blib/arch /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /root/.cpan/build/Net-OpenSSH-0.77-rRapXd/blib/lib/Net/OpenSSH.pm line 23.
     2 BEGIN failed--compilation aborted at /root/.cpan/build/Net-OpenSSH-0.77-rRapXd/blib/lib/Net/OpenSSH.pm line 23.
     3 Compilation failed in require at t/1_run.t line 10.
     4 BEGIN failed--compilation aborted at t/1_run.t line 10.
     5 t/1_run.t .... Dubious, test returned 2 (wstat 512, 0x200)
     6 No subtests run
     7 t/quoting.t .. # unable to exec csh -c echo good
     8 # unable to exec tcsh -c echo good
     9 # unable to exec ksh -c echo good
    10 # unable to exec dash -c echo good
    11 # unable to exec ash -c echo good
    12 # unable to exec pdksh -c echo good
    13 # unable to exec mksh -c echo good
    14 # unable to exec zsh -c echo good
    15 # unable to exec fish -c echo good
    16 # running tests for shells sh bash
    17 t/quoting.t .. ok
    18 t/uri.t ...... Can't locate Digest/MD5.pm in @INC (@INC contains: /root/.cpan/build/Net-OpenSSH-0.77-rRapXd/blib/lib /root/.cpan/build/Net-OpenSSH-0.77-rRapXd/blib/arch /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /root/.cpan/build/Net-OpenSSH-0.77-rRapXd/blib/lib/Net/OpenSSH.pm line 23.
    19 BEGIN failed--compilation aborted at /root/.cpan/build/Net-OpenSSH-0.77-rRapXd/blib/lib/Net/OpenSSH.pm line 23.
    20 Compilation failed in require at t/uri.t line 7.
    21 BEGIN failed--compilation aborted at t/uri.t line 7.
    22 t/uri.t ...... Dubious, test returned 2 (wstat 512, 0x200)
    23 No subtests run
    24 
    25 Test Summary Report
    26 -------------------
    27 t/1_run.t  (Wstat: 512 Tests: 0 Failed: 0)
    28   Non-zero exit status: 2
    29   Parse errors: No plan found in TAP output
    30 t/uri.t    (Wstat: 512 Tests: 0 Failed: 0)
    31   Non-zero exit status: 2
    32   Parse errors: No plan found in TAP output
    33 Files=3, Tests=406,  2 wallclock secs ( 0.07 usr  0.01 sys +  0.58 cusr  0.67 csys =  1.33 CPU)
    34 Result: FAIL
    35 Failed 2/3 test programs. 0/406 subtests failed.
    36 make: *** [test_dynamic] Error 2
    37   SALVA/Net-OpenSSH-0.77.tar.gz
    38   /bin/make test -- NOT OK
    39 //hint// to see the cpan-testers results for installing this module, try:
    40   reports SALVA/Net-OpenSSH-0.77.tar.gz
    41 Running make install
    42   make test had returned bad status, won't install without force

    解决办法

    跟问题2类似,我们使用强大的google很快就能找到解决方案

    sudo yum install perl-Digest-MD5 -y

    参考

    https://github.com/agentzh/sshbatch

    http://blog.51cto.com/wanglq/872463

    https://superuser.com/questions/1181310/perl-script-cant-locate-env-pm-in-inc

    https://stackoverflow.com/questions/34248737/cant-locate-digest-md5-pm-directadmin

  • 相关阅读:
    第二章 算法基础 思考题2-4(逆序对)
    JSF中使用f:ajax标签无刷新页面改变数据
    JSF在ui:include中传递参数到对应控制层
    JSF通过超链接传递参数到控制层
    给JavaScript文件传入参数的几种方法
    Spring 与 @Resource注解
    GWT嵌入纯HTML页面
    一个分类,两个问题之ArrayList
    GWT更改元素样式属性
    Hello 2019 D 素因子贡献法计算期望 + 概率dp + 滚动数组
  • 原文地址:https://www.cnblogs.com/halu126/p/8847587.html
Copyright © 2020-2023  润新知