




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、如果你有以下需求,本文章或許會對你有所幫助:1. 網(wǎng)絡(luò)里L(fēng)INUX服務(wù)器較多,缺乏統(tǒng)一管理的工具。2. 系統(tǒng)經(jīng)常需要更改,如果定期更改所有服務(wù)器密碼、批量更新特定文件等。3. 需實時獲得所有服務(wù)器的運(yùn)行信息,例如,需立刻查看每臺服務(wù)上裝分別裝了多少根內(nèi)存條該怎么辦,難道一臺臺登錄 上去看?當(dāng)然一般的系統(tǒng)監(jiān)控軟件是不會收集服務(wù)器有多少條內(nèi)存條這樣的信息的。4. 如果想往所有服務(wù)器上放一個文件,怎么辦?5. 想在所有服務(wù)器上啟動一個服務(wù)或執(zhí)行一個腳本怎么辦?大家在讀下文時如有不理解的地方或其它問題,可以隨時聯(lián)系我,大家互相交流,共同成長,我的qq:317828332#做Linux系統(tǒng)管理以來,由于
2、維護(hù)過比較大的網(wǎng)絡(luò),例如在飛信做支持的時候,面對上千臺的服務(wù)器,有時候可能要對每臺機(jī)子打一個補(bǔ)丁,或者是修改一個文件,如果只有10臺服務(wù)器,那一一修改也就罷了,但是如果讓你一臺一臺的登錄1000臺服務(wù)器只是為了去改一個文件,那一定痛苦死,并且效率低下,沒有任何技術(shù)含量,如果一直做這種工作,那被稱為IT民工也不能怪別人了,因為我一直想找一個可以批量管理的工具,后來發(fā)現(xiàn)了兩種方式可以實現(xiàn):1.通過SSH密鑰認(rèn)證,這樣登錄到遠(yuǎn)程機(jī)器上后就不需要輸入密碼了,這樣就可以通過腳本去批量登錄到遠(yuǎn)程服務(wù)器并且修改你想要文件或操作等,但是這有一個缺點,就是這個在管理端的私鑰你一定要保存好,萬一管理服務(wù)器系統(tǒng)重裝
3、或其它原因?qū)е滤借€丟失,那你就沒辦法登錄遠(yuǎn)程機(jī)器了。還有,如果需要管理的機(jī)器更改了IP,那你還得重新把公鑰COPY到那臺機(jī)子上,這樣管理起來可能不是那么靈活。2.通過expect 工具進(jìn)行批量管理,expect工具很強(qiáng)大,可以實現(xiàn)交互式管理,比如如果你想改密碼,輸入passwd命令后,系統(tǒng)會提示你輸入New Password: ,如果使用普通腳本的話,那你是沒辦法進(jìn)行交互式的。但是expect就可以做到檢測系統(tǒng)的返回值并且根據(jù)返回的提示來自動交互,如下例:#!/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; #自動輸入密碼expect "hknp"send "/etc/init.d/heartbeat stop r" #停止一個程序expect "hknp"send "exitr" #退出系統(tǒng)expect eofexit以上腳本通過命令: expect ha-switch.exp 192.168.193.133 123DDFD執(zhí)行 ,其中123DDFD 就是133這臺機(jī)子的root密碼,如果你的一百臺機(jī)子都是一樣的密碼,你就可以寫個簡單的
6、批量腳本來登錄所有的機(jī)子并停止一個程序,如下:#!/bin/bashfor i in $(seq 100 200);doIP = "192.168.193.$i"expect ha-switch.exp $IP '123DDFD'done這樣此腳本就會調(diào)用ha-switch.exp腳本并登錄到192.168.193.100-200的機(jī)器上分別執(zhí)行"/etc/init.d/heartbeat stop 命令了。很強(qiáng)大吧,但使通過我使用的經(jīng)驗,我覺得expect 有個缺點就是有慢,因為它是一臺一臺的去登錄 然后執(zhí)行命令,因為有的時
7、候由于DNS解析或什么原因 ,通過SSH登錄到一臺機(jī)子時可能需要等待30s才能登錄進(jìn)去,假如1000臺機(jī)子的話那就需要50分鐘才能完成在所有機(jī)器上的操作,對于要求在1分鐘內(nèi)實現(xiàn)數(shù)千臺機(jī)器執(zhí)行相同操作的需要來講這顯然達(dá)不到要求。以上兩種方法各有利弊,我個人建議在50-100臺的小網(wǎng)絡(luò)中可以考慮使用SSH認(rèn)證或expect的方法。但是想像一下,如果我有一萬臺機(jī)器 ,分別處于全國各地不同的網(wǎng)絡(luò)中,要求我在1分鐘內(nèi)更改所有機(jī)器的root密碼,顯然以上兩種方法均是做不到的,當(dāng)然有這樣大型網(wǎng)絡(luò)的公司中國也并不多見,但是從技術(shù)的角度上來講這還是有一定挑戰(zhàn)性的,由于在網(wǎng)上一直找不到這樣的工具,我就自己索性寫了
8、一個,經(jīng)過多天的努力,終于將這個批量管理工具寫完了,此工具是用的Python寫的,基于socket server的模式,即需要在所有的需要管理的服務(wù)器上啟動一個客戶端(可能好多朋友不太喜歡這種還需要裝客戶端的東東),客戶端會開啟一個端口,你的管理服務(wù)器就是通過此端口與被管理端通信,然后對被管理端進(jìn)行操作,你可以遠(yuǎn)程修改密碼,查看系統(tǒng)信息,內(nèi)存情況等操作,操作結(jié)果會在你的管理端實現(xiàn)顯示出來(這也是我比較喜歡的地方,就跟在本地操作命令一樣)。并且還可以向遠(yuǎn)程服務(wù)器批量COPY文件,下面我就把這個工具在使用過程中的一些截圖列出來: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 #登錄到某臺機(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;#同時在多臺遠(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 #每臺設(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 #每臺設(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 #每臺設(shè)備返回的結(jié)果 1900000DesktopDocumentsRMT_client.pyRemote_management_toolautoinst.xmlbinnohup.outntp-clientscriptvmware#Received log from /root/Remote_management_tool/192.168.193.137.log #每臺設(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 #每臺設(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 #批量更改多臺服務(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 #批量往多臺服務(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 #批量部署客戶端到多臺服務(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等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 南昌市污泥固化處理工程方案
- 2025年天津市創(chuàng)佳時代科技企業(yè)管理有限公司招聘考試筆試試題(含答案)
- 2025年濟(jì)寧金鄉(xiāng)縣城鎮(zhèn)公益性崗位招聘考試筆試試題(含答案)
- 代持房產(chǎn)繼承完整協(xié)議書范本
- 征兵體檢培訓(xùn)內(nèi)科課件
- 生產(chǎn)安全責(zé)任制度內(nèi)容
- 2025年煤礦安全培訓(xùn)心得體會
- 幼兒園安全隱患排查會議記錄
- 安全生產(chǎn)二十字方針
- 育嬰員培訓(xùn)課件
- T/CNFAGS 16-2024綠色甲醇分級標(biāo)準(zhǔn)(試行)
- 國民經(jīng)濟(jì)行業(yè)分類代碼(2024年版)
- 房屋市政工程生產(chǎn)安全重大事故隱患判定檢查表(2024版)
- 2025年財會業(yè)務(wù)知識競賽題庫及答案(360題)
- 大連農(nóng)商銀行2024年招聘172人管理單位遴選500模擬題附帶答案詳解
- 鋼卷尺檢定證書
- 齊魯醫(yī)學(xué)健康知識-遠(yuǎn)離“三高”
- 安徽省工傷職工停工留薪期分類目錄
- 混凝土試件養(yǎng)護(hù)出入臺賬
- 2022醫(yī)學(xué)課件出疹性傳染病
- 職業(yè)安全衛(wèi)生知識競賽題
評論
0/150
提交評論