7-28 32 views
背景说明
工作中经常会遇到一次上几十台、几百台服务器的情况
每当到这个时候小伙伴们拿台笔记本和一根网线,一台服务器、一台服务器的去修改idrac IP
为了节约这个工作量,利用dell的racadm工具,写了下面这个脚本。只要运行起这个脚本,后面要做的就只是插拔网线的工作
安装racadm工具包
1 2 |
[root@localhost ~]# curl -s http://linux.dell.com/repo/hardware/dsu/bootstrap.cgi | bash [root@localhost ~]# yum -y install srvadmin-all |
准备工作
CSV文件
在采购时dell会提供一份服务器的sn列表,会根据这个列表规划好每台服务器的idrac IP,我们可以将此转换成以逗号分隔的CSV文件如下:
1 2 3 |
[root@localhost ~]# cat idrac_ip_list AAAAAAA,10.10.10.2,255.255.255.0,10.10.10.1 BBBBBBB,10.10.10.3,255.255.255.0,10.10.10.1 |
脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
[root@localhost ~]# cat set_idrac_ip.sh #!/usr/bin/env bash # @Author : Eric Winn # @Email : eng.eric.winn@gmail.com # @Time : 2018-07-27 14:47 # @Version : 1.0 # @File : set_idrac_ip # @Software : PyCharm # the file of idrac idrac_ip_list_file=${1} if [ ! -f "${idrac_ip_list_file}" ]; then echo "idrac_ip_list_file is not found!!!!" echo "$0 [idrac_ip_list_file]" exit 127 fi # idrac Default infomation idrac_default_ip=${2:-192.168.0.120} idrac_default_user=${3:-root} idrac_default_pass=${4:-calvin} # racadm bin racadm_bin=/opt/dell/srvadmin/sbin/racadm # install check srvadmin_install="curl -s http://linux.dell.com/repo/hardware/dsu/bootstrap.cgi | bash\nyum -y install srvadmin-all" test ! `ls ${racadm_bin} 2> /dev/null` && printf "Please run these commands as root to install racadm.\n\e[1;31m${srvadmin_install}\e[0m\n" && exit 1 RACADM="${racadm_bin} -r $idrac_default_ip -u $idrac_default_user -p $idrac_default_pass" # idrac history idrac_sn_history=() # idrac set set_idrac_ip(){ # get SN sn=`${RACADM} get BIOS.SysInformation.SystemServiceTag |grep SystemServiceTag |awk -F '=' '{print $2}'` if [ "${sn}s" == "s" ]; then echo "Get idrac sn is field!" return 1 fi # We only need the first 7 characters sn=${sn:0:7} echo "sn ======> ${sn}" for h_sn in ${idrac_sn_history[*]} do if [ "$h_sn" == "${sn}" ]; then echo "The ${sn} is already set." return 0 fi done # get new idrac_net from idrac_ip_list_file new_idrac_net=(`grep ${sn} $idrac_ip_list_file|awk -F ',' '{print $2,$3,$4}'`) if [ "${new_idrac_net}s" == "s" ]; then echo "The ${sn} is not in the ${idrac_ip_list_file}" return 1 fi echo "Setting the new ip: ${new_idrac_net[*]}" # set idrac ip ${RACADM} setniccfg -s ${new_idrac_net[*]} | grep successfully if [ $? -eq 0 ]; then idrac_sn_history=(${idrac_sn_history[*]} ${sn}) return 0 else echo "Set is field!" return 1 fi } # check internet check_internet() { pings="" echo -e "Connecting ...\c" while [ "${pings}s" == "s" ] do pings=`ping -c 2 $idrac_default_ip |awk 'NR==6 {print $4}'` if [ "${pings}s" == "s" ]; then echo -e ".\c" else echo fi done return 0 } # main function main() { while true do check_internet if [ $? -eq 0 ]; then echo "Let's starting set" set_idrac_ip if [ $? -eq 0 ]; then echo echo "Now , Please change to a new server" sleep 5 else echo echo "Please check it." sleep 15 fi fi done } main |
运行
注:后面的idrac_ip是csv文件名
1 2 3 4 5 6 7 8 |
[root@localhost ~]# sh set_idrac_ip.sh idrac_ip Connecting ... Let's starting set sn ======> AAAAAAA Setting the new ip: 10.10.10.2 255.255.255.0 10.10.10.1 Static IP configuration enabled and modified successfully Now , Please change to a new server |
如果想赏钱,可以用微信扫描下面的二维码,一来能刺激我写博客的欲望,二来好维护云主机的费用; 另外再次标注博客原地址 itnotebooks.com 感谢!
我看不懂脚本,请问服务器原来的iDRAC有IP地址吗???你这个脚本是跑在服务器的操作系统下面的?还是笔记本的操作系统下,然后用笔记本一台台的接iDRAC的接口?
Dell 服务器管理口默认的地址是192.168.0.120,可以在笔记本上安装个CentOS的虚拟机网卡桥接,然后运行这个脚本,根据提示一台台的接到服务器的IDRAC口上就行了