码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-06 10:27:04      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:turn   date   service   .com   director   google   sla   自动   https   

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 "[user@]host[:port]")
   -H HOST_STRING, --host=HOST_STRING
                         additional host entries ("[user@]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 hadoop@db02 -P date
db02: Thu Oct  5 23:56:25 CST 2017
[1] 23:56:25 [SUCCESS] hadoop@db02

$ pssh -H hadoop@db02 -i date
[1] 23:56:30 [SUCCESS] hadoop@db02
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工具安装配置及简单使用讲解

标签:turn   date   service   .com   director   google   sla   自动   https   

原文地址:http://www.cnblogs.com/wcwen1990/p/7630541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!