自动化运维工具-pssh工具安装配置及简单使用讲解

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动化运维工具-pssh工具安装配置及简单使用讲解相关的知识,希望对你有一定的参考价值。

1、先决条件:安装pssh工具要求python版本大于2.4即可。
安装pssh工具的主机针对远程主机需要配置免秘钥认证:
ssh-keygen -t rsa
ssh-copy-id [remotehost]

2、下载pssh工具安装介质:
https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/parallel-ssh/pssh-2.3.1.tar.gz

3、安装pssh:

tar -zxvf pssh-2.3.1.tar.gz
cd pssh-2.3.1
python setup.py install

安装完成后默认生成5个linux命令:

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

4、pssh使用案例讲解:

1)pssh使用案例:

pssh --help可以查看命令帮助文档。

$ pssh --help
Usage: pssh [OPTIONS] command [...]

Options:
   --version             show program‘s version number and exit
   --help                show this help message and exit
   -h HOST_FILE, --hosts=HOST_FILE
                         hosts file (each line "[[email protected]]host[:port]")
   -H HOST_STRING, --host=HOST_STRING
                         additional host entries ("[[email protected]]host[:port]")
   -l USER, --user=USER  username (OPTIONAL)
   -p PAR, --par=PAR     max number of parallel threads (OPTIONAL)
   -o OUTDIR, --outdir=OUTDIR
                         output directory for stdout files (OPTIONAL)
   -e ERRDIR, --errdir=ERRDIR
                         output directory for stderr files (OPTIONAL)
   -t TIMEOUT, --timeout=TIMEOUT
                         timeout (secs) (0 = no timeout) per host (OPTIONAL)
   -O OPTION, --option=OPTION
                         SSH option (OPTIONAL)
   -v, --verbose         turn on warning and diagnostic messages (OPTIONAL)
   -A, --askpass         Ask for a password (OPTIONAL)
   -x ARGS, --extra-args=ARGS
                         Extra command-line arguments, with processing for
                         spaces, quotes, and backslashes
   -X ARG, --extra-arg=ARG
                         Extra command-line argument
   -i, --inline          inline aggregated output and error for each server
   --inline-stdout       inline standard output for each server
   -I, --send-input      read from standard input and send as input to ssh
   -P, --print           print output as we get it
  
  
1)pssh简单案例:

$ pssh -H [email protected] -P date
db02: Thu Oct  5 23:56:25 CST 2017
[1] 23:56:25 [SUCCESS] [email protected]

$ pssh -H [email protected] -i date
[1] 23:56:30 [SUCCESS] [email protected]
Thu Oct  5 23:56:30 CST 2017
  
2)批量查看远程服务器负载:

more remotehosts
  
db01
db02
db03
db04

$ pssh -i -O "StrictHostKeyChecking=no" -h remotehosts "uptime"
[1] 00:29:42 [SUCCESS] db02
  00:29:42 up 1 day, 12:33,  3 users,  load average: 0.03, 0.02, 0.10
[2] 00:29:42 [SUCCESS] db01
  00:29:42 up 1 day, 12:33,  4 users,  load average: 0.02, 0.02, 0.05
[3] 00:29:42 [SUCCESS] db03
  16:27:00 up 1 day, 12:32,  1 user,  load average: 0.00, 0.01, 0.05
[4] 00:29:42 [SUCCESS] db04
  16:27:00 up 1 day, 12:32,  0 users,  load average: 0.01, 0.02, 0.05
 
pssh通过tar命令解压远程主机文件:

pssh -i -h remotehosts "sudo "tar -zxvf /root/pssh-2.3.1.tar.gz -C /root/""
pssh -i -h remotehosts "sudo "ls -l /root/""
pssh -i -h remotehosts "rm -rf pssh-2.3.1"

pssh批量启停远程服务器服务:

pssh -i -h remotehosts "sudo "service ntpd restart""
pssh -i -h remotehosts "sudo "service ntpd status""

2)pscp使用案例:

pscp -h remotehosts /mnt/pssh-2.3.1.tar.gz /tmp/
pscp -h remotehosts -r /mnt/pssh-2.3.1 /tmp/

3)pslurp使用案例:

pslurp -h remotehosts -L /home/hadoop/ /tmp/pssh-2.3.1.tar.gz pssh.tar
pslurp -h remotehosts -r -L /home/hadoop/ /tmp/pssh-2.3.1 pssh
$ll
total 4
drwxrwxr-x 3 hadoop hadoop 34 Oct  5 23:21 db01
drwxrwxr-x 3 hadoop hadoop 34 Oct  5 23:21 db02
drwxrwxr-x 3 hadoop hadoop 34 Oct  5 23:21 db03
drwxrwxr-x 3 hadoop hadoop 34 Oct  5 23:21 db04

4)prsync使用案例:

prsync -h remotehosts -l hadoop -a -r /mnt/software/php-5.6.22 /tmp/
prsync -h remotehosts -l hadoop -az -r /mnt/software/httpd-2.2.31 /tmp/

5)pnuke使用案例:

pnuke -h remotehosts "ntpd"











































































以上是关于自动化运维工具-pssh工具安装配置及简单使用讲解的主要内容,如果未能解决你的问题,请参考以下文章

自动化运维工具-mussh工具安装配置及简单使用讲解

轻量级自动化运维工具pssh与pslurp

轻量级自动化运维工具Pssh

超简单:Centos7部署轻量级自动化运维工具pssh

tree老师:PSSH自动化运维实战

Centos7部署轻量级自动化运维工具pssh