W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
批量管理執(zhí)行
pssh命令 是一個(gè)python編寫可以在多臺(tái)服務(wù)器上執(zhí)行命令的工具,同時(shí)支持拷貝文件,是同類工具中很出色的,類似pdsh,個(gè)人認(rèn)為相對(duì)pdsh更為簡(jiǎn)便,使用必須在各個(gè)服務(wù)器上配置好密鑰認(rèn)證訪問。
在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:主機(jī)文件列表,內(nèi)容格式”[user@]host[:port]”
-H:主機(jī)字符串,內(nèi)容格式”[user@]host[:port]”
-:登錄使用的用戶名
-p:并發(fā)的線程數(shù)【可選】
-o:輸出的文件目錄【可選】
-e:錯(cuò)誤輸入文件【可選】
-t:TIMEOUT 超時(shí)時(shí)間設(shè)置,0無限制【可選】
-O:SSH的選項(xiàng)
-v:詳細(xì)模式
-A:手動(dòng)輸入密碼模式
-x:額外的命令行參數(shù)使用空白符號(hào),引號(hào),反斜線處理
-X:額外的命令行參數(shù),單個(gè)參數(shù)模式,同-x
-i:每個(gè)服務(wù)器內(nèi)部處理信息輸出
-P:打印出服務(wù)器返回信息
獲取每臺(tái)服務(wù)器的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
查看每臺(tái)服務(wù)器上mysql復(fù)制IO/SQL線程運(yùn)行狀態(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
保存每臺(tái)服務(wù)器運(yùn)行的結(jié)果:
# 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/下的文件及其內(nèi)容
# 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命令很少的一部分,大家可以將其用到適合自己的場(chǎng)景,發(fā)揮它的最大功效。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: