CentOS 8
Sponsored Link

OpenSSH : Parallel SSH を利用する2020/03/13

 
MPSSH (Mass Parallel Secure Shell) を使用して、SSH サーバーが稼働する複数ホストに対して並列で SSH 接続します。
[1] MPSSH をインストールします。
# EPELからインストール

[root@dlp ~]#
dnf --enablerepo=epel -y install mpssh
[2] MPSSH の使い方です。
各対象サーバーに対して、パスフレーズ無し鍵ペアで認証可能であることを前提とします。
パスフレーズ付き鍵ペア認証の場合は 事前に SSH-Agent を起動してパスフレーズをセットしておけば、以下と同様の操作で利用可能です。
# 接続対象のホストを一行ずつ記載する

[cent@dlp ~]$
vi ssh_targets
node01.srv.world
node02.srv.world
# 設定したホストに対して [uname] コマンドを実行

[cent@dlp ~]$
mpssh -f ssh_targets "uname -a"

MPSSH - Mass Parallel Ssh Ver.1.3.3

  [*] read (2) hosts from the list
  [*] executing "uname -a" as user "cent"
  [*] spawning 2 parallel ssh sessions

node01.srv.world -> Linux node01.srv.world 4.18.0-147.5.1.el8_1.x86_64 #1 SMP Wed Feb 5 02:00:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
node02.srv.world -> Linux node02.srv.world 4.18.0-147.5.1.el8_1.x86_64 #1 SMP Wed Feb 5 02:00:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

  Done. 2 hosts processed.

# ホスト毎に結果をファイルに書き出す

[cent@dlp ~]$
mpssh -b -o ./output -f ssh_targets "cat /etc/passwd"

MPSSH - Mass Parallel Ssh Ver.1.3.3

  [*] read (2) hosts from the list
  [*] executing "cat /etc/passwd" as user "cent"
  [*] blind mode enabled
  [*] using output directory : ./output
  [*] spawning 2 parallel ssh sessions

  Done. 2 hosts processed.

[cent@dlp ~]$
ll ./output

total 8
-rw-r--r--. 1 cent cent 1236 Mar 13 15:04 cent@node01.srv.world.out
-rw-r--r--. 1 cent cent 1183 Mar 13 15:04 cent@node02.srv.world.out

[cent@dlp ~]$
cat ./output/cent@node01.srv.world.out

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
.....
.....
関連コンテンツ