Chinaunix首页 | 论坛 | 博客
  • 博客访问: 612557
  • 博文数量: 486
  • 博客积分: 10125
  • 博客等级: 上将
  • 技术积分: 5842
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-27 18:34
文章分类

全部博文(486)

文章存档

2011年(52)

2010年(107)

2009年(289)

2008年(38)

我的朋友

分类: LINUX

2010-04-26 00:40:48

http://hi.baidu.com/sunkitty1984/blog/item/2dd7df37b45613380a55a9a3.html


今天对xen双网卡桥接进行了配置与测试,总结以下方式最直接。

一、手动生成xen虚拟网桥

编写脚本my-briges.sh

#!/bin/sh
      # network-xen-multi-bridge
      # Exit if anything goes wrong.
      set -e
      # First arg is the operation.
      OP=$1
      shift
      script=/etc/xen/scripts/network-bridge

      case ${OP} in
      start)
      $script start vifnum=1 bridge=xenbr1 netdev=eth1
      $script start vifnum=0 bridge=xenbr0 netdev=eth0
      ;;
      stop)
      $script stop vifnum=1 bridge=xenbr1 netdev=eth1
      $script stop vifnum=0 bridge=xenbr0 netdev=eth0
      ;;
      status)
      $script status vifnum=1 bridge=xenbr1 netdev=eth1
      $script status vifnum=0 bridge=xenbr0 netdev=eth0
      ;;
      *)
      echo 'Unknown command: ' ${OP}
      echo 'Valid commands are: start, stop, status'
      exit 1
      esac

chmod u+x my-briges.sh

#my-briges.sh start 创建虚拟网桥

#my-briges.sh status 查看虚拟网桥等相关信息

#my-briges.sh stop 删除虚拟网桥

二、安装虚拟机

#xm list

Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0      449     1 r-----     65.7
mcz1                                       1      255     1 -b----      9.9
mcz2                                       3      255     1 -b----      9.1

三、配置虚拟机网桥设备接口

#cd /etc/xen

#vi mcz1

修改:vif = [ "mac=00:16:3e:0e:88:02,bridge=xenbr0" ]

#vi mcz2

修改:vif = [ "mac=00:16:3e:0e:88:02,bridge=xenbr1" ]

#brctl addif xenbr0 vif1.0

#brctl addif xenbr1 vif3.0

这样domain-u即可通过各自的网桥上网。

四、测试

编写脚本flow.sh:

#!/bin/bash

if [ $# -ne 3 ];then
   echo example: ntop eth0 1 10
   exit
fi

eth=$1
count=$3
interval=$2

infirst=$(cat /proc/net/dev |tr ':' ' '|awk '/'$eth'/{print $2}')
if [ -z "$infirst" ];then
    echo The network interface $eth is not exits!
    exit 1;
fi

outfirst=$(cat /proc/net/dev |tr ':' ' '|awk '/'$eth'/{print $10}')
echo "ifname" "in_bytes/s" "out_bytes/s" "total_bytes/s" |awk '{printf("%10s %16s %16s %16s\n",$1,$2,$3,$4)}'
sleep $interval"s"
i=0
while [ "$i" -lt "$count" ]
do
   inend=$(cat /proc/net/dev |tr ':' ' '|awk '/'$eth'/{print $2}')
   outend=$(cat /proc/net/dev |tr ':' ' '|awk '/'$eth'/{print $10}')
   sumin=$((($inend-$infirst)/$interval))
   sumout=$((($outend-$outfirst)/$interval))
   sum=$(($sumin+$sumout))

   echo $eth $sumin $sumout $sum |awk '{printf("%10s %16s %16s %16s\n",$1,$2,$3,$4)}'
   infirst=$inend
   outfirst=$outend
   i=$(($i+1))
   sleep $interval"s"
done

#chmod u+x flow.sh

#flow.sh peth1 1 3

    ifname       in_bytes/s      out_bytes/s    total_bytes/s
     peth1              509                0              509
     peth1              285                0              285
     peth1              256                0              256

在mcz2机器上运行ping

#flow.sh peth1 1 3

    ifname       in_bytes/s      out_bytes/s    total_bytes/s
     peth1              300               98              398
     peth1              240               98              338
     peth1              391               98              489

所以,从流量上可以看出,Xen双网卡桥接方法配置成功。


阅读(708) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~