2014年新的一年春天来了,又是一年春来到,×××三月好风光,好久没发表文章了,今天在这里记录一下KVM网卡绑定安装脚本,供大家参考。

一、实施环境:

硬件设备:H3C S5500三层交换机+DELLR720服务器

虚拟化软件:KVM虚拟化

二、脚本内容:

脚本基于服务器四块网卡绑定,网卡流量聚合叠加,总和为4G,模拟测试任意down掉一块网卡、两块网卡对物理机上的虚拟机集群没有任何影响。直接上脚本如下:

#!/bin/sh
#Auto Make KVM Virtualization
#Author wugk 2013-12-06 bond0+br0
#Auto config bond scripts
eth_bond()
{
NETWORK=(
  HWADDR=`ifconfig eth0 |egrep "HWaddr|Bcast" |tr "\n" " "|awk '{print $5,$7,$NF}'|sed -e 's/addr://g' -e 's/Mask://g'|awk '{print $1}'`
  IPADDR=`ifconfig eth0 |egrep "HWaddr|Bcast" |tr "\n" " "|awk '{print $5,$7,$NF}'|sed -e 's/addr://g' -e 's/Mask://g'|awk '{print $2}'`
  NETMASK=`ifconfig eth0 |egrep "HWaddr|Bcast" |tr "\n" " "|awk '{print $5,$7,$NF}'|sed -e 's/addr://g' -e 's/Mask://g'|awk '{print $3}'`
  GATEWAY=`route -n|grep "UG"|awk '{print $2}'`
)
DIR=/etc/sysconfig/network-scripts/
BAK=/data/backup/`date +%Y%m%d`
if
[ ! -d $BAK ];then
mkdir -p $BAK
cp $DIR/ifcfg-eth* $BAK
else
cp $DIR/ifcfg-eth* $BAK
fi
cat >ifcfg-bond0<>/dev/null
if
  [ "$?" -eq "0" ];then
  echo 'Congratulations, your system success supports virtualization !'
else
  echo -e 'OH,your system does not support virtualization !\nPlease modify the BIOS virtualization options (Virtualization Technology)'
  exit 0
fi
  if
    [ -e /usr/bin/virsh ];then
  echo "Virtualization is already installed ,Please exit ...." ;exit 0
  fi
  yum -y install ${KVM_SOFT[@]}
  /sbin/modprobe kvm
  ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm
  lsmod | grep kvm >>/dev/null
  if
    [ "$?" -eq "0" ];then
    echo 'KVM installation is successful !'
else
    echo 'KVM installation is falis,Please check ......'
  exit 1
fi
cd /etc/sysconfig/network-scripts/
  mkdir -p /data/backup/`date +%Y%m%d-%H:%M`
  yes|cp ifcfg-eth* /data/backup/`date +%Y%m%d-%H:%M`/
if
  [ -e /etc/sysconfig/network-scripts/ifcfg-br0 ];then
  echo "The ifcfg-br0 already exist ,Please wait exit ......"
  exit 2
else
  cat >ifcfg-bond0 <ifcfg-br0 < 
  

三、网卡内容:

修改之后ifcfg-eth0配置内容如下,其他三块网卡依次修改为对应的网卡名称,内容跟eth0一致:

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
TYPE=Ethernet
NM_CONTROLLED=no

四、H3C S5500交换机配置:

服务器端聚合配置完毕后,还需要在交换机把相应的4个端口做网络聚合,命令如下:

system-view
interface Bridge-Aggregation 100
link-aggregation mode dynamic
quit
interface GigabitEthernet1/0/1
port link-aggregation group 100
quit
interface GigabitEthernet1/0/2
port link-aggregation group 100
quit
interface GigabitEthernet1/0/3
port link-aggregation group 100
quit
interface GigabitEthernet1/0/4
port link-aggregation group 100
quit

参考文章:

http://navyaijm.blog.51cto.com/4647068/1316910

http://wgkgood.blog.51cto.com/1192594/1337628