Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7173387
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类:

2012-08-07 01:05:11

原文地址:xen下创建多个网桥 作者:qingheliu

留为笔记!
1. Configure another network interface using either the system-config-network application.
Alternatively, create a new configuration file named ifcfg-ethX in the /etc/sysconfig/
network-scripts/ directory where X is any number not already in use. Below is an example
configuration file for a second network interface called eth1

  1. [root@ungeoxliu network-scripts]# cat ifcfg-eth1
  2. # Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
  3. DEVICE=eth1
  4. BOOTPROTO=static
  5. IPADDR=10.4.3.2
  6. ONBOOT=yes
  7. HWADDR=00:0c:29:6d:74:93
2:Copy the file, /etc/xen/scripts/network-bridge, to /etc/xen/scripts/network-bridge.
xen.
3:Comment out any existing network scripts in /etc/xen/xend-config.sxp and add the line
(network-xen-multi-bridge). A typical xend-config.sxp file should have the following
line. Comment this line out. Use the # symbol to comment out lines.network-script network-bridge
实质就是:将(network-script network-bridge)修改为(network-script network-xen-multi-bridge)
4:Create a script to create multiple network bridges. This example creates a script called network-xen-multi-bridge.sh in the /etc/xen/scripts/ directory. A sample scripts is below, this example script will create two Xen network bridges (xenbr0 and xenbr1) one will be attached to eth1 and the other one to eth0. If you want to create additional bridges just follow the example in the script and copy nad paste the lines as required:

  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
这个尤其注意,不能命名为network-xen-multi-bridge.sh ,应该命名为network-xen-multi-bridge, 否则无论是重启xend服务或重启系统,ifconfig都不能显示xenbr0和xenbr1 网桥!这里占用了很长的时间, 不知道为什么rhel的官方文档有问题!
5. Make the script executable.
# chmod +x /etc/xen/scripts/network-xen-multi-bridge
6:重启xend或系统
  #service xend restart
7:重启xend服务或系统后显示如下:

  1. [root@ungeoxliu xen]# ifconfig
  2. eth0 Link encap:Ethernet HWaddr 00:0C:29:6D:74:89
  3. inet addr:192.168.1.106 Bcast:192.168.1.255 Mask:255.255.255.0
  4. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  5. RX packets:4009 errors:0 dropped:0 overruns:0 frame:0
  6. TX packets:644 errors:0 dropped:0 overruns:0 carrier:0
  7. collisions:0 txqueuelen:0
  8. RX bytes:1120519 (1.0 MiB) TX bytes:92293 (90.1 KiB)
  9. eth1 Link encap:Ethernet HWaddr 00:0C:29:6D:74:93
  10. inet addr:10.4.3.2 Bcast:10.255.255.255 Mask:255.0.0.0
  11. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  12. RX packets:4411 errors:0 dropped:0 overruns:0 frame:0
  13. TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
  14. collisions:0 txqueuelen:0
  15. RX bytes:1162498 (1.1 MiB) TX bytes:546 (546.0 b)
  16. lo Link encap:Local Loopback
  17. inet addr:127.0.0.1 Mask:255.0.0.0
  18. UP LOOPBACK RUNNING MTU:16436 Metric:1
  19. RX packets:7 errors:0 dropped:0 overruns:0 frame:0
  20. TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
  21. collisions:0 txqueuelen:0
  22. RX bytes:688 (688.0 b) TX bytes:688 (688.0 b)
  23. peth0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
  24. UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
  25. RX packets:54955 errors:0 dropped:0 overruns:0 frame:0
  26. TX packets:1092 errors:0 dropped:0 overruns:0 carrier:0
  27. collisions:0 txqueuelen:1000
  28. RX bytes:22623947 (21.5 MiB) TX bytes:148877 (145.3 KiB)
  29. peth1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
  30. UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
  31. RX packets:55446 errors:0 dropped:0 overruns:0 frame:0
  32. TX packets:23 errors:0 dropped:0 overruns:0 carrier:0
  33. collisions:0 txqueuelen:1000
  34. RX bytes:22705798 (21.6 MiB) TX bytes:966 (966.0 b)
  35. vif0.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
  36. UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
  37. RX packets:682 errors:0 dropped:0 overruns:0 frame:0
  38. TX packets:4010 errors:0 dropped:0 overruns:0 carrier:0
  39. collisions:0 txqueuelen:0
  40. RX bytes:97881 (95.5 KiB) TX bytes:1120579 (1.0 MiB)
  41. vif0.1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
  42. UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
  43. RX packets:13 errors:0 dropped:0 overruns:0 frame:0
  44. TX packets:4430 errors:0 dropped:0 overruns:0 carrier:0
  45. collisions:0 txqueuelen:0
  46. RX bytes:546 (546.0 b) TX bytes:1163638 (1.1 MiB)
  47. xenbr0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
  48. UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
  49. RX packets:3911 errors:0 dropped:0 overruns:0 frame:0
  50. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  51. collisions:0 txqueuelen:0
  52. RX bytes:1056282 (1.0 MiB) TX bytes:0 (0.0 b)
  53. xenbr1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
  54. UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
  55. RX packets:3912 errors:0 dropped:0 overruns:0 frame:0
  56. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  57. collisions:0 txqueuelen:0
  58. RX bytes:1056346 (1.0 MiB) TX bytes:0 (0.0 b)
  59. [root@ungeoxliu xen]#
查看网卡绑定到那个网桥上:
[root@ungeoxliu xen]# brctl  show
bridge name     bridge id               STP enabled     interfaces
xenbr0          8000.feffffffffff       no              vif0.0
                                                        peth0
xenbr1          8000.feffffffffff       no              vif0.1
                                                        peth1
[root@ungeoxliu xen]# 

virt-clone  -o vm02 -n vm01  -f /data/vm01.img ##用此命令clone几个虚拟机!
我在物理机器上安装了vm01---vm06六个虚拟机,现在准备外网接到xenbr0上,内网都接到xenbr1上!
[root@host012 ~]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     1509    16 r-----   5127.5
vm01                                      36     2048     2 -b----     77.3
vm02                                      37     2048     2 -b----     77.9
vm03                                      38     2048     2 -b----     78.0
vm04                                      39     2048     2 -b----     77.5
vm05                                      40     2048     2 -b----     78.6
vm06                                      41     2048     2 -b----     76.8
[root@host012 ~]# cd /etc/xen/
[root@host012 xen]# cat vm01
name = "vm01"
uuid = "d717ba45-8487-8e57-1cbc-0458a5cfb6cb"
maxmem = 2048
memory = 2048
vcpus = 2
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
disk = [ "tap:aio:/data/vm01.img,xvda,w" ]
vif = [ "mac=00:16:3e:33:fd:2e,bridge=xenbr0,script=vif-bridge","mac=00:16:3e:33:fd:2f,bridge=xenbr1,script=vif-bridge" ] ##红色字体为我添加的一快网卡
[root@host012 xen]# cat vm01_bak  ##未添加网卡前的配置文件
name = "vm01"
uuid = "d717ba45-8487-8e57-1cbc-0458a5cfb6cb"
maxmem = 2048
memory = 2048
vcpus = 2
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy"
on_reboot = "restart"
on_crash = "restart"
disk = [ "tap:aio:/data/vm01.img,xvda,w" ]
vif = [ "mac=00:16:3e:33:fd:2e,bridge=xenbr0,script=vif-bridge" ]


然后xm shutdown vm01 关闭虚拟机,再xm create vm01 开启虚拟机!
开机后ifconfig发现多出一块网卡eth1,但没有地址 ,到/etc/sysconfig/network-scripts/   下发现多出一个ifcfg-eth1 ,它默认是dhcp启动方式!修改为static方式。我的物理机上我eth1 内网地址为192.168.2.12,所以我修改如下:
[root@ungeomysql01 network-scripts]# cat ifcfg-eth1 
# Xen Virtual Ethernet
DEVICE=eth1
BOOTPROTO=static
#HWADDR=00:16:3E:4F:FE:39  ##注意这个可以注释掉 
IPADDR=192.168.2.101
NETMASK=255.255.255.0
ONBOOT=yes
在虚拟机上ping物理机器的内网地址如下:
[root@ungeomysql01 network-scripts]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:16:3E:33:FD:2F  
          inet addr:192.168.2.101  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:299439 errors:0 dropped:0 overruns:0 frame:0
          TX packets:25 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:32230933 (30.7 MiB)  TX bytes:3093 (3.0 KiB)

[root@ungeomysql01 network-scripts]# ping 192.168.2.12
PING 192.168.2.12 (192.168.2.12) 56(84) bytes of data.
64 bytes from 192.168.2.12: icmp_seq=1 ttl=64 time=0.275 ms
64 bytes from 192.168.2.12: icmp_seq=2 ttl=64 time=0.072 ms

--- 192.168.2.12 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.072/0.173/0.275/0.102 ms
[root@ungeomysql01 network-scripts]# 
 
在物理机上查看网络分布情况如下:

[root@host012 xen]# brctl show
bridge name     bridge id               STP enabled     interfaces
virbr0          8000.000000000000       yes
xenbr0          8000.feffffffffff       no              vif41.0
                                                        vif40.0
                                                        vif39.0
                                                        vif38.0
                                                        vif37.0
                                                        vif36.0
                                                        vif0.0
                                                        peth0
xenbr1          8000.feffffffffff       no              vif41.1
                                                        vif40.1
                                                        vif39.1
                                                        vif38.1
                                                        vif37.1
                                                        vif36.1
                                                        vif0.1
                                                        peth1
[root@host012 xen]# 

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