1pssh介紹
pssh可在發在多臺機器上批量執行命令的工具,它支持文件並行複製,遠程命令執行,殺掉遠程主機上的進程等
等。當進行再遠程主機批量上傳下載的時候
2pssh的使用
在使用pssh之前,必須要保證管理主機和本地主機進行過密鑰的認證,或者是在進行批量時,沒有做過密鑰認
證,但是必須保證被管理的多臺主機的密碼相同。
3安裝
這個軟件在epel源中有,需要下載epel源文件後,可以用yum來安裝
CentOS 6
wget-O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
CentOS 7
wget-O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
4,常用命令
pssh:在遠程多臺主機上並行運行命令
pscp :把文件並行複製到多臺遠程主機上
prsync :使用rsync協議本地文件同步到遠程多臺主機上。
pnuke :在遠程多臺主機上並行killall某一進程
pslurp :把文件從遠程多臺主機上覆制到本地主機上
5,pssh的常用參數
-h HOST_FILE 後邊跟遠程主機列表(ip)
-H HOST_STRING 後邊跟遠程主機名或者ip地址
-l USER 指定遠程主機的用戶名
-p PAR 指定pssh最大的並行線程數。
-o 將輸出的內容重定向到一個指定的文件中
-O 指定ssh參數的具體配置
-e 將執行錯誤重定向到一個指定的文件中
-t 設定命令執行超時時間
-x 傳遞ssh命令的一些參數
-i 在遠程主機上執行命令完成後顯示標準輸出和標準錯誤
-P 在執行遠程命令時,輸出執行結果
6,使用方法
生成密鑰文件,並將文件拷貝到要控制的主機上
[root@localhost ~] ssh-keygen
[root@localhost ~] ssh-copy-id -i 192.168.8.133
查看遠程主機上查看主機名
[root@localhost ~] pssh -H 192.168.8.133 -A -i hostname
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password:
[1] 09:29:05 [SUCCESS] 192.168.8.133
localhost.localdomain
查看遠程主機文件夾下的目錄
[root@localhost ~] pssh -H 192.168.8.133 -A -i ls -l /tmp/
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password:
[1] 09:30:20 [SUCCESS] 192.168.8.133
關閉遠程主機的Apache服務
[root@localhost ~] pnuke -H 192.168.8.133 httpd
[1] 09:32:10 [SUCCESS] 192.168.8.133
遠程主機拷貝文件到本地主機的root目錄下,並改名爲test1
[root@localhost ~] pslurp -H 192.168.8.133 -L /root/ /root/test test1
[1] 09:35:21 [SUCCESS] 192.168.8.133
注:在root目錄下會自動創建一個和目標主機IP地址同名的目錄,文件在此目錄中
將多個主機的名稱寫入到文件中批量執行
[root@localhost ~] vim host.txt
192.168.8.133
192.168.8.128
[root@localhost ~] pssh -h host.txt -A -i hostname
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password:
[1] 09:53:42 [SUCCESS] 192.168.8.133
localhost.localdomain
[2] 09:53:42 [SUCCESS] 192.168.8.128
localhost