最新消息:

KVM 多网卡绑定(流量聚合)

kvm admin 3793浏览 0评论

随着虚拟化技术不断发展与普及,越来越多的企业搭建和使用自己的虚拟化平台,这里我发一个KVM 虚拟化自动安装脚本,里面包含多网卡自动聚合配置,网卡绑定模式为4(流量叠加),脚本如下:(当然才mode=4模式,还需要在交换机配置网卡绑定)

#!/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<<EOF
DEVICE=bond0
BOOTPROTO=static
${NETWORK[1]}
${NETWORK[2]}
${NETWORK[3]}
ONBOOT=yes
TYPE=Ethernet
NM_CONTROLLED=no
EOF
yes|cp ifcfg-bond0 ifcfg-eth0 ifcfg-eth1 ifcfg-eth2 ifcfg-eth3 $DIR
yes|cp modprobe.conf /etc/modprobe.d/
echo "The Server bond0 config success !!"
}
#Auto install kvm and config br0 scripts
kvm_install()
{
cat <<EOF
++++++++++++++++Welcome To Use Auto Install KVM Scripts ++++++++++++++++++
+++++++++++++++++++++++++This KVM Install Virtual ++++++++++++++++++++++++
+++++++++++++++++++++++++2013-12-06 Author wugk ++++++++++++++++++++++++++
EOF
KVM_SOFT=(
    kvm python-virtinst libvirt  bridge-utils virt-manager qemu-kvm-tools  virt-viewer  virt-v2v libguestfs-tools
)
NETWORK=(
    HWADDR=`ifconfig bond0 |egrep "HWaddr|Bcast" |tr "n" " "|awk '{print $5,$7,$NF}'|sed -e 's/addr://g' -e 's/Mask://g'|awk '{print $1}'`
    IPADDR=`ifconfig bond0 |egrep "HWaddr|Bcast" |tr "n" " "|awk '{print $5,$7,$NF}'|sed -e 's/addr://g' -e 's/Mask://g'|awk '{print $2}'`
    NETMASK=`ifconfig bond0 |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}'`
)
#Check whether the system supports virtualization
    egrep 'vmx|svm'  /proc/cpuinfo >>/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 <<EOF
    DEVICE=bond0
    BOOTPROTO=none
    #${NETWORK[0]}
    NM_CONTROLLED=no
    ONBOOT=yes
    TYPE=Ethernet
    BRIDGE="br0"
    ${NETWORK[1]}
    ${NETWORK[2]}
    ${NETWORK[3]}
    USERCTL=no
EOF
    cat >ifcfg-br0 <<EOF
    DEVICE="br0"
    BOOTPROTO=none
    #${NETWORK[0]}
    IPV6INIT=no
    NM_CONTROLLED=no
    ONBOOT=yes
    TYPE="Bridge"
    ${NETWORK[1]}
    ${NETWORK[2]}
    ${NETWORK[3]}
    USERCTL=no
EOF
fi
    echo 'Your can restart Ethernet Service: /etc/init.d/network restart !'
    echo '---------------------------------------------------------'
    sleep 1
    echo 'Your can restart KVM Service : /etc/init.d/libvirtd restart !'
    echo
    echo -e "You can create a KVM virtual machine: nvirt-install --name=centos01 --ram 512 --vcpus=1 --disk path=/data/kvm/centos01.img,size=7,bus=virtio --accelerate --cdrom /data/iso/centos58.iso --vnc --vncport=5910 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole"
}
case $1 in
    eth_bond )
    eth_bond
    ;;
    kvm_install )
    kvm_install
    ;;
    * )
    echo "Usage: { $0 eth_bond|kvm_install|help}"
esac
附: ifcfg-eth0内容:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
TYPE=Ethernet
NM_CONTROLLED=no
附: modprobe.conf内容:
alias bond0 bonding
options bond0 miimon=100 mode=4

H3C交换机端需要做的配置如下: 

system-view
interface Bridge-Aggregation 100
link-aggregation mode dynamic
quit
interface GigabitEthernet1/0/28
port link-aggregation group 100
quit
interface GigabitEthernet1/0/29
port link-aggregation group 100
quit
interface GigabitEthernet1/0/33
port link-aggregation group 100
quit
interface GigabitEthernet1/0/30
port link-aggregation group 100
quit

网卡绑定(服务器&&交换机)

转载请注明:爱开源 » KVM 多网卡绑定(流量聚合)

您必须 登录 才能发表评论!