留为笔记!
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
- [root@ungeoxliu network-scripts]# cat ifcfg-eth1
- # Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
- DEVICE=eth1
- BOOTPROTO=static
- IPADDR=10.4.3.2
- ONBOOT=yes
- 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:
- #!/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.xen
- 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
这个尤其注意,不能命名为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服务或系统后显示如下:
- [root@ungeoxliu xen]# ifconfig
- eth0 Link encap:Ethernet HWaddr 00:0C:29:6D:74:89
- inet addr:192.168.1.106 Bcast:192.168.1.255 Mask:255.255.255.0
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:4009 errors:0 dropped:0 overruns:0 frame:0
- TX packets:644 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:1120519 (1.0 MiB) TX bytes:92293 (90.1 KiB)
- eth1 Link encap:Ethernet HWaddr 00:0C:29:6D:74:93
- inet addr:10.4.3.2 Bcast:10.255.255.255 Mask:255.0.0.0
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:4411 errors:0 dropped:0 overruns:0 frame:0
- TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:1162498 (1.1 MiB) TX bytes:546 (546.0 b)
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- UP LOOPBACK RUNNING MTU:16436 Metric:1
- RX packets:7 errors:0 dropped:0 overruns:0 frame:0
- TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:688 (688.0 b) TX bytes:688 (688.0 b)
- peth0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
- UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
- RX packets:54955 errors:0 dropped:0 overruns:0 frame:0
- TX packets:1092 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:22623947 (21.5 MiB) TX bytes:148877 (145.3 KiB)
- peth1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
- UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
- RX packets:55446 errors:0 dropped:0 overruns:0 frame:0
- TX packets:23 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:22705798 (21.6 MiB) TX bytes:966 (966.0 b)
- vif0.0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
- UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
- RX packets:682 errors:0 dropped:0 overruns:0 frame:0
- TX packets:4010 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:97881 (95.5 KiB) TX bytes:1120579 (1.0 MiB)
- vif0.1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
- UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
- RX packets:13 errors:0 dropped:0 overruns:0 frame:0
- TX packets:4430 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:546 (546.0 b) TX bytes:1163638 (1.1 MiB)
- xenbr0 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
- UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
- RX packets:3911 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:1056282 (1.0 MiB) TX bytes:0 (0.0 b)
- xenbr1 Link encap:Ethernet HWaddr FE:FF:FF:FF:FF:FF
- UP BROADCAST RUNNING NOARP MTU:1500 Metric:1
- RX packets:3912 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:1056346 (1.0 MiB) TX bytes:0 (0.0 b)
- [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) |