您的位置:首页 > 运维架构 > Linux

Linux批量远程执行命令管理pssh

2016-02-06 16:27 741 查看
pssh是一个简单的字符界面并发向多个服务器发送指令进行执行的工具。适合一次性向集群大量服务器发送相同指令(并观察输出)

使用前提

主机连接远程主机可以通过ssh密钥无密码连接 可参见 SSH无需密码密钥登录

1.下载

下载页面:https://code.google.com/archive/p/parallel-ssh/downloads

wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/parallel-ssh/pssh-2.3.1.tar.gz

wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/parallel-ssh/pssh-2.3.1.tar.gz[/code] 

2.安装

tar -zxvf pssh-2.3.1.tar.gz
cd pssh-2.3.1
python setup.py build
python setup.py install

如果是 redhat (或者CentOS)也可以用yum安装

yum install -y pssh


3.使用

3.1 介绍pssh参数

-l 远程机器的用户名

-o 输出内容重定向到一个文件

-t 设置命令执行的超时时间

-O 设置ssh参数的具体配置,参照ssh_config配置文件

-X 同-x 但是一次只能传递一个命令

-I 读取每个输入命令,并传递给ssh进程 允许命令脚本传送到标准输入

完整说明见命令:pssh --help
Usage: pssh [OPTIONS] command [...]

Options:
--version show program's version number and exit
--help show this help message and exit
-h HOST_FILE, --hosts=HOST_FILE
hosts file (each line "[user@]host[:port]")
-H HOST_STRING, --host=HOST_STRING
additional host entries ("[user@]host[:port]")
-l USER, --user=USER username (OPTIONAL)
-p PAR, --par=PAR max number of parallel threads (OPTIONAL)
-o OUTDIR, --outdir=OUTDIR
output directory for stdout files (OPTIONAL)
-e ERRDIR, --errdir=ERRDIR
output directory for stderr files (OPTIONAL)
-t TIMEOUT, --timeout=TIMEOUT
timeout (secs) (0 = no timeout) per host (OPTIONAL)
-O OPTION, --option=OPTION
SSH option (OPTIONAL)
-v, --verbose turn on warning and diagnostic messages (OPTIONAL)
-A, --askpass Ask for a password (OPTIONAL)
-x ARGS, --extra-args=ARGS
Extra command-line arguments, with processing for
spaces, quotes, and backslashes
-X ARG, --extra-arg=ARG
Extra command-line argument
-i, --inline inline aggregated output and error for each server
--inline-stdout inline standard output for each server
-I, --send-input read from standard input and send as input to ssh
-P, --print print output as we get it

3.2 介绍软件包内其他命令

pssh 包安装 5 个实用程序:
pssh 在多个主机上并行地运行命令。
pscp 把文件并行地复制到多个主机上。
prsync 通过 rsync 协议把文件高效地并行复制到多个主机上。
pslurp 把文件并行地从多个远程主机复制到中心主机上。
pnuke 并行地在多个远程主机上杀死进程。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息