版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、如果你有以下需求,本文章或許會對你有所幫助:1. 網絡里LINUX服務器較多,缺乏統(tǒng)一管理的工具。2. 系統(tǒng)經常需要更改,如果定期更改所有服務器密碼、批量更新特定文件等。3. 需實時獲得所有服務器的運行信息,例如,需立刻查看每臺服務上裝分別裝了多少根內存條該怎么辦,難道一臺臺登錄 上去看?當然一般的系統(tǒng)監(jiān)控軟件是不會收集服務器有多少條內存條這樣的信息的。4. 如果想往所有服務器上放一個文件,怎么辦?5. 想在所有服務器上啟動一個服務或執(zhí)行一個腳本怎么辦?大家在讀下文時如有不理解的地方或其它問題,可以隨時聯系我,大家互相交流,共同成長,我的qq:317828332#做Linux系統(tǒng)管理以來,由于
2、維護過比較大的網絡,例如在飛信做支持的時候,面對上千臺的服務器,有時候可能要對每臺機子打一個補丁,或者是修改一個文件,如果只有10臺服務器,那一一修改也就罷了,但是如果讓你一臺一臺的登錄1000臺服務器只是為了去改一個文件,那一定痛苦死,并且效率低下,沒有任何技術含量,如果一直做這種工作,那被稱為IT民工也不能怪別人了,因為我一直想找一個可以批量管理的工具,后來發(fā)現了兩種方式可以實現:1.通過SSH密鑰認證,這樣登錄到遠程機器上后就不需要輸入密碼了,這樣就可以通過腳本去批量登錄到遠程服務器并且修改你想要文件或操作等,但是這有一個缺點,就是這個在管理端的私鑰你一定要保存好,萬一管理服務器系統(tǒng)重裝
3、或其它原因導致私鑰丟失,那你就沒辦法登錄遠程機器了。還有,如果需要管理的機器更改了IP,那你還得重新把公鑰COPY到那臺機子上,這樣管理起來可能不是那么靈活。2.通過expect 工具進行批量管理,expect工具很強大,可以實現交互式管理,比如如果你想改密碼,輸入passwd命令后,系統(tǒng)會提示你輸入New Password: ,如果使用普通腳本的話,那你是沒辦法進行交互式的。但是expect就可以做到檢測系統(tǒng)的返回值并且根據返回的提示來自動交互,如下例:#!/usr/bin/expect -fset ipaddress lindex $argv 0 #設置命令行參數set passwd li
4、ndex $argv 1 #參數1 為passwordset ipaddress lindex $argv 0 #參數 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這臺機子的root密碼,如果你的一百臺機子都是一樣的密碼,你就可以寫個簡單的
6、批量腳本來登錄所有的機子并停止一個程序,如下:#!/bin/bashfor i in $(seq 100 200);doIP = "192.168.193.$i"expect ha-switch.exp $IP '123DDFD'done這樣此腳本就會調用ha-switch.exp腳本并登錄到192.168.193.100-200的機器上分別執(zhí)行"/etc/init.d/heartbeat stop 命令了。很強大吧,但使通過我使用的經驗,我覺得expect 有個缺點就是有慢,因為它是一臺一臺的去登錄 然后執(zhí)行命令,因為有的時
7、候由于DNS解析或什么原因 ,通過SSH登錄到一臺機子時可能需要等待30s才能登錄進去,假如1000臺機子的話那就需要50分鐘才能完成在所有機器上的操作,對于要求在1分鐘內實現數千臺機器執(zhí)行相同操作的需要來講這顯然達不到要求。以上兩種方法各有利弊,我個人建議在50-100臺的小網絡中可以考慮使用SSH認證或expect的方法。但是想像一下,如果我有一萬臺機器 ,分別處于全國各地不同的網絡中,要求我在1分鐘內更改所有機器的root密碼,顯然以上兩種方法均是做不到的,當然有這樣大型網絡的公司中國也并不多見,但是從技術的角度上來講這還是有一定挑戰(zhàn)性的,由于在網上一直找不到這樣的工具,我就自己索性寫了
8、一個,經過多天的努力,終于將這個批量管理工具寫完了,此工具是用的Python寫的,基于socket server的模式,即需要在所有的需要管理的服務器上啟動一個客戶端(可能好多朋友不太喜歡這種還需要裝客戶端的東東),客戶端會開啟一個端口,你的管理服務器就是通過此端口與被管理端通信,然后對被管理端進行操作,你可以遠程修改密碼,查看系統(tǒng)信息,內存情況等操作,操作結果會在你的管理端實現顯示出來(這也是我比較喜歡的地方,就跟在本地操作命令一樣)。并且還可以向遠程服務器批量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 #列出所有服務器列表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 #掃描所有服務器列表上的客戶端的狀態(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 #登錄到某臺機器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 #顯示的結果#Please input the command:ls #輸入的命令Received log from /root/Remote_management_tool/192.168.193.135
28、.log# #顯示的結果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 #上傳服務器列表 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;#同時在多臺遠程服務器上執(zhí)行命令并返回結果 It might will takes a few minutes to scan all the avialiable servers.The fllowing servers are avaliable: #可以進行遠程操作的列表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 #每臺設備返回的結果#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 #每臺設備返回的結果#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 #每臺設備返回的結果 1900000DesktopDocumentsRMT_client.pyRemote_management_toolautoinst.xmlbinnohup.outntp-clientscriptvmware#Received log from /root/Remote_management_tool/192.168.193.137.log #每臺設備返回的結果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 #每臺設備返回的結果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 #批量更改多臺服務器密碼 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 #批量往多臺服務器上拷文件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 #批量部署客戶端到多臺服務器上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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度交通樞紐車位劃線與無障礙設施施工合同4篇
- 2025版土地租賃合同模板(中英文對照)
- 二零二五年度建筑幕墻設計與施工一體化勞務分包合同樣本4篇
- 2025年度環(huán)保設施升級改造與運維合同4篇
- 2025-2030年中國紅色旅游行業(yè)市場現狀調查及未來趨勢研判報告
- 2025年度模具制造與產品研發(fā)一體化服務合同4篇
- 2025版航空航天器維修保養(yǎng)合同4篇
- 2025年科創(chuàng)大數據項目評價分析報告
- 2025年金屬架用拋光布輪項目投資可行性研究分析報告
- 2020-2025年中國手繪行業(yè)發(fā)展前景預測及投資戰(zhàn)略研究報告
- 南通市2025屆高三第一次調研測試(一模)地理試卷(含答案 )
- 2025年上海市閔行區(qū)中考數學一模試卷
- 2025中國人民保險集團校園招聘高頻重點提升(共500題)附帶答案詳解
- 勞務派遣招標文件范本
- 信息安全意識培訓課件
- Python試題庫(附參考答案)
- 碳排放管理員 (碳排放核查員) 理論知識考核要素細目表三級
- 2024年河北省中考數學試題(含答案解析)
- 小學二年級數學口算練習題1000道
- 納布啡在產科及分娩鎮(zhèn)痛的應用
- DZ/T 0462.4-2023 礦產資源“三率”指標要求 第4部分:銅等12種有色金屬礦產(正式版)
評論
0/150
提交評論