sshbatch:SSH协议

  • P4_855258
    了解作者
  • 104.3KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-05 10:07
    上传日期
名称 SSH :: Batch-基于并行SSH,设置和间隔算法的集群操作 目录 版本 本文档介绍了2015年11月8日发布的SSH :: Batch 0.030。 概要 提供了以下脚本: 前节点 将模式扩展到计算机主机列表。 $ cat > ~/.fornodesrc ps=blah.ps.com bloo.ps.com boo[2-25,32,41-70].ps.com as=ws[1101-1105].as.com # use set operations to define new sets: foo={ps} + {ps} * {as} - {ps} / {as} bar = foo.com bar.org \ bah.cn \ baz.com ^D $ fornodes 'api[02-10].foo.bar.com'
sshbatch-master.zip
内容介绍
# NAME SSH::Batch - Cluster operations based on parallel SSH, set and interval arithmetic Table of Contents ================= * [NAME](#name) * [VERSION](#version) * [SYNOPSIS](#synopsis) * [DESCRIPTION](#description) * [TIPS](#tips) * [PREREQUISITES](#prerequisites) * [INSTALLATION](#installation) * [CODE REPOSITORY](#code-repository) * [TODO](#todo) * [AUTHORS](#authors) * [COPYRIGHT & LICENSE](#copyright--license) * [SEE ALSO](#see-also) # VERSION This document describes SSH::Batch 0.030 released on 8 November 2015. # SYNOPSIS The following scripts are provided: - fornodes Expand patterns to machine host list. $ cat > ~/.fornodesrc ps=blah.ps.com bloo.ps.com boo[2-25,32,41-70].ps.com as=ws[1101-1105].as.com # use set operations to define new sets: foo={ps} + {ps} * {as} - {ps} / {as} bar = foo.com bar.org \ bah.cn \ baz.com ^D $ fornodes 'api[02-10].foo.bar.com' 'boo*.ps.com' $ fornodes 'tq[ab-ac].[1101-1105].foo.com' $ fornodes '{ps} + {as} - ws1104.as.com' # set union and subtraction $ fornodes '{ps} * {as}' # set intersect - atnodes Run command on clusters. (atnodes calls fornodes internally.) # run a command on the specified servers: $ atnodes $'ps -fe|grep httpd' 'ws[1101-1105].as.com' # multiple-arg command requires "--": $ atnodes ls /opt/ -- '{ps} + {as}' 'localhost' # or use single arg command: $ atnodes 'ls /opt/' '{ps} + {as}' 'localhost' # ditto # specify a different user name and SSH server port: $ atnodes hostname '{ps}' -u agentz -p 12345 # use -w to prompt for password if w/o SSH key (no echo back) $ atnodes hostname '{ps}' -u agentz -w # or prompt for password if both login and sudo are required... $ atnodes 'sudo apachectl restart' '{ps}' -w # or prompt for password for sudo only... $ atnodes 'sudo apachectl restart' '{ps}' -W # run sudo command if tty required... $ atnodes -tty 'sudo apachectl restart' '{ps}' # or specify a timeout: $ atnodes 'ping foo.com' '{ps}' -t 3 - tonodes Upload local files/directories to remote clusters $ tonodes /tmp/*.inst -- '{as}:/tmp/' $ tonodes foo.txt 'ws1105*' :/tmp/bar.txt # use rsync instead of scp: $ tonodes foo.txt 'ws1105*' :/tmp/bar.txt -rsync $ tonodes -r /opt /bin/* -- 'ws[1101-1102].foo.com' 'bar.com' :/foo/bar/ - key2nodes Push the SSH public key (or generate one if not any) to the remote clusters. $ key2nodes 'ws[1101-1105].as.com' # DESCRIPTION System administration (sysadmin) is also part of my `$work`. Playing with a (big) bunch of machines without a handy tool is painful. So I refactored some of our old scripts and hence this module. This is a high-level abstraction over the powerful [Net::OpenSSH](https://metacpan.org/pod/Net::OpenSSH) module. A bunch of handy scripts are provided to simplify big cluster operations: [fornodes](https://metacpan.org/pod/fornodes), [atnodes](https://metacpan.org/pod/atnodes), [tonodes](https://metacpan.org/pod/tonodes), and [key2nodes](https://metacpan.org/pod/key2nodes). `SSH::Batch` allows you to name your clusters using variables and interval/set syntax in your `~/.fornodesrc` config file (or a different file name specified by the `SSH_BATCH_RC` environment). For instance: $ cat ~/.fornodesrc A=foo[01-03].com bar.org B=bar.org baz[a-b,d,e-g].cn foo02.com C={A} * {B} D={A} - {B} where cluster `C` is the intersection set of cluster `A` and `B` while `D` is the sef of machines that are in `A` but not in `B`. And then you can query machine host list by using `SSH::Batch`'s [fornodes](https://metacpan.org/pod/fornodes) script: $ fornodes '{C}' bar.org foo02.com $ fornodes '{D}' foo01.com foo03.com $ fornodes blah.com '{C} + {D}' bar.org blah.com foo01.com foo02.com foo03.com It's always best practice to **put spaces around set operators** like `+`, `-`, `*`, and `/`, so as to allow these characters (notably the dash `-`) in your host names, as in: $ fornodes 'foo-bar-[a-d].com - foo-bar-c.com' foo-bar-a.com foo-bar-b.com foo-bar-d.com for the ranges like `[a-z]`, there's also an alternative syntax: [a..z] To exclude some discrete values from certain range, you need set subtration: foo[1-100].com - foo[32,56].com or equivalently foo[1-31,33-55,57-100].com [fornodes](https://metacpan.org/pod/fornodes) could be very handy in shell programming. For example, to test the 80 port HTTP service of a cluster `A`, simply put $ for node in `fornodes '{A}'`; \ do curl "http://$node:80/blah'; \ done Also, other scripts in this module, like [atnodes](https://metacpan.org/pod/atnodes), [tonodes](https://metacpan.org/pod/tonodes), and [key2nodes](https://metacpan.org/pod/key2nodes) also call fornodes internally so that you can use the cluster spec syntax in those scripts' command line as well. [atnodes](https://metacpan.org/pod/atnodes) meets the common requirement of running a command on a remote cluster. For example: # at the concurrency level of 6: atnodes 'ls -lh' '{A} + {B}' my.more.com -c 6 Or upload a local file to the remote cluster: tonodes ~/my.tar.gz '{A} / {B}' :/tmp/ or multiple files as well as some directories: tonodes -r ~/mydir ~/mydir2/*.so -- foo.com bar.cn :~/ It's also possible to use wildcards in the cluster spec expression, as in atnodes 'ls ~' 'api??.*.com' where [atnodes](https://metacpan.org/pod/atnodes) will match the pattern `api??.*.com` against the "universal set" consisting of those hosts appeared in `~/fornodesrc` and those host names apeared before this pattern on the command line (if any). Note that only `?` (match any character) and `*` (match 0 or more characters) are supported here. There's also a [key2nodes](https://metacpan.org/pod/key2nodes) script to push SSH public keys to remote machines ;) [Back to TOC](#table-of-contents) # TIPS There's some extra tips found in our own's everyday use: - Running sudo commands Often, we want to run commands requiring root access, such as when installing software packages on remote machines. So you'll have to tell [atnodes](https://metacpan.org/pod/atnodes) to prompt for your password: $ atnodes 'sudo yum install blah' '{my_cluster}' -w Then you'll be prompted by the `Password:` prompt after which you enter your remote password (with echo back turned off). Because the remote `sshd` might be smart enough to "remember" the sudo password for a (small) amount of time, immediate subsequent "sudo" might omit the `-w` option, as in $ atnodes 'sudo mv ~/foo /usr/local/bin/' {my_cluster} But remember, you can use _sudo without passwords_ just for a _small_ amount of time ;) If you see the following error message while doing sudo with [atnodes](https://metacpan.org/pod/atnodes) sudo: sorry, you must have a tty to run sudo then you should add option -tty, or you can probably comment out the "Defaults requiretty" line in your server's `/etc/sudoers` file (best just to do this for your own account). - Passing custom options to the underlying `ssh` By default, `atnodes` relies on [Net::OpenSSH](https://metacpan.org/pod/Net::OpenSSH) to locate the OpenSSH client executable "ssh". But you can define the `SSH_BATCH_SSH_CMD` environment to specify the command explicitly. You can use the `-ssh` option to override it further. (The [key2nodes](https://metacpan.org/pod/key2nodes) script also supports the `SSH_BATCH_SSH_CMD` environment.) Note that to specify your own "ssh" is also a way to pass more options to the underlying OpenSSH client executable when using `atnodes`: $ cat > ~/bin/myssh #!/bin/sh # to enable X11 forwa
评论
    相关推荐