Polysh命令實(shí)現(xiàn)多日志查詢

一、Polysh簡介

Polysh 是一個(gè)交互式命令,可以在一臺(tái)服務(wù)器上批量的對(duì)一批服務(wù)器進(jìn)行處理,運(yùn)行交互式命令。Polysh可以同時(shí)登錄多個(gè)遠(yuǎn)程主機(jī),而不需要通過relay一臺(tái)一臺(tái)的登錄,并執(zhí)行相同的指令,方便了問題的排查和定位,大大減少了我們的工作量。

注: 官方解釋:Polysh 是一個(gè)由幾個(gè)遠(yuǎn)程腳本集合而成的工具,它被用于在許多服務(wù)器上運(yùn)行一個(gè)交互式的遠(yuǎn)程腳本,由 Python 編寫,最低要求為 Python 2.4 。

二、polysh安裝

通過relay登錄staging機(jī)器,執(zhí)行如下命令安裝polysh。安裝目錄為用戶目錄: /opt/hl/。

1.已安裝python的安裝
wget wget http://guichaz.free.fr/polysh/files/polysh-0.4.tar.gz
tar -zxvf polysh-0.4.tar.gz

vim prod-polysh.sh
腳本內(nèi)容如下:
#10.252.176.33,10.252.176.35是你要鏈接的機(jī)器ip
python /opt/hl/polysh-0.4/polysh.py {10.252.176.33,10.252.176.35}

開放給其他用戶可執(zhí)行的權(quán)限

chmod 777 prod-polysh.sh
2.未安裝python的安裝
wget wget http://guichaz.free.fr/polysh/files/polysh-0.4.tar.gz
tar -zxvf polysh-0.4.tar.gz
cd polysh-0.4 
su 
python setup.py install

vim prod-polysh.sh
腳本內(nèi)容如下:
#10.252.176.33,10.252.176.35是你要鏈接的機(jī)器ip
python /opt/hl/polysh-0.4/polysh.py {10.252.176.33,10.252.176.35}

開放給其他用戶可執(zhí)行的權(quán)限
chmod 777 prod-polysh.sh

三、Xshell配置Xagent(mac可跳過這一步)

打開文件-屬性,選擇SSH選項(xiàng),選擇”使用密碼處理的Xagent(SSH代理)”。然后將Xshell重啟。

四、polysh使用

4.1.使用方法一
polysh 10.252.176.33 10.252.176.35
4.2.使用方法二
./prod-polysh.sh

則會(huì)出現(xiàn)如下提示信息

[---hl-----]$ ./prod-polysh.sh
ready (8)

ready (8) 表示 8臺(tái)機(jī)器已經(jīng)連接完畢,可以執(zhí)行查詢命令。exit或Crtl+z都可以退出。

4.3.執(zhí)行命令
ready (8)>cd /opt/hl
ready (8)>pwd

顯示如下:

10.252.176.33: /opt/hl
10.252.176.35 : /opt/hl

五、源碼

可以通過git獲取polysh的源碼

git clone git://repo.or.cz/polysh.git

六、其他

以冒號(hào)開頭的指令不會(huì)發(fā)送到遠(yuǎn)程主機(jī),polysh會(huì)執(zhí)行以冒號(hào)開頭的指令,例如:

ready (2)> :help 
:add Add one or many remote shells. 
:chdir Change the current directory of polysh (not the remote shells). 
:disable Disable sending commands to remote shells. 
:enable Enable sending commands to remote shells. 
:export_vars Export some environment variables on enabled remote shells. 
:help List control commands or show their documentations. 
:hide_password Do not echo the next typed line. 
:list List remote shells and their states. 
:purge Delete disabled remote shells. 
:quit Quit polysh. 
:reconnect Try to reconnect to disconnected remote shells. 
:rename Rename all enabled remote shells with the argument. 
:replicate Copy a path from one remote shell to all others 
:reset_prompt Change the prompt to be recognized by polysh. 
:send_ctrl Send a control character to remote shells. 
:set_debug Enable or disable debugging output for remote shells. 
:set_log Duplicate every console I/O into the given local file. 
:show_read_buffer Print the data read by remote shells. 
:upload Upload the specified local path to enabled remote shells.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • linux資料總章2.1 1.0寫的不好抱歉 但是2.0已經(jīng)改了很多 但是錯(cuò)誤還是無法避免 以后資料會(huì)慢慢更新 大...
    數(shù)據(jù)革命閱讀 13,196評(píng)論 2 33
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,527評(píng)論 19 139
  • Ubuntu的發(fā)音 Ubuntu,源于非洲祖魯人和科薩人的語言,發(fā)作 oo-boon-too 的音。了解發(fā)音是有意...
    螢火蟲de夢(mèng)閱讀 100,603評(píng)論 9 468
  • # Python 資源大全中文版 我想很多程序員應(yīng)該記得 GitHub 上有一個(gè) Awesome - XXX 系列...
    aimaile閱讀 26,832評(píng)論 6 427
  • 我以為我已經(jīng)痊愈,經(jīng)過忙碌充實(shí)快樂的半天后。 上午J讓我?guī)ヅ月犖衣牭哪情T課,沒想到她還挺感興趣。她的聽力口...
    顏如蘇閱讀 275評(píng)論 0 0

友情鏈接更多精彩內(nèi)容