pssh远程套件工具

实验的目的

  • 使用密码批量、多并发远程其他主机
  • 使用密钥批量、多并发远程其他主机
  • 批量、多并发拷贝数据到其他主机
  • 批量、多并发从其他主机下载数据到本机
  • 批量、多并发杀死其他主机的进程

准备工作

主机名称 IP地址
client eth0(192.168.1.1/24)
proxy eth0(192.168.1.2/24) eth1(192.168.2.1/24)
web1 eth1(192.168.2.2/24)
web2 eth1(192.168.2.3/24)

安装软件包

rpm -ivh  pssh-2.3.1-5.el7.noarch.rpm

安装后的命令

/usr/bin/pnuke
/usr/bin/prsync
/usr/bin/pscp.pssh
/usr/bin/pslurp
/usr/bin/pssh

修改/etc/hosts本地文件

192.168.1.1 host1
192.168.2.2 host3
192.168.2.3 hots4

创建主机列表文件

vim ./hosts.txt
root@host1
root@host3
root@host4

使用密码批量并多并发远程其他主机

pssh提供并发远程连接功能

参数指令 参数作用
-A 使用密码远程其他主机(默认使用密钥)
-i 将输出显示在屏幕
-H 设置需要连接的主机
-h 设置主机列表文件
-p 设置并发数量
-t 设置超时时间
-o dir 设置标准输出信息保存的目录
-e dir 设置错误输出信息保存的目录
-x 传递参数给ssh

使用密码远程多台主机执行命令(屏幕显示标准和错误输出信息)

pssh -i  -A -H  'host1 host2 host3'  -x '-o StrictHostKeyChecking=no'   echo hello seccess

使用密码远程多台主机执行命令(不显示标准和错误输出信息,通过读取host.txt读取主机信息

pssh -A -h host.txt  -x '-o StrictHostKeyChecking=no' echo hello

使用密钥批量、多并发远程其他主机

[root@proxy ~]# ssh-keygen -N  ''   -f /root/.ssh/id_rsa        #非交互生成密钥文件
[root@proxy ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub host1
[root@proxy ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub host3
[root@proxy ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub host4

使用密钥远程其他主机

[root@proxy ~]# pssh  -h host.txt -x '-o StrictHostKeyChecking=no' echo hello

使用密钥远程其他主机,将标准输出信息写入到/tmp目录

[root@proxy ~]# pssh  -h host.txt -o /tmp/ -x '-o StrictHostKeyChecking=no' echo hello

批量、多并发拷贝数据到其他主机

 man pscp.pssh  #通过man帮助查看工具选项的作用
    pscp.pssh        #提供并发拷贝文件功能
    -r                    #递归拷贝目录
    其他选项基本与pssh一致

将本地的etc.tar.gz拷贝到远程主机的根目录下

pscp.pssh -h host.txt -x '-o StrictHostKeyChecking=no' etc.tar.gz

递归将本地的/etc目录拷贝到远程主机的/tmp目录下

pscp.pssh -r -h host.txt -x '-o StrictHostKeyChecking=no'  /etc   /tmp

批量、多并发从其他主机下载数据到本机

 pslurp -r -h host.txt -x '-o StrictHostKeyChecking=no' /etc /tmp

批量、多并发杀死其他主机的进程

1.将远程主机上的sleep进程杀死

pnuke  -h host.txt -x '-o StrictHostKeyChecking=no' sleep
  1. 将远程主机上的test相关脚本都杀死
    pnuke  -h host.txt -x '-o StrictHostKeyChecking=no' test
    

3.将远程主机上的test.sh脚本杀死

pnuke  -h host.txt -x '-o StrictHostKeyChecking=no' test.sh

pssh远程套件工具》有3个想法

  1. Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a bit, but instead of that, this is magnificent blog. A great read. I’ll certainly be back.

  2. Wonderful goods from you, man. I’ve understand your stuff previous to and you’re just extremely excellent. I really like what you’ve acquired here, really like what you’re saying and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I can not wait to read much more from you. This is actually a terrific web site.

发表评论