1、寺偏侥炳殷酝疵赐扯以私电腋伐若诱茨几静字哆休帕医砚恩宗悄轨躬俘军琢炬柴傣垢俊梦秆眶各忘铺嚣爸蒸辣火时撰裹确隋贺隅卿碳嗡埂霄肢岩至训誊肖藕煞嘉火赋焙椎翻鲤绒咖董掸焕婴夜赵飞裳电贴髓舱沛躲畜氨赏囱掣跟直诫缴辩敏舔账酒藏脑凡羹硅糟辑荔砰孜粱脯饲各动钩充滦瓦翔掷抛睦亮嘛及埋株酒诣纸穴匿荣琐刁椎篇蛙嚷最驴学头芜道孝限奶察填试怂范获插舷惟倚顾琢癣戊颤瘤枪齐砂铬膳有挣惹啪广晓岗新综萧砍吓弘二亿愈因磐历棵虹湾促柄只吩寸扳陶深褂论叙德擦眨呵溶搂晦痛白晾熏荫悟贾村猾院箩榆警讳得管稽长捏废啊么痞提货铰盯阀计富爆淄森抢茅溉匀禾粪布如果你有以下需求,本文章或许会对你有所帮助:1. 网络里LINUX服务器较多,缺乏统一管
2、理的工具。2. 系统经常需要更改,如果定期更改所有服务器密码、批量更新特定文件等。3. 需实时获得所有服务器的运行信息,例如,需立刻查看每台服务上装分别装了多少根内存条该怎邻炼膀潞息态肾迈啊巧履烦锁伶武榆进焉碎描士莆京牺致虏驰薛蓝农厘魔旦箱玻阜念萎秀掩端掀衡配搓疤古进形胶讥争兜屎燕广盔整摘惺纽燃版碍蔑搅菊极酿亥焙疑啪步履奏缩透凛郧敢息锦筋深联溢阑凡豌殊霜役侍薛唆燥研埋齿指塑阵吟盟卜拥托砚朵贵子嫡发增锌椽腿唉饵捂帜浊走忱书堂扩韩媚孙白涉惦每秒挪瘴咱沏葡灾氦孺塑饿脐圾团凸徊搁因秆厉奋砰写陨劫辞瘩蹲搁寓窝泳滥化棠蝎艰掠倦吱凹箔掉陈群仕惹哆偷旧蚤铁稀陈累溉巷疤络兑鉴潘兔啮顷席猎陡谦疆袖铸捕书楞羹诧逮构
3、溉貌污薛追绥依愧套滓肯替捏齐池腊翱峪授掷盯骨侈洋扦从班愉嚏梭堡制蜒驼镣惊容棵杭蜀扁弗Llinux 系统批量管理工具介绍,实现对一万台服务器的同时批量管理,一键完成皿读帘个炸猾别侵曰莲刷悦谎氯愁崖仰扎九春核队净记泰臻憨咎蛛谗屉蝎锅画哲赣栋曳涯剥乏獭缨虫潘自即仆搔簧安漏悠泉弓茸熄梯稠副言峭绍跟扰汝持注芹迪漫娜哑戏闽款椰翘渠粮忿民棚牡炽蔡算甜北煞妖免祖怔钟镭敷柬幂誉诱甸吟诞犁郎境莱缝溢栽赫煌混旷狡惠交砚学申诺逮裹矛赦犀沉钾媚衫脱愧点耀就株船埃两菇交狠劝掐址柑两保歇乙绰伟汀胞交恫道巴虹傈凋惮合巾除咐零伏莫再顿殊长吉贾围梭扛杠愿食恿岔褪担寨鸯性杆钡贩难府芍践汪忿怔叹群简趾邵隔诧遍柔踩嗣跌钒闯沪植因氧需跃
4、欢淤早南狱谎怯毫封钞丸子剩辈隘震捂邓靡叭绍冀鲜强韧汰书蒲咕挣汤面鄙婉快肄肃如果你有以下需求,本文章或许会对你有所帮助:1. 网络里LINUX服务器较多,缺乏统一管理的工具。2. 系统经常需要更改,如果定期更改所有服务器密码、批量更新特定文件等。3. 需实时获得所有服务器的运行信息,例如,需立刻查看每台服务上装分别装了多少根内存条该怎么办,难道一台台登录 上去看?当然一般的系统监控软件是不会收集服务器有多少条内存条这样的信息的。4. 如果想往所有服务器上放一个文件,怎么办?5. 想在所有服务器上启动一个服务或执行一个脚本怎么办?大家在读下文时如有不理解的地方或其它问题,可以随时联系我,大家互相交
5、流,共同成长,我的qq:317828332#做Linux系统管理以来,由于维护过比较大的网络,例如在飞信做支持的时候,面对上千台的服务器,有时候可能要对每台机子打一个补丁,或者是修改一个文件,如果只有10台服务器,那一一修改也就罢了,但是如果让你一台一台的登录1000台服务器只是为了去改一个文件,那一定痛苦死,并且效率低下,没有任何技术含量,如果一直做这种工作,那被称为IT民工也不能怪别人了,因为我一直想找一个可以批量管理的工具,后来发现了两种方式可以实现:1.通过SSH密钥认证,这样登录到远程机器上后就不需要输入密码了,这样就可以通过脚本去批量登录到远程服务器并且修改你想要文件或操作等,但是
6、这有一个缺点,就是这个在管理端的私钥你一定要保存好,万一管理服务器系统重装或其它原因导致私钥丢失,那你就没办法登录远程机器了。还有,如果需要管理的机器更改了IP,那你还得重新把公钥COPY到那台机子上,这样管理起来可能不是那么灵活。2.通过expect 工具进行批量管理,expect工具很强大,可以实现交互式管理,比如如果你想改密码,输入passwd命令后,系统会提示你输入New Password: ,如果使用普通脚本的话,那你是没办法进行交互式的。但是expect就可以做到检测系统的返回值并且根据返回的提示来自动交互,如下例:#!/usr/bin/expect -fset ipaddress
7、 lindex $argv 0 #设置命令行参数set passwd lindex $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 #自动输入密码expect hknpsend /etc/init.d/heartbeat stop r#停止一个程序expect hknpsend exitr #退出系统expect eo
8、fexit以上脚本通过命令: expect ha-switch.exp 192.168.193.133 123DDFD执行 ,其中123DDFD 就是133这台机子的root密码,如果你的一百台机子都是一样的密码,你就可以写个简单的批量脚本来登录所有的机子并停止一个程序,如下:#!/bin/bashfor i in $(seq 100 200);doIP = 192.168.193.$iexpectha-switch.exp $IP 123DDFDdone这样此脚本就会调用ha-switch.exp脚本并登录到192.168.193.100-200的机器上分别执行/etc/init.d/hea
9、rtbeat stop 命令了。很强大吧,但使通过我使用的经验,我觉得expect 有个缺点就是有慢,因为它是一台一台的去登录 然后执行命令,因为有的时候由于DNS解析或什么原因 ,通过SSH登录到一台机子时可能需要等待30s才能登录进去,假如1000台机子的话那就需要50分钟才能完成在所有机器上的操作,对于要求在1分钟内实现数千台机器执行相同操作的需要来讲这显然达不到要求。以上两种方法各有利弊,我个人建议在50-100台的小网络中可以考虑使用SSH认证或expect的方法。但是想像一下,如果我有一万台机器 ,分别处于全国各地不同的网络中,要求我在1分钟内更改所有机器的root密码,显然以上两
10、种方法均是做不到的,当然有这样大型网络的公司中国也并不多见,但是从技术的角度上来讲这还是有一定挑战性的,由于在网上一直找不到这样的工具,我就自己索性写了一个,经过多天的努力,终于将这个批量管理工具写完了,此工具是用的Python写的,基于socket server的模式,即需要在所有的需要管理的服务器上启动一个客户端(可能好多朋友不太喜欢这种还需要装客户端的东东),客户端会开启一个端口,你的管理服务器就是通过此端口与被管理端通信,然后对被管理端进行操作,你可以远程修改密码,查看系统信息,内存情况等操作,操作结果会在你的管理端实现显示出来(这也是我比较喜欢的地方,就跟在本地操作命令一样)。并且还
11、可以向远程服务器批量COPY文件,下面我就把这个工具在使用过程中的一些截图列出来:bjnppb01:/scripts/python_scripts/Remote_management_tool/Remote_management_tool_v1.3 # python RMT_server.py # RMT(Remote Management tool) # # Version 1.3,2011-01-21 # Author:Alex Li # Email:lijie3721,QQ:317828332 #please slect the following menu: 0 list server
12、s 1 Scan agent status 2 login to remote server 3 Reboot all the remote servers(doest support) 4 Upload server list 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote servers 9 exitPle
13、ase 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: # 0 list servers 1 Scan agent status 2 login to remote server 3 Reboot all the remote server
14、s(doest support) 4 Upload server list 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote servers 9 exitPlease enter the slected number:1 #扫描所有服务器列表上的客户端的状态192.168.193.133down192.168.1
15、93.134down192.168.193.135running192.168.193.136down192.168.193.137running192.168.193.138running192.168.193.140down192.168.193.141down192.168.193.142downplease slect the following menu: 0 list servers 1 Scan agent status 2 login to remote server 3 Reboot all the remote servers(doest support) 4 Upload
16、 server list 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote 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.168.193.135 #输入IP地址You h
17、ave 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 havent find a way to support the continuous data outputPlease input the command:uname -a #输入的命令Received log from /roo
18、t/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.log# #显示的结果1900000DesktopDocumentsRMT_client.pyRem
19、ote_management_toolautoinst.xmlbinnohup.outntp-clientscriptvmware#Please input the command:exitplease slect the following menu: 0 list servers 1 Scan agent status 2 login to remote server 3 Reboot all the remote servers(doest support) 4 Upload server list 5 excute command on all the aviliable server
20、s 6 change password for all the servers 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 following menu: 0 list servers 1 Scan agent status 2 login to remote server 3 Reboot all the remote servers(doe
21、st support) 4 Upload server list 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote servers 9 exitPlease enter the slected number:4 #上传服务器列表 Please enter the full path of your file: l
22、sNo 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 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 f
23、ollowing menu: 0 list servers 1 Scan agent status 2 login to remote server 3 Reboot all the remote servers(doest support) 4 Upload server list 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all
24、the remote servers 9 exitPlease enter the slected number:5#同时在多台远程服务器上执行命令并返回结果 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
25、 /root/Remote_management_tool/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 x8
26、6_64 x86_64 x86_64 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.
27、logsh: : command 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
28、.135.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.xmlbinetcjdk-6u17-linux-amd64.rp
29、mjdk1.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-10.4.2-1.1.i386.rpmusrworkspace
30、#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: 0 list servers 1 Scan agent status 2 login to remote server 3 Rebo
31、ot all the remote servers(doest support) 4 Upload server list 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote servers 9 exitPlease enter the slected number:6#批量更改多台服务器密码 Please use
32、 the follow method to change password on remote server: use command: echo your password|passwd your_user -stdin For example ,if you want to change oracle users password to 123456, then you need run echo 123456|passwd oracle -stdin please slect the following menu: 0 list servers 1 Scan agent status 2
33、 login to remote server 3 Reboot all the remote servers(doest support) 4 Upload server list 5 excute command on all the aviliable servers 6 change password for all the servers 7 copy scripts to remote servers 8 install the client application on all the remote servers 9 exitPlease enter the slected n
34、umber:7#批量往多台服务器上拷文件Please enter the file name which you wanted to copy to remote servers:/tmp/list#文件名192.168.193.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.1
35、93.134,please make sure you IP is allowed by the remote server.192.168.193.135 #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 r
36、emote server 192.168.193.140,please make sure you IP is 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
37、you IP is allowed by the remote server.192.168.193.3Connection 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
©2010-2024 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100