리눅스 본딩 스크립트.
centOS 5.6버전에서 테스트했고, 다른버전은 안해봤음.
#!/bin/bash clear user=`whoami` #--- check the user----------------- if [ "$user" != "root" ] ; then echo "You must run as root account!" exit 1 fi echo "==============================================================" echo "Choose bonding set in server [1] bonding [2] restore " echo "==============================================================" read type case $type in 1) echo -e "Server Teaming is now!\n\n\n\n" #---- Configure Setting -------------------------------------- echo -e "Set IP : \c" read ipAdd echo -e "Set Netmask: \c" read Netmask echo -e "Set Gateway : \c" read Gateway echo -e "Set bonding mode : \c" read mode echo "" echo "" #ipAdd=192.168.0.86 # IP setting #Netmask=255.255.255.0 # Subnet setting #Gateway=192.168.0.2 # Gateway setting
Inf_bond=bond0 # Bonding interface setting Inf_1=eth0 # slave first interface Inf_2=eth1 # slave second interface
#mode=1 # Bonding mode setting
cur_dir=`pwd` backdir=${cur_dir}/lan_config_backup # Backup Interface infomation [ -e ${backdir} ] && backdir=${backdir}.$$ mkdir ${backdir}
echo "--Configure set IP in server --" echo "Bonding IP : ${ipAdd}" echo "Bonding Gatway : ${Gateway}" echo "Bonding interface : ${Inf_bond}" echo "Slave interfaces : ${Inf_1} , ${Inf_2}" echo "Netmask : ${Netmask}" echo "Backup Dir : ${backdir}" echo "" echo "Continue press any key..." read #----Network infomation back up ---------------------------------------------- echo -n "Backup dir ${backdir}..." cp /etc/sysconfig/network-scripts/ifcfg-${Inf_1} ${backdir} cp /etc/sysconfig/network-scripts/ifcfg-${Inf_2} ${backdir} cp /etc/sysconfig/network ${backdir} cp /etc/modprobe.conf ${backdir} echo "done" #-------------------------------------------------------------
#---- create file ------------------------------------------------ echo -n "Make bonding file..." # ifcfg-bond echo "DEVICE=bond0" > /etc/sysconfig/network-scripts/ifcfg-${Inf_bond} echo "BOOTPROTO=static" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_bond} echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_bond} echo "NETMASK=$Netmask" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_bond} echo "IPADDR=$ipAdd" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_bond} echo "USERCTL=no" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_bond} echo "GATEWAY=$Gateway" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_bond}
# ifcfg-eth0 orgstring1=`head -1 /etc/sysconfig/network-scripts/ifcfg-${Inf_1}` hwaddr1=`grep -i hwaddr /etc/sysconfig/network-scripts/ifcfg-${Inf_1}` echo "${orgstring1}" > /etc/sysconfig/network-scripts/ifcfg-${Inf_1} echo "DEVICE=${Inf_1}" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_1} echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_1} echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_1} echo "MASTER=bond0" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_1} echo "SLAVE=yes" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_1} echo "USERCTL=no" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_1} echo "#${hwaddr1}" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_1} # ifcfg-eth1 orgstring2=`head -1 /etc/sysconfig/network-scripts/ifcfg-${Inf_2}` hwaddr2=`grep -i hwaddr /etc/sysconfig/network-scripts/ifcfg-${Inf_2}` echo "${orgstring2}" > /etc/sysconfig/network-scripts/ifcfg-${Inf_2} echo "DEVICE=${Inf_2}" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_2} echo "BOOTPROTO=none" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_2} echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_2} echo "MASTER=bond0" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_2} echo "SLAVE=yes" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_2} echo "USERCTL=no" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_2} echo "#${hwaddr2}" >> /etc/sysconfig/network-scripts/ifcfg-${Inf_2} echo "done"
echo -n "Adding file..." #---- Adding network for gateway ------ [ "`grep -i ${Inf_bond} /etc/sysconfig/network`" == "" ] && echo "GATEDEV=${Inf_bond}" >> /etc/sysconfig/network
#---- Adding modprobe.conf ------ [ "`cat /etc/modprobe.conf | grep -v "^#" | grep -i ${Inf_bond}`" == "" ] && \ { echo "alias ${Inf_bond} bonding" >> /etc/modprobe.conf ; echo "options bonding mode=${mode} miimon=100" >> /etc/modprobe.conf ; #echo "options bonding mode=${mode} miimon=100 primary=eth0 max_bonds=1" >> /etc/modprobe.conf; } echo "done" #-----Service restart------------ echo "" echo -e "Try to network restart..." service network restart echo "done" #--- end -------------------------------------------------------- rm -rf ${cur_dir}/bonding_config_backup exit 1 ;; 2) Inf_bond=bond0 # Bonding interface setting Inf_1=eth0 # slave first interface Inf_2=eth1 cur_dir=`pwd` fname=$cur_dir/lan_config_backup if [ -e $fname ] then echo "Continue press any key..." read else echo " not dir" exit 0 fi backdir=${cur_dir}/bonding_config_backup # Backup Interface infomation [ -e ${backdir} ] && backdir=${backdir}.$$ mkdir ${backdir} echo -n "Backup dir ${backdir}..." mv /etc/sysconfig/network-scripts/ifcfg-${Inf_bond} ${backdir} mv /etc/sysconfig/network-scripts/ifcfg-${Inf_1} ${backdir} mv /etc/sysconfig/network-scripts/ifcfg-${Inf_2} ${backdir} mv /etc/sysconfig/network ${backdir} mv /etc/modprobe.conf ${backdir} echo "done" cp ${cur_dir}/lan_config_backup/ifcfg-${Inf_1} /etc/sysconfig/network-scripts/ifcfg-${Inf_1} cp ${cur_dir}/lan_config_backup/ifcfg-${Inf_2} /etc/sysconfig/network-scripts/ifcfg-${Inf_2} cp ${cur_dir}/lan_config_backup/network /etc/sysconfig/network cp ${cur_dir}/lan_config_backup/modprobe.conf /etc/modprobe.conf rmmod bonding service network restart rm -rf ${cur_dir}/lan_config_backup hostname localhost exit 1 ;; *) echo "No read type !! " exit 1 ;; esac exit 0
|
'IT > 리눅스' 카테고리의 다른 글
ecc 알고리즘 만들기 (0) | 2016.12.14 |
---|---|
필수 rpm 패키지 설치 스크립트 만들기 (1) | 2015.01.05 |