自动化运维之 PSSH
Posted 51reboot运维开发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动化运维之 PSSH相关的知识,希望对你有一定的参考价值。
PSSH 提供 OpenSSH 和相关工具的并行版本。包括 pssh,pscp,prsync,pnuke 和 pslurp。该项目包括 psshlib,可以在自定义应用程序中使用。
前提条件:注意需要安装 python 2.4 或以上版本
wget https://clsn.io/files/pssh/pssh-2.3.1.tar.gz
tar zxf pssh-2.3.1.tar.gz
cd pssh-2.3.1
python setup.py install
安装过程
[root@clsn.io /opt/pssh-2.3.1]
#python setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/psshlib
copying psshlib/task.py -> build/lib/psshlib
copying psshlib/askpass_server.py -> build/lib/psshlib
copying psshlib/__init__.py -> build/lib/psshlib
copying psshlib/cli.py -> build/lib/psshlib
copying psshlib/psshutil.py -> build/lib/psshlib
copying psshlib/manager.py -> build/lib/psshlib
copying psshlib/askpass_client.py -> build/lib/psshlib
copying psshlib/version.py -> build/lib/psshlib
copying psshlib/color.py -> build/lib/psshlib
running build_scripts
creating build/scripts-2.6
copying and adjusting bin/pssh -> build/scripts-2.6
copying and adjusting bin/pnuke -> build/scripts-2.6
copying and adjusting bin/prsync -> build/scripts-2.6
copying and adjusting bin/pslurp -> build/scripts-2.6
copying and adjusting bin/pscp -> build/scripts-2.6
copying and adjusting bin/pssh-askpass -> build/scripts-2.6
changing mode of build/scripts-2.6/pssh from 644 to 755
changing mode of build/scripts-2.6/pnuke from 644 to 755
changing mode of build/scripts-2.6/prsync from 644 to 755
changing mode of build/scripts-2.6/pslurp from 644 to 755
changing mode of build/scripts-2.6/pscp from 644 to 755
changing mode of build/scripts-2.6/pssh-askpass from 644 to 755
running install_lib
creating /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/task.py -> /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/askpass_server.py -> /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/__init__.py -> /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/cli.py -> /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/psshutil.py -> /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/manager.py -> /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/askpass_client.py -> /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/version.py -> /usr/lib/python2.6/site-packages/psshlib
copying build/lib/psshlib/color.py -> /usr/lib/python2.6/site-packages/psshlib
byte-compiling /usr/lib/python2.6/site-packages/psshlib/task.py to task.pyc
byte-compiling /usr/lib/python2.6/site-packages/psshlib/askpass_server.py to askpass_server.pyc
byte-compiling /usr/lib/python2.6/site-packages/psshlib/__init__.py to __init__.pyc
byte-compiling /usr/lib/python2.6/site-packages/psshlib/cli.py to cli.pyc
byte-compiling /usr/lib/python2.6/site-packages/psshlib/psshutil.py to psshutil.pyc
byte-compiling /usr/lib/python2.6/site-packages/psshlib/manager.py to manager.pyc
byte-compiling /usr/lib/python2.6/site-packages/psshlib/askpass_client.py to askpass_client.pyc
byte-compiling /usr/lib/python2.6/site-packages/psshlib/version.py to version.pyc
byte-compiling /usr/lib/python2.6/site-packages/psshlib/color.py to color.pyc
running install_scripts
copying build/scripts-2.6/pscp -> /usr/bin
copying build/scripts-2.6/prsync -> /usr/bin
copying build/scripts-2.6/pnuke -> /usr/bin
copying build/scripts-2.6/pssh -> /usr/bin
copying build/scripts-2.6/pssh-askpass -> /usr/bin
copying build/scripts-2.6/pslurp -> /usr/bin
changing mode of /usr/bin/pscp to 755
changing mode of /usr/bin/prsync to 755
changing mode of /usr/bin/pnuke to 755
changing mode of /usr/bin/pssh to 755
changing mode of /usr/bin/pssh-askpass to 755
changing mode of /usr/bin/pslurp to 755
running install_data
creating /usr/man
creating /usr/man/man1
copying man/man1/pssh.1 -> /usr/man/man1
copying man/man1/pscp.1 -> /usr/man/man1
copying man/man1/prsync.1 -> /usr/man/man1
copying man/man1/pslurp.1 -> /usr/man/man1
copying man/man1/pnuke.1 -> /usr/man/man1
running install_egg_info
Writing /usr/lib/python2.6/site-packages/pssh-2.3.1-py2.6.egg-info
使用 yum 安装后,只能使用 pssh,但是编译安装后会包括其他命令也安装了(pscp prsync pnuke pslurp)
pssh:在远程多台主机上并行运行命令
Example: pssh -h hosts.txt -l irb2 -o /tmp/foo uptime
pscp :把文件并行复制到多台远程主机上
Example: pscp -h hosts.txt -l irb2 foo.txt /home/irb2/foo.txt
prsync:使用 rsync 协议本地文件同步到远程多台主机上。
Example: prsync -r -h hosts.txt -l irb2 foo /home/irb2/foo
pnuke:在远程多台主机上并行 killall 某一进程
Example: pnuke -h hosts.txt -l irb2 java
pslurp:把文件从远程多台主机上复制到本地主机上
Example: pslurp -h hosts.txt -L /tmp/outdir -l irb2
/home/irb2/foo.txt foo.txt
-h HOST_FILE 后边跟远程主机列表(ip)
-l USER 指定远程主机的用户名-p PAR 指定 pssh 最大的并行线程数。
-o 将输出的内容重定向到一个指定的文件中
-O 指定 ssh参数的具体配置
-e 将执行错误重定向到一个指定的文件中
-t 设定命令执行超时时间
-x 传递 ssh命令的一些参数
-i 在远程主机上执行命令完成后显示标准输出和标准错误
-P 在执行远程命令时,输出执行结果
pssh 使用帮助
pssh --help
pssh 查看所有服务器的 uptime
-h list 指定了执行命令的机器列表
-A表示提示输入密码(如果机器都是ssh key打通的则无需加-A)
pssh -i -A -h list 'uptime'
使用 pscp 向一堆机器分发文件
pscp -h list localfile remote_dir
从一堆机器中拷贝文件到中心机器
pslurp -h list /etc/hosts local_dir
如果你遇到这样的错误:
IOError: [Errno 4] Interrupted system call
建议升级python版本到python2.7
本站将 pssh 软件包镜像到本地,以防丢失,有需求的可以执行下载,下载后注意校验 MD5 值。
下载完成后务必校验 MD5 值
https://code.google.com/archive/p/parallel-ssh/
http://opstool.com/article/266
https://www.cnblogs.com/Dicky-Zhang/p/5988415.html
https://help.aliyun.com/knowledge_detail/38835.html
Golang 课程
K8S 课程
Python 自动化进阶课程
Python 基础实战课程
运维前端课程
课程试听预约请扫码>>>
以上是关于自动化运维之 PSSH的主要内容,如果未能解决你的问题,请参考以下文章