




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、如果你有以下需求,本文章或許會(huì)對(duì)你有所幫助:1. 網(wǎng)絡(luò)里L(fēng)INUX服務(wù)器較多,缺乏統(tǒng)一管理的工具。2. 系統(tǒng)經(jīng)常需要更改,如果定期更改所有服務(wù)器密碼、批量更新特定文件等。3. 需實(shí)時(shí)獲得所有服務(wù)器的運(yùn)行信息,例如,需立刻查看每臺(tái)服務(wù)上裝分別裝了多少根內(nèi)存條該怎么辦,難道一臺(tái)臺(tái)登錄 上去看?當(dāng)然一般的系統(tǒng)監(jiān)控軟件是不會(huì)收集服務(wù)器有多少條內(nèi)存條這樣的信息的。4. 如果想往所有服務(wù)器上放一個(gè)文件,怎么辦?5. 想在所有服務(wù)器上啟動(dòng)一個(gè)服務(wù)或執(zhí)行一個(gè)腳本怎么辦?大家在讀下文時(shí)如有不理解的地方或其它問題,可以隨時(shí)聯(lián)系我,大家互相交流,共同成長(zhǎng),我的qq:317828332#做Linux系統(tǒng)管理以來,由于
2、維護(hù)過比較大的網(wǎng)絡(luò),例如在飛信做支持的時(shí)候,面對(duì)上千臺(tái)的服務(wù)器,有時(shí)候可能要對(duì)每臺(tái)機(jī)子打一個(gè)補(bǔ)丁,或者是修改一個(gè)文件,如果只有10臺(tái)服務(wù)器,那一一修改也就罷了,但是如果讓你一臺(tái)一臺(tái)的登錄1000臺(tái)服務(wù)器只是為了去改一個(gè)文件,那一定痛苦死,并且效率低下,沒有任何技術(shù)含量,如果一直做這種工作,那被稱為IT民工也不能怪別人了,因?yàn)槲乙恢毕胝乙粋€(gè)可以批量管理的工具,后來發(fā)現(xiàn)了兩種方式可以實(shí)現(xiàn):1.通過SSH密鑰認(rèn)證,這樣登錄到遠(yuǎn)程機(jī)器上后就不需要輸入密碼了,這樣就可以通過腳本去批量登錄到遠(yuǎn)程服務(wù)器并且修改你想要文件或操作等,但是這有一個(gè)缺點(diǎn),就是這個(gè)在管理端的私鑰你一定要保存好,萬一管理服務(wù)器系統(tǒng)重裝
3、或其它原因?qū)е滤借€丟失,那你就沒辦法登錄遠(yuǎn)程機(jī)器了。還有,如果需要管理的機(jī)器更改了IP,那你還得重新把公鑰COPY到那臺(tái)機(jī)子上,這樣管理起來可能不是那么靈活。2.通過expect 工具進(jìn)行批量管理,expect工具很強(qiáng)大,可以實(shí)現(xiàn)交互式管理,比如如果你想改密碼,輸入passwd命令后,系統(tǒng)會(huì)提示你輸入New Password: ,如果使用普通腳本的話,那你是沒辦法進(jìn)行交互式的。但是expect就可以做到檢測(cè)系統(tǒng)的返回值并且根據(jù)返回的提示來自動(dòng)交互,如下例:#!/usr/bin/expect -fset ipaddress lindex $argv 0 #設(shè)置命令行參數(shù)set passwd li
4、ndex $argv 1 #參數(shù)1 為passwordset ipaddress lindex $argv 0 #參數(shù) 0 為IP 地址set timeout 1000 spawn ssh root$ipaddressexpect "yes/no" send "yesr"exp_continue "Password:" send "$passwdr&qu
5、ot; #自動(dòng)輸入密碼expect "hknp"send "/etc/init.d/heartbeat stop r" #停止一個(gè)程序expect "hknp"send "exitr" #退出系統(tǒng)expect eofexit以上腳本通過命令: expect ha-switch.exp 192.168.193.133 123DDFD執(zhí)行 ,其中123DDFD 就是133這臺(tái)機(jī)子的root密碼,如果你的一百臺(tái)機(jī)子都是一樣的密碼,你就可以寫個(gè)簡(jiǎn)單的
6、批量腳本來登錄所有的機(jī)子并停止一個(gè)程序,如下:#!/bin/bashfor i in $(seq 100 200);doIP = "192.168.193.$i"expect ha-switch.exp $IP '123DDFD'done這樣此腳本就會(huì)調(diào)用ha-switch.exp腳本并登錄到192.168.193.100-200的機(jī)器上分別執(zhí)行"/etc/init.d/heartbeat stop 命令了。很強(qiáng)大吧,但使通過我使用的經(jīng)驗(yàn),我覺得expect 有個(gè)缺點(diǎn)就是有慢,因?yàn)樗且慌_(tái)一臺(tái)的去登錄 然后執(zhí)行命令,因?yàn)橛械臅r(shí)
7、候由于DNS解析或什么原因 ,通過SSH登錄到一臺(tái)機(jī)子時(shí)可能需要等待30s才能登錄進(jìn)去,假如1000臺(tái)機(jī)子的話那就需要50分鐘才能完成在所有機(jī)器上的操作,對(duì)于要求在1分鐘內(nèi)實(shí)現(xiàn)數(shù)千臺(tái)機(jī)器執(zhí)行相同操作的需要來講這顯然達(dá)不到要求。以上兩種方法各有利弊,我個(gè)人建議在50-100臺(tái)的小網(wǎng)絡(luò)中可以考慮使用SSH認(rèn)證或expect的方法。但是想像一下,如果我有一萬臺(tái)機(jī)器 ,分別處于全國(guó)各地不同的網(wǎng)絡(luò)中,要求我在1分鐘內(nèi)更改所有機(jī)器的root密碼,顯然以上兩種方法均是做不到的,當(dāng)然有這樣大型網(wǎng)絡(luò)的公司中國(guó)也并不多見,但是從技術(shù)的角度上來講這還是有一定挑戰(zhàn)性的,由于在網(wǎng)上一直找不到這樣的工具,我就自己索性寫了
8、一個(gè),經(jīng)過多天的努力,終于將這個(gè)批量管理工具寫完了,此工具是用的Python寫的,基于socket server的模式,即需要在所有的需要管理的服務(wù)器上啟動(dòng)一個(gè)客戶端(可能好多朋友不太喜歡這種還需要裝客戶端的東東),客戶端會(huì)開啟一個(gè)端口,你的管理服務(wù)器就是通過此端口與被管理端通信,然后對(duì)被管理端進(jìn)行操作,你可以遠(yuǎn)程修改密碼,查看系統(tǒng)信息,內(nèi)存情況等操作,操作結(jié)果會(huì)在你的管理端實(shí)現(xiàn)顯示出來(這也是我比較喜歡的地方,就跟在本地操作命令一樣)。并且還可以向遠(yuǎn)程服務(wù)器批量COPY文件,下面我就把這個(gè)工具在使用過程中的一些截圖列出來:bjnppb01:/scripts/python_scripts/Re
9、mote_management_tool/Remote_management_tool_v1.3 # python RMT_server.py # RMT(Remote Management tool)
10、0; #
11、60; # Version 1.3,2011-01-21
12、 # Author:Alex Li
13、; # Email:lijie3721,QQ:317828332 #please slect the following menu: &
14、#160; 0 list servers 1 Scan agent status 2 login to remote server
15、; 3 Reboot all the remote servers(does't support) 4 Upload server list 5 excute command on all the aviliable servers
16、0; 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote servers
17、; 9 exitPlease enter the slected number:0 #列出所有服務(wù)器列表192.168.193.133192.168.193.134192.168.193.135192.168.193.136192.168.193.137192.168.193.138192.168.193.140192.168.193.141192.168.193.142please slect the following menu: #
18、60; 0 list servers 1 Scan agent status 2 login to remote server
19、 3 Reboot all the remote servers(does't support) 4 Upload server list 5 excute command on all the aviliable servers
20、 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote servers
21、 9 exitPlease enter the slected number:1 #掃描所有服務(wù)器列表上的客戶端的狀態(tài)192.168.193.133 down192.168.193.134 down192.168.193.135 running192.168.193.136 down192.168.193.137 running192.168.193.138 running1
22、92.168.193.140 down192.168.193.141 down192.168.193.142 downplease slect the following menu: 0 list servers 1 Scan agent sta
23、tus 2 login to remote server 3 Reboot all the remote servers(does't support) 4 Upload server list
24、60; 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remot
25、e servers 8 install the client application on all the remote servers 9 exitPlease enter the slected number:2 #登錄到某臺(tái)機(jī)器Please enter the remote server IP: 192.16
26、8.193.135 #輸入IP地址You have successfully login to the remote server, now you can run most of the system command in this mode ,but do not suggestyou to run the command such as top,tail -f,because right now I haven't find a way to support the continuous data outputPlease input the command:uname -a #
27、輸入的命令Received log from /root/Remote_management_tool/192.168.193.135.log#Linux bjnpif02 2.6.16.60-0.54.5-smp #1 SMP Fri Sep 4 01:28:03 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux #顯示的結(jié)果#Please input the command:ls #輸入的命令Received log from /root/Remote_management_tool/192.168.193.135
28、.log# #顯示的結(jié)果1900000DesktopDocumentsRMT_client.pyRemote_management_toolautoinst.xmlbinnohup.outntp-clientscriptvmware#Please input the command:exitplease slect the following menu: 0 list servers
29、160; 1 Scan agent status 2 login to remote server 3 Reboot all the remote servers(does't support)
30、160; 4 Upload server list 5 excute command on all the aviliable servers 6 change password for all the servers
31、160; 7 copy scripts to remote servers 8 install the client application on all the remote servers 9 exitPlease enter the slected number:3 please slect the fol
32、lowing menu: 0 list servers 1 Scan agent status 2 login to remote server
33、; 3 Reboot all the remote servers(does't support) 4 Upload server list 5 excute command on all the aviliable servers
34、0; 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote
35、 servers 9 exitPlease enter the slected number:4 #上傳服務(wù)器列表 Please enter the full path of your file: lsNo such file,please make sure you inputed the right file. Please enter the full path of your file: /tmp.HNo such file,please make sure
36、 you inputed the right file.Please enter the full path of your file: /tmp/list 192.168.193.3192.32.34.24Adding uploaded list to Server list.# done.please slect the following menu: 0 list servers
37、160; 1 Scan agent status 2 login to remote server 3 Reboot all the remote servers(does't support)
38、160; 4 Upload server list 5 excute command on all the aviliable servers 6 change password for all the servers
39、160; 7 copy scripts to remote servers 8 install the client application on all the remote servers 9 exitPlease enter the slected number:5
40、160;#同時(shí)在多臺(tái)遠(yuǎn)程服務(wù)器上執(zhí)行命令并返回結(jié)果 It might will takes a few minutes to scan all the avialiable servers.The fllowing servers are avaliable: #可以進(jìn)行遠(yuǎn)程操作的列表192.168.193.135 192.168.193.137192.168.193.138please input your command: uname -a #輸入命令Received log from /root/Remote_management_tool
41、/192.168.193.135.logLinux bjnpif02 2.6.16.60-0.54.5-smp #1 SMP Fri Sep 4 01:28:03 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux #每臺(tái)設(shè)備返回的結(jié)果#Received log from /root/Remote_management_tool/192.168.193.137.logLinux bjnpbo01 2.6.16.60-0.54.5-smp #1 SMP Fri Sep 4 01:28:03 UTC 2009 x86_64 x86_64 x86_6
42、4 GNU/Linux #每臺(tái)設(shè)備返回的結(jié)果#Received log from /root/Remote_management_tool/192.168.193.138.logLinux bjnpbo02 2.6.16.60-0.54.5-smp #1 SMP Fri Sep 4 01:28:03 UTC 2009 x86_64 x86_64 x86_64 GNU/Linux#please input your command: iHReceived log from /root/Remote_management_tool/192.168.193.135.logsh: : command
43、not found#Received log from /root/Remote_management_tool/192.168.193.137.logsh: : command not found#Received log from /root/Remote_management_tool/192.168.193.138.logsh: : command not found#please input your command: ls #輸入的命令Received log from /root/Remote_management_tool/192.168.193.135.
44、log #每臺(tái)設(shè)備返回的結(jié)果 1900000DesktopDocumentsRMT_client.pyRemote_management_toolautoinst.xmlbinnohup.outntp-clientscriptvmware#Received log from /root/Remote_management_tool/192.168.193.137.log #每臺(tái)設(shè)備返回的結(jié)果1900000DesktopDocumentsRMT_client.pyRemote_management_toolaautoinst.x
45、mlbinetcjdk-6u17-linux-amd64.rpmjdk1.6.0_17netperf-2.4.5netperf-2.4.5.tar.gznohup.outntp-clientoptsbinsun-javadb-client-10.4.2-1.1.i386.rpmsun-javadb-common-10.4.2-1.1.i386.rpmsun-javadb-core-10.4.2-1.1.i386.rpmsun-javadb-demo-10.4.2-1.1.i386.rpmsun-javadb-docs-10.4.2-1.1.i386.rpmsun-javadb-javadoc-
46、10.4.2-1.1.i386.rpmusrworkspace#Received log from /root/Remote_management_tool/192.168.193.138.log #每臺(tái)設(shè)備返回的結(jié)果1900000DesktopDocumentsRMT_client.pyRemote_management_toolautoinst.xmlbinnohup.outntp-client#please input your command: exitplease slect the following menu:
47、0; 0 list servers 1 Scan agent status 2 login to remote server 3
48、 Reboot all the remote servers(does't support) 4 Upload server list 5 excute command on all the aviliable servers &
49、#160; 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote servers
50、160; 9 exitPlease enter the slected number:6 #批量更改多臺(tái)服務(wù)器密碼 Please use the follow method to change password on remote server:
51、0; use command: echo "your password"|passwd your_user -stdin
52、160; For example ,if you want to change oracle user's password to '123456', then you need run
53、 echo "123456"|passwd oracle -stdin
54、160; please slect the following menu: 0 list servers 1 Scan agent status
55、2 login to remote server 3 Reboot all the remote servers(does't support) 4 Upload server list 5 excu
56、te command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote servers &
57、#160; 8 install the client application on all the remote servers 9 exitPlease enter the slected number:7 #批量往多臺(tái)服務(wù)器上拷文件Please enter the file name which you wanted to copy to remote servers:/tmp/list #文件名192.168.193
58、.133Connection refused by the remote server 192.168.193.133 #連接失敗,please make sure you IP is allowed by the remote server.192.168.193.134Connection refused by the remote server 192.168.193.134,please make sure you IP is allowed by the remote server.192.168.193.135
59、;#COPY成功192.168.193.136Connection refused by the remote server 192.168.193.136,please make sure you IP is allowed by the remote server.192.168.193.137 #COPY成功192.168.193.138 #COPY成功192.168.193.140Connection refused by the remote server 192.168.193.140,please make sure you IP i
60、s allowed by the remote server.192.168.193.141Connection refused by the remote server 192.168.193.141,please make sure you IP is allowed by the remote server.192.168.193.142Connection refused by the remote server 192.168.193.142,please make sure you IP is allowed by the remote server.192.168.193.3Co
61、nnection refused by the remote server 192.168.193.3,please make sure you IP is allowed by the remote server.192.32.34.24Connection refused by the remote server 192.32.34.24,please make sure you IP is allowed by the remote server. File list has successfully copied into /root/Remote_managem
62、ent_tool/recieved_files directory of above remote servers.please slect the following menu: 0 list servers 1 Scan agent status
63、; 2 login to remote server 3 Reboot all the remote servers(does't support) 4 Upload server list
64、0; 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote servers
65、; 8 install the client application on all the remote servers 9 exitPlease enter the slected number:8 #批量部署客戶端到多臺(tái)服務(wù)器上This function is for you to install client application on mutiple servers , to ach
66、ieve this, please follow the following step: 1 Fill your IP address and password of remote server in to password.txt under expect_tool directory 2 Make you have the access right to /root directory on remote server,the client f
67、ile RMT_client.py will be copied into /root/ directory on all the remote servers which you assigned in password.txtDo you want install the client on mutiple servers? (yes/no) :yStarting to install RMT_client.py on remote servers.Checking for the remote server list.Going to install on the
68、 following servers:192.168.193.137192.168.193.135spawn scp -rp ./RMT_client.py 192.168.193.137:/root/Password: RMT_client.py
69、 100% 1983 1.9KB/s 00:00 spawn ssh root192.168.193.137Password: Last login: Fri Jan 21 16:06:20 2011 from 192.168.193.132bjnpbo01:
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年黑龍江農(nóng)業(yè)工程職業(yè)學(xué)院?jiǎn)握新殬I(yè)傾向性測(cè)試題庫(kù)及答案一套
- 2025年河南醫(yī)學(xué)高等專科學(xué)校單招職業(yè)傾向性測(cè)試題庫(kù)新版
- 2025年甘肅省甘南藏族自治州單招職業(yè)適應(yīng)性測(cè)試題庫(kù)帶答案
- 2025年河南地礦職業(yè)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(kù)審定版
- 2025年河南工業(yè)職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)傾向性測(cè)試題庫(kù)完整
- 科技成果轉(zhuǎn)化的國(guó)際經(jīng)驗(yàn)與本土實(shí)踐
- 2025年貴州省畢節(jié)地區(qū)單招職業(yè)適應(yīng)性測(cè)試題庫(kù)完整版
- 2025年湖北交通職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)傾向性測(cè)試題庫(kù)學(xué)生專用
- 2025年貴州建設(shè)職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)傾向性測(cè)試題庫(kù)及答案1套
- 2025年吉林交通職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(kù)含答案
- 法規(guī)解讀丨2024新版《突發(fā)事件應(yīng)對(duì)法》及其應(yīng)用案例
- JGJ46-2024 建筑與市政工程施工現(xiàn)場(chǎng)臨時(shí)用電安全技術(shù)標(biāo)準(zhǔn)
- 2024年世界職業(yè)院校技能大賽高職組“關(guān)務(wù)實(shí)務(wù)組”賽項(xiàng)參考試題庫(kù)(含答案)
- 河北美術(shù)出版社小學(xué)六年級(jí)下冊(cè)書法練習(xí)指導(dǎo)教案
- 五下音樂《美麗的家鄉(xiāng)(簡(jiǎn)譜、五線譜)》課件
- 2024年長(zhǎng)沙職業(yè)技術(shù)學(xué)院高職單招(英語(yǔ)/數(shù)學(xué)/語(yǔ)文)筆試歷年參考題庫(kù)含答案解析
- 會(huì)計(jì)英語(yǔ)專業(yè)詞匯全
- 拆除工程檢驗(yàn)批質(zhì)量檢驗(yàn)記錄
- 怎樣把握文章線索
- LED與金鹵燈對(duì)比(共4頁(yè))
- (完整版)部編四年級(jí)語(yǔ)文下詞語(yǔ)表
評(píng)論
0/150
提交評(píng)論