W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
批量管理執(zhí)行
pssh命令 是一個python編寫可以在多臺服務器上執(zhí)行命令的工具,同時支持拷貝文件,是同類工具中很出色的,類似pdsh,個人認為相對pdsh更為簡便,使用必須在各個服務器上配置好密鑰認證訪問。
在CentOS系統(tǒng)環(huán)境下,介紹yum的安裝和源碼安裝的方式:
yum方法
yum install pssh
編譯安裝
wget http://parallel-ssh.googlecode.com/files/pssh-2.3.1.tar.gz
tar xf pssh-2.3.1.tar.gz
cd pssh-2.3.1/
python setup.py install
--version:查看版本
--help:查看幫助,即此信息
-h:主機文件列表,內容格式”[user@]host[:port]”
-H:主機字符串,內容格式”[user@]host[:port]”
-:登錄使用的用戶名
-p:并發(fā)的線程數【可選】
-o:輸出的文件目錄【可選】
-e:錯誤輸入文件【可選】
-t:TIMEOUT 超時時間設置,0無限制【可選】
-O:SSH的選項
-v:詳細模式
-A:手動輸入密碼模式
-x:額外的命令行參數使用空白符號,引號,反斜線處理
-X:額外的命令行參數,單個參數模式,同-x
-i:每個服務器內部處理信息輸出
-P:打印出服務器返回信息
獲取每臺服務器的uptime:
# pssh -h ip.txt -i uptime
[1] 11:15:03 [SUCCESS] Mar.mars.he
11:15:11 up 4 days, 16:25, 1 user, load average: 0.00, 0.00, 0.00
[2] 11:15:03 [SUCCESS] Jan.mars.he
11:15:12 up 3 days, 23:26, 0 users, load average: 0.00, 0.00, 0.00
[3] 11:15:03 [SUCCESS] Feb.mars.he
11:15:12 up 4 days, 16:26, 2 users, load average: 0.08, 0.02, 0.01
查看每臺服務器上mysql復制IO/SQL線程運行狀態(tài)信息:
# pssh -h IP.txt -i "/usr/local/mysql/bin/mysql -e 'show slave status \G'"|grep Running:
Slave_IO_Running: yes
Slave_SQL_Running: Yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
保存每臺服務器運行的結果:
# pssh -h IP.txt -i -o /tmp/pssh/ uptime
[1] 11:19:47 [SUCCESS] Feb.mars.he
11:19:55 up 4 days, 16:31, 2 users, load average: 0.02, 0.03, 0.00
[2] 11:19:47 [SUCCESS] Jan.mars.he
11:19:56 up 3 days, 23:30, 0 users, load average: 0.01, 0.00, 0.00
[3] 11:19:47 [SUCCESS] Mar.mars.he
11:19:56 up 4 days, 16:30, 1 user, load average: 0.00, 0.00, 0.00
我們來看一下/tmp/pssh/下的文件及其內容
# ll /tmp/pssh/
總用量 12
-rw-r--r--. 1 root root 70 12月 1 11:19 Feb.mars.he
-rw-r--r--. 1 root root 70 12月 1 11:19 Jan.mars.he
-rw-r--r--. 1 root root 69 12月 1 11:19 Mar.mars.he
# cat /tmp/pssh/*
11:19:55 up 4 days, 16:31, 2 users, load average: 0.02, 0.03, 0.00
11:19:56 up 3 days, 23:30, 0 users, load average: 0.01, 0.00, 0.00
11:19:56 up 4 days, 16:30, 1 user, load average: 0.00, 0.00, 0.00
上面介紹的是pssh命令很少的一部分,大家可以將其用到適合自己的場景,發(fā)揮它的最大功效。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: