Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17084
  • 博文数量: 5
  • 博客积分: 125
  • 博客等级: 入伍新兵
  • 技术积分: 60
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-03 23:00
文章分类
文章存档

2012年(5)

我的朋友

分类: 虚拟化

2012-06-03 23:13:05

摘要:先简单的介绍一下Xen环境下bridge的创建过程,然后给出多网卡创建bridge的方法以及监控流量的脚本。


一. Xen单网卡网桥创建的过程:
1. the script creates a new bridge named xenbr0
2. "real" ethernet interface eth0 is brought down
3. the IP and MAC addresses of eth0 are copied to virtual network interface veth0
4. real interface eth0 is renamed peth0
5. virtual interface veth0 is renamed eth0
6. peth0 and vif0.0 are attached to bridge xenbr0 as bridge ports
7. the bridge, peth0, eth0 and vif0.0 are brought up


二. 多网卡创建bridge
如果是双网卡则需要添加网卡创建的脚本,使得上面的步骤能够同时进行,添加的过程如下:
修改/etc/xen/xend-config-sxp
修改成如下内容:
#(network-script network-bridge)
(network-script network-xen-multi-bridge)
在/etc/xen/scripts
执行:
mv network-bridge network-bridge.xen
vi network-xen-multi-bridge
内容如下:

点击(此处)折叠或打开

  1. #!/bin/sh
  2. # network-xen-multi-bridge
  3. # Exit if anything goes wrong.
  4. set -e
  5. # First arg is the operation.
  6. OP=$1
  7. shift
  8. script=/etc/xen/scripts/network-bridge.xen
  9. case ${OP} in
  10. start)
  11. $script start vifnum=1 bridge=xenbr1 netdev=eth1
  12. $script start vifnum=0 bridge=xenbr0 netdev=eth0
  13. ;;
  14. stop)
  15. $script stop vifnum=1 bridge=xenbr1 netdev=eth1
  16. $script stop vifnum=0 bridge=xenbr0 netdev=eth0
  17. ;;
  18. status)
  19. $script status vifnum=1 bridge=xenbr1 netdev=eth1
  20. $script status vifnum=0 bridge=xenbr0 netdev=eth0
  21. ;;
  22. *)
  23. echo 'Unknown command: ' ${OP}
  24. echo 'Valid commands are: start, stop, status'
  25. exit 1
  26. esac


最后执行:
chmod 755 network-xen-multi-bridge
重启xend或者服务器
重启xend
/etc/init.d/xend restart
至此网桥创建完毕。


三. 网络监控
监控VPS物理主机总的流量,主要是监控peth0和peth1

点击(此处)折叠或打开

  1. #!/usr/bin/env python

  2. from __future__ import division
  3. import os
  4. import sys
  5. import time
  6. import string

  7. def getnetdev(netstreamlist):
  8.     fnetdev = open('/proc/net/dev', 'r')
  9.     netdevfile = fnetdev.readlines()
  10.     fnetdev.close()
  11.     for i in range(3, len(netdevfile)):
  12.         nidlist = []
  13.         if netdevfile[i].split()[8] != '0':
  14.             nidlist.append(netdevfile[i].split()[0])
  15.             nidlist.append(netdevfile[i].split()[8])
  16.     netstreamlist.append(nidlist)

  17. def calculate_bandwidth(timesetting):
  18.     netstreamlist1 = []
  19.     netstreamlist2 = []
  20.     getnetdev(netstreamlist1)
  21.     print ""
  22.     print ""
  23.     print "The average speed in %d :" % timesetting
  24.     time.sleep(timesetting)
  25.     getnetdev(netstreamlist2)
  26.     for i in range(len(netstreamlist1)):
  27.        name = netstreamlist1[i][0].split(":", 1)[0]
  28.        revdata1 = string.atoi(netstreamlist1[i][0].split(":", 1)[1])
  29.        revdata2 = string.atoi(netstreamlist2[i][0].split(":", 1)[1])
  30.        trxdata1 = string.atoi(netstreamlist1[i][1])
  31.        trxdata2 = string.atoi(netstreamlist2[i][1])
  32.        revspeed = (((revdata2 - revdata1))/timesetting)/1024
  33.        trxspeed = (((trxdata2 - trxdata1))/timesetting)/1024
  34.        print "The %s rev speed is %d Kb/s, trx speed is %d Kb/s" % (name, revspeed, trxspeed)

  35. def main():
  36.     if (len(sys.argv) < 2):
  37.         print "Please enter the time "
  38.         sys.exit()
  39.     while 1:
  40.         calculate_bandwidth(string.atoi(sys.argv[1]))

  41. if __name__ == '__main__':
  42.     main()


四. 参考资源:
阅读(826) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:openstack中NoVNC的配置

给主人留下些什么吧!~~