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
使用前提
主机连接远程主机可以通过ssh密钥无密码连接 可参见 SSH无需密码密钥登录1.下载
下载页面:https://code.google.com/archive/p/parallel-ssh/downloadswget 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 pssh3.使用
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 it3.2 介绍软件包内其他命令
pssh 包安装 5 个实用程序:
pssh 在多个主机上并行地运行命令。
pscp 把文件并行地复制到多个主机上。
prsync 通过 rsync 协议把文件高效地并行复制到多个主机上。
pslurp 把文件并行地从多个远程主机复制到中心主机上。
pnuke 并行地在多个远程主机上杀死进程。
相关文章推荐
- U盘安装 CENTOS 7 时发生一些问题
- linux4.3.2 块设备驱动简析-1
- Linux文件属性设置 -- fcntl函数
- linux内核驱动 TI OMAP类处理器的LED所涉及到设备树汇整
- Linux运维面试题及解答(二)
- Linux文件操作 -- lseek实践
- Linux中pushd、popd和dirs
- 第一个Linux驱动程序
- linux开机自启动的几种方法
- emacs快捷键学习(一)--Linux最强大的编辑器
- ./arm-none-linux-gnueabi-gcc: 没有那个文件或目录
- Linux文件复制cp命令的实现
- 如何让linux的history命令显示时间记录
- Sum up - Linux Interview Questions (Updating)
- Linux以KB显示内存大小
- 一次Linux服务器被入侵和删除木马程序的经历
- CFS中的虚拟运行时间
- Linux下mysql备份 恢复
- x86 TSC使用的那些坑
- linux命令