pssh全称是parallel-ssh,是一个Python编写的可以并发在多台服务器上批量执行命令的工具,
它支持文件并行复制、远程并行执行命令、杀掉远程主机上的进程等。
前提:使用pssh工具包,必须保证本地主机和管理的远程主机之间的单向信任,
也就是要在本地主机和所有远程服务器上配置密钥认证访问。
一、建立本地主机和管理的远程主机之间的单向信任
[fieldyang@master~]$ mkdir ~/.ssh
mkdir:无法创建目录"/home/fieldyang/.ssh":文件已存在
[fieldyang@master~]$ chmod 700 ~/.ssh
[fieldyang@master~]$ cd ~/.ssh
1、使用ssh-keygen命令生成基于SSH协议的RSA秘钥,提示保存位置及密钥时,选择默认,方便使用
[fieldyang@master.ssh]$ ssh-keygen -t rsa
Generatingpublic/private rsa key pair.
Enterfile in which to save the key (/home/fieldyang/.ssh/id_rsa): <-----可以输入存放密钥的地址
Enterpassphrase (empty for no passphrase): <-----输入密语,可以为空
Entersame passphrase again: <-----确认密语,可以为空
Youridentification has been saved in /home/fieldyang/.ssh/id_rsa. <-----生成的密钥
Yourpublic key has been saved in /home/fieldyang/.ssh/id_rsa.pub.<-----生成的公钥
Thekey fingerprint is:
e2:56:ea:0d:62:df:4a:30:e2:b2:1f:5c:d8:ce:33:cefieldyang@master.field.com
Thekey's randomart image is:
+--[RSA 2048]----+
| |
| |
| |
| o |
| o = . S |
|o = + + |
|.+ B * |
|o = O + |
|...E +.o |
+-----------------+
2、将本地节点生成的公钥文件整合为一个authorized_keys文件,并进行授权
[fieldyang@master.ssh]$ cd ~/.ssh
[fieldyang@master.ssh]$ cat /home/fieldyang/.ssh/id_rsa.pub > authorized_keys
[fieldyang@master.ssh]$ chmod 600 ~/.ssh/authorized_keys
3、将authorized_keys文件复制到远程主机上
[fieldyang@master.ssh]$ scp authorized_keys 192.168.56.103:/home/fieldyang/.ssh/
Theauthenticity of host '192.168.56.103 (192.168.56.103)' can't beestablished.
RSAkey fingerprint is 8a:75:1f:1b:16:cd:ac:0c:8a:f5:be:ea:11:42:d1:f6.
Areyou sure you want to continue connecting (yes/no)? yes
Warning:Permanently added '192.168.56.103' (RSA) to the list of known hosts.
fieldyang@192.168.56.103'spassword:
authorized_keys 100% 408 0.4KB/s 00:00
4、测试ssh密钥认证是否成功建立
[fieldyang@master.ssh]$ ssh slave.field.com date
2017年03月28日星期二 17:20:34CST
5、重复以上1~4,在所有的远程主机上执行,即可实现本地主机对所有远程主机的单向通信
二、pssh的安装与用法:
安装完成的pssh工具包附带5个主程序,分别是;
parallelssh(pssh),在远程多台主机上并行运行命令
parallelscp(pscp),把文件并行复制到远程多台主机上,类似scp命令
parallelrsync(prsync),使用rsync协议将文件从本地主机同步到远程多台主机上
parallelnuke(pnuke),在远程多台主机上并行killall某一进程
parallelslurp(pslurp),把文件从远程多台主机复制到本地主机,与pscp命令相反
1、源码安装pssh: