收藏 分销(赏)

Llinux-系统批量管理工具介绍-实现对一万台服务器的同时批量管理-一键完成.doc

上传人:天**** 文档编号:3712091 上传时间:2024-07-15 格式:DOC 页数:15 大小:472.50KB 下载积分:8 金币
下载 相关 举报
Llinux-系统批量管理工具介绍-实现对一万台服务器的同时批量管理-一键完成.doc_第1页
第1页 / 共15页
Llinux-系统批量管理工具介绍-实现对一万台服务器的同时批量管理-一键完成.doc_第2页
第2页 / 共15页


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

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服