Pssh研究小结

pssh简介

官网:http://www.theether.org/pssh/

提供的功能:

Parallel ssh (pssh):并行ssh
Parallel scp (pscp):并行scp
Parallel rsync (prsync):并行rsync
Parallel nuke (pnuke):并行pnuke
Parallel slurp (pslurp):并行pslurp

 pssh部署安装

2.1 pssh安装

1)系统环境

[root@pssh ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@pssh ~]# uname -a
Linux pssh 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

2)安装部署

[root@pssh ~]# wget http://www.theether.org/pssh/pssh-1.4.3-1.noarch.rpm
[root@pssh ~]# rpm -ivh pssh-1.4.3-1.noarch.rpm
error: Failed dependencies:
        python(abi) = 2.5 is needed by pssh-1.4.3-1.noarch
改为源码安装
[root@pssh ~]# wget http://www.theether.org/pssh/pssh-1.4.3.tar.gz
[root@pssh ~]# tar -zxf pssh-1.4.3.tar.gz
[root@pssh ~]# cd pssh-1.4.3
[root@pssh pssh-1.4.3]# python setup.py install

3)查看参数

[root@pssh ~]# pssh
Usage: pssh [OPTIONS] -h hosts.txt prog [arg0] ..

  -h --hosts   hosts file (each line "host[:port] [user]")
  -l --user    username (OPTIONAL)
  -p --par     max number of parallel threads (OPTIONAL)
  -o --outdir  output directory for stdout files (OPTIONAL)
  -e --errdir  output directory for stderr files (OPTIONAL)
  -t --timeout timeout (secs) (-1 = no timeout) per host (OPTIONAL)
  -O --options SSH options (OPTIONAL)
  -v --verbose turn on warning and diagnostic messages (OPTIONAL)
  -P --print   print output as we get it (OPTIONAL)
  -i --inline  inline aggregated output for each server (OPTIONAL)

Example: pssh -h nodes.txt -l irb2 -o /tmp/foo uptime

[root@pssh ~]# pscp
Usage: pscp [OPTIONS] -h hosts.txt local remote

  -r --recursive recusively copy directories (OPTIONAL)
  -h --hosts     hosts file (each line "host[:port] [login]")
  -l --user      username (OPTIONAL)
  -p --par       max number of parallel threads (OPTIONAL)
  -o --outdir    output directory for stdout files (OPTIONAL)
  -e --errdir    output directory for stderr files (OPTIONAL)
  -t --timeout   timeout (secs) (-1 = no timeout) per host (OPTIONAL)
  -v --verbose   turn on warning and diagnostic messages (OPTIONAL)
  -O --options   SSH options (OPTIONAL)

Example: pscp -h hosts.txt -l irb2 foo.txt /home/irb2/foo.txt

4)设置中心主机到客户端的ssh互信

pssh应用

1)pssh并行运行命令

[root@pssh pssh]# pssh -h host_ip.txt -P hostname        
172.16.1.162: openstack_172.16.1.162
172.16.1.162: [1] 21:53:13 [SUCCESS] 172.16.1.162 63008
172.16.1.122: logstash02
172.16.1.122: [2] 21:53:18 [SUCCESS] 172.16.1.122 63008

2)pscp把文件并行的复制到多个主机上

[root@pssh pssh]# pscp -h host_ip.txt /etc/sysconfig/network /tmp/network
[2] 22:03:17 [SUCCESS] 172.16.1.122 63008

3)prsync使用rsync协议从本地计算机同步到远程主机

[root@server ~]# pssh -h test.txt -P mkdir /tmp/etc
[root@server ~]# prsync -h test.txt -l dongwm -a -r /etc/sysconfig /tmp/etc
//标示将本地的/etc/sysconfig目录递归同步到目标服务器的 /tmp/etc目录下,并保持原来的时间戳,使用用户 dongwm

4)pslurp 将文件从远程主机复制到本地,和pscp方向相反

[root@server ~]# pslurp -h test.txt   -L /tmp/test -l root /tmp/network test 
//标示将目标服务器的/tmp/network文件复制到本地的/tmp/test目录下,并更名为test
[1] 14:53:54 [SUCCESS] 192.168.9.102 9922
[2] 14:53:54 [SUCCESS] 192.168.9.104 9922
[root@server ~]# ll /tmp/test/192.168.9.10
192.168.9.102/ 192.168.9.104/
[root@server ~]# ll /tmp/test/192.168.9.102/
总计 4.0K
-rw-r--r-- 1 root root 60 2011-04-22 14:53 test
[root@server ~]# ll /tmp/test/192.168.9.104/
总计 4.0K
-rw-r--r-- 1 root root 60 2011-04-22 14:53 test

5)pnuke 并行在远程主机杀进程

[root@server ~]# pnuke -h test.txt   syslog           //杀死目标服务器的syslog进程,只要ps进程中出现相关词语 都能杀死
[1] 15:05:14 [SUCCESS] 192.168.9.102 9922
[2] 15:05:14 [SUCCESS] 192.168.9.104 9922

6)pslurp 将文件从远程主机复制到本地,和pscp方向相反

7)常见问题解决

问题1:非常规ssh端口如何处理
[root@pssh pssh]# cat host_ip.txt
172.16.1.162:63008
172.16.1.122:63008

                  

posted @ 2016-07-20 15:09  每天进步一点点!!!  阅读(605)  评论(0编辑  收藏  举报