轻量级运维工具-pssh,pscp,prsync,pslurp,pnuke

批量执行,并行传输,远程killall

#yum安装
yum install pssh -y
#yun安装后pscp改名为pscp.pssh

#源码编译
wget https://pypi.python.org/packages/60/9a/8035af3a7d3d1617ae2c7c174efa4f154e5bf9c24b36b623413b38be8e4a/pssh-2.3.1.tar.gz
tar xf pssh-2.3.1.tar.gz
cd pssh-2.3.1/
python setup.py install
#注:在使用工具前,确保主机间做了密钥认证,否则无法实现自动化,当然我们可以使用sshpass配合pssh -A参数实现自动输入密码,
#但这要保证多台主机的密码相同,同时还要注意如果known_hosts没有信任远程主机,那么命令执行会失败,
#可以加上-O StrictHostKeyChecking=no参数解决,ssh能用的选项pssh也能用

#pssh 远程批量执行命令  
pssh -h ip.txt -P "uptime"  
#-h  后面接主机ip文件,文件数据格式[user@]host[:port]
#-P  显示输出内容 
#如果没办法密钥认证.可以采用下面方法,但不是很安全
sshpass -p 123456 pssh -A -h ip.txt -i "uptime" 

#pscp 并行传输文件到远端
#传文件,不支持远程新建目录
pscp -h ip.txt test.py /tmp/dir1/
#传目录
pscp -r -h ip.txt test/ /tmp/dir1/

#prsync 并行传输文件到远端
#传文件,支持远程新建目录,即目录不存在则新建
prsync -h ip.txt test.py /tmp/dir2/
#传目录
prsync -r -h ip.txt test/ /tmp/dir3/

#pslurp从远程拉取文件到本地,在本地自动创建目录名为远程主机ip的目录,将拉取的文件放在对应主机IP目录下
#格式:pslurp -h ip.txt -L <本地目录>  <远程目录/文件>  <本地重命名>
#拉取文件
pslurp -h ip.txt -L /root/ /root/1.jpg picture
ll /root/172.16.1.13/picture 
-rw-r--r-- 1 root root 148931 Jan  9 15:41 /root/172.16.1.13/picture
#拉取目录
pslurp -r -h ip.txt -L /root/ /root/test temp
ll -d /root/172.16.1.13/temp/
drwxr-xr-x 2 root root 23 Jan  9 15:49 /root/172.16.1.13/temp/

#pnuke:远程批量killall
pnuke -h ip.txt nginx
posted @ 2018-01-09 16:04  Peterer~王勇  阅读(3039)  评论(0编辑  收藏  举报