运维自动化轻量级工具pssh
1pssh介紹
pssh是python寫的可以并發在多臺機器上批量執行命令的工具,它的用法可以媲美ansible的一些簡單用法,執行起來速度比ansible快它支持文件并行復制,遠程命令執行,殺掉遠程主機上的進程等等。殺手锏是文件并行復制,,當進行再遠程主機批量上傳下載的時候,最好使用它。
2pssh的使用
在使用pssh之前,必須要保證管理主機和本地主機進行過密鑰的認證,或者是在進行批量時,沒有做過密鑰認證,但是必須保證被管理的多臺主機的密碼相同。關于如何做密鑰認證,這里就不多說了,可以自行百度。
2.1安裝
官網地址:https://code.google.com/archive/p/parallel-ssh/downloads(需要能打開谷歌)
或者是yum 來安裝
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/parallel-ssh/pssh-2.3.1.tar.gz tar -zxvf pssh-2.3.1.tar.gz cd pssh-2.3.1 python setup.py install 或者 yum install -y pssh使用yum安裝后,只能使用pssh,但是編譯安裝后會包括其他命令也安裝了(pscp ?prsync ?pnuke ?pslurp)
pssh:在遠程多臺主機上并行運行命令
pscp :把文件并行復制到多臺遠程主機上
prsync:使用rsync協議本地文件同步到遠程多臺主機上。
pnuke:在遠程多臺主機上并行killall某一進程
pslurp:把文件從遠程多臺主機上復制到本地主機上
2.2 pssh常用參數
1 pssh --help 2 3 Usage: pssh [OPTIONS] command [...] 4 5 Options: 6 --version show program's version number and exit 7 --help show this help message and exit 8 -h HOST_FILE, --hosts=HOST_FILE 9 hosts file (each line "[user@]host[:port]") 10 -H HOST_STRING, --host=HOST_STRING 11 additional host entries ("[user@]host[:port]") 12 -l USER, --user=USER username (OPTIONAL) 13 -p PAR, --par=PAR max number of parallel threads (OPTIONAL) 14 -o OUTDIR, --outdir=OUTDIR 15 output directory for stdout files (OPTIONAL) 16 -e ERRDIR, --errdir=ERRDIR 17 output directory for stderr files (OPTIONAL) 18 -t TIMEOUT, --timeout=TIMEOUT 19 timeout (secs) (0 = no timeout) per host (OPTIONAL) 20 -O OPTION, --option=OPTION 21 SSH option (OPTIONAL) 22 -v, --verbose turn on warning and diagnostic messages (OPTIONAL) 23 -A, --askpass Ask for a password (OPTIONAL) 24 -x ARGS, --extra-args=ARGS 25 Extra command-line arguments, with processing for 26 spaces, quotes, and backslashes 27 -X ARG, --extra-arg=ARG 28 Extra command-line argument 29 -i, --inline inline aggregated output and error for each server 30 --inline-stdout inline standard output for each server 31 -I, --send-input read from standard input and send as input to ssh 32 -P, --print print output as we get it 33 34 Example: pssh -h hosts.txt -l irb2 -o /tmp/foo uptime View Code具體常用介紹:
-h ? HOST_FILE ? 后邊跟遠程主機列表(ip)
-H ? HOST_STRING ? 后邊跟遠程主機名或者ip地址
-l ? USER ?指定遠程主機的用戶名
-p ?PAR ? 指定pssh最大的并行線程數。
-o ?將輸出的內容重定向到一個指定的文件中
-O 指定ssh參數的具體配置
-e ?將執行錯誤重定向到一個指定的文件中
-t ?設定命令執行超時時間
-x ?傳遞ssh命令的一些參數
-i ?在遠程主機上執行命令完成后顯示標準輸出和標準錯誤
-P ?在執行遠程命令時,輸出執行結果
?用法實例:
pssh -P -i -h sz_vpc.txt "w"3pscp拷貝文件到遠程主機
pscp -h ip.txt /etc/wenjian.txt /tmp/4pnuke殺掉某一進程
這個命令類似yu ?killall命令
pnuke -h iplist.txt httpd上邊的意思是在遠程主機上批量關閉httpd服務
能通過killall關閉的服務,都可以通過pnuke來批量完成
?5 pslurp 遠程主機拷貝文件到本地主機
pslurp -h iplist.txt -L /home/ /hose/wenjian/yuanc.conf open.conf上邊是,將所有遠程主機/hose/wenjian/yuanc.conf復制到本地主機/home/目錄下,并且重新命名為open.conf ?-L 來指定本地文件路徑
下面這個是拷貝目錄
pslurp -h iplist.txt -r -L /home/ /hose/wenjian/ openps:建議分發文件,執行命令,批量殺死進程,使用pssh,pscp,pnuke,速度很快的
轉載于:https://www.cnblogs.com/Dicky-Zhang/p/5988415.html
總結
以上是生活随笔為你收集整理的运维自动化轻量级工具pssh的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: U3D临时文件GICache巨大
- 下一篇: Python中super()和__ini