关于linux:Linux-下自动化工具-Parallel-SSH-中文使用指南

9次阅读

共计 2157 个字符,预计需要花费 6 分钟才能阅读完成。

parallel-ssh 是为小规模自动化而设计的异步并行的 SSH 库!

parallel-ssh 是为小规模自动化而设计的异步并行的 SSH 库,包含 pssh、pscp、prsync、pslurp 和 pnuke 工具,其源代码应用 Python 语言编写开发的。该我的项目最后位于 Google Code 上,是由 Brent N.Chun 编写和保护的,然而因为工作忙碌,Brent 于 2009 年 10 月将保护工作移交给了 Andrew McNabb 治理。到了 2012 年的时候,因为 Google Code 的已敞开,该我的项目一度被废除,当初也只能在 Google Code 的归档中找到过后的版本了。

然而须要留神的是,之前的版本是不反对 Python3 的,然而 Github 下面有人 Fork 了一份,本人进行了革新使其反对 Python3 以上的版本了。与此同时,还有一个组织专门针对 parallel-ssh 进行了开发和保护,明天看了下很久都没有更新了。有须要的,本人能够自行查阅。

https://github.com/lilydjwg/pssh

https://github.com/ParallelSS…

  • 可扩展性

    • 反对扩大到百台,甚至上千台主机应用
  • 易于应用

    • 只需两行代码,即可在任意数量的主机上运行命令
  • 执行高效

    • 号称是最快的 Python SSH 库可用
  • 资源应用

    • 相比于其余 Python SSH 库,其耗费资源起码

装置

# Mac 零碎装置
$ brew install pssh

# CentOS 零碎装置
$ yum install pssh

# Ubuntu 零碎装置
$ apt install pssh

# PIP 装置
$ pip insall pssh

源代码编译装置 (2.3.1)

# 官网地址: https://code.google.com/archive/p/parallel-ssh/source/default/source
$ tar zxvf pssh-2.3.1.tar.gz
$ cd pssh-2.3.1
$ python setup.py install

# 工具对应的子命令子命令
$ ls -lh /usr/local/Cellar/pssh/2.3.1_1/bin/
pnuke -> ../libexec/bin/pnuke
prsync -> ../libexec/bin/prsync
pscp -> ../libexec/bin/pscp
pslurp -> ../libexec/bin/pslurp
pssh -> ../libexec/bin/pssh
pssh-askpass -> ../libexec/bin/pssh-askpass

pssh

通过 ssh 协定在多台主机上并行地运行命令

命令参数应用

实用范例

# Usage: pssh [OPTIONS] command [...]

# 在两个主机上运行命令并在每个服务器上打印其输入
$ pssh -i -H "host1 host2" hostname -i

# 运行命令并将输入保留到独自的文件中
$ pssh -H host1 -H host2 -o path/to/output_dir hostname -i

# 在多个主机上运行命令并在新行分隔的文件中指定
$ pssh -i -h path/to/hosts_file hostname -i

# 以 root 运行命令 (要求输出 root 用户明码)
$ pssh -i -h path/to/hosts_file -A -l root_username hostname -i

# 运行带有额定 SSH 参数的命令
$ pssh -i -h path/to/hosts_file -x "-O VisualHostKey=yes" hostname -i

# 运行并行连贯数量限度为 10 的命令
$ pssh -i -h path/to/hosts_file -p 10 'cd dir; ./script.sh; exit'

pscp

通过 ssh 协定把文件并行地复制到多台主机上

命令参数应用

# Usage: pscp [OPTIONS] local remote

# 将本地文件复制到近程机器上
$ pscp -h hosts.txt -l root foo.txt /home/irb2/foo.txt
[1] 23:00:08 [SUCCESS] 172.18.10.25
[2] 09:52:28 [SUCCESS] 172.18.10.24

3. prsync

通过 rsync 协定把文件高效地并行复制到多台主机上

命令参数应用

实用范例

# Usage: prsync [OPTIONS] local remote

# 应用 rsync 协定进行本地文件复制操作
$ prsync -r -h hosts.txt -l root foo /home/irb2/foo

4. pslurp

通过 ssh 协定把文件并行地从多个近程主机复制到核心主机上

命令参数应用

实用范例

# Usage: pslurp [OPTIONS] remote local

# 将近程主机下面的文件复制到本地
$ pslurp -h hosts.txt -l root -L /tmp/outdir /home/irb2/foo.txt foo.txt

5. pnuke

通过 ssh 协定并行地在多个近程主机上杀死过程

命令参数应用

实用范例

# Usage: pnuke [OPTIONS] pattern

# 完结近程主机下面的过程工作
$ pnuke -h hosts.txt -l root java

作者: Escape
链接: https://www.escapelife.site/p…

正文完
 0