Linux下批量管理工具pssh安裝和使用
pssh工具包
安裝:yum -y install pssh
- pssh:在多個主機上並行地運行命令
- pscp:把文件並行地復制到多個主機上
- prsync:通過 rsync 協議把文件高效地並行復制到多個主機上
- pslurp:把文件並行地從多個遠程主機復制到中心主機上
- pnuke:並行地在多個遠程主機上殺死進程
pssh配置
要求:執行pssh的機器務必要與遠程機器有信任關系,即可以ssh免密碼登錄(ssh-copy-id)
IP列表文件內容格式[user@]host[:port]
如:root@127.0.0.1:22 (默認用戶為root,默認端口為22,用戶及端口為可選參數)
pssh幫助文檔
- --version:查看版本
- --help:查看幫助,即此信息
- -h:主機文件列表,內容格式"[user@]host[:port]"
- -H:主機字符串,內容格式"[user@]host[:port]"
- -l:登錄使用的用戶名
- -p:並發的線程數【可選】
- -o:輸出目錄(將遠程執行結果輸出到指定目錄,輸出結果存入到對應主機名文件)【可選】
- -e:錯誤輸入文件【可選】
- -t:TIMEOUT 超時時間設置,0無限制【可選】
- -i:每個服務器內部處理信息輸出
- -P:打印出服務器返回信息
pssh Example
pssh -i -h hostsFile command
pssh -i -h -p 10 hostsFile command
pssh -i -H 127.0.0.1 command
pscp.pssh Example
作用:
- 傳輸文件到多個hosts,類似scp
pscp.pssh -h hostsFile localFile1 localFile2 remoteDir - 傳輸目錄到多個hosts,需要添加
-r
參數
pscp.pssh -h hostsFile -r localDir1 localDir2 remoteDir
pslurp Example
作用:
- 從多台遠程機器拷貝文件到本地 (只能下載到當前目錄,不能在命令中跟指定的路徑,建議cd到指定目錄執行)
slurp -h hostsFile remoteFile ./ - 從多台遠程機器拷貝目錄到本地,需要添加
-r
參數
slurp -h hostsFile -r remoteFile ./
prsync Example
作用:使用rsync協議從本地計算機同步文件到遠程主機
- 批量同步文件 (完全覆蓋,遠程機器文件會被替換)
rsync -r -h hostsFile localFile remoteFile - 批量同步目錄 (將本機對應目錄數據同步到遠程機器上,遠程機器上對於目錄下多余的文件也會保留,不會刪除多余文件)
rsync -r -h hostsFile -r localDir remoteDir