xen 使用桥接网络创建新的虚拟机

xen 使用桥接网络创建新的虚拟机

我使用的是 CentOS 6.5 64

用这个教程设置 Bridge

[root@CentOS ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr0          8000.08002754b3fa       yes             eth0

使用命令创建一个新的虚拟机(CentOS)xm,一切正常

Xen 配置文件

kernel = "/var/lib/xen/images/vmlinuz"
ramdisk = "/var/lib/xen/images/initrd.img"
extra = "text ks=http://192.168.1.8/kickstart-minimal6-x86_64.cfg"
name = "xc63"
memory = "512"
disk = [ "file:/var/lib/xen/images/centos63.img,xvda,w","file:/var/lib/xen/images/centos63.swp,xvdb,w"]
vif = [ 'bridge=xenbr0' ]
vcpus = 1
on_reboot = "destroy"
on_crash = "destroy"

创建后

[root@CentOS ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
xenbr0          8000.08002754b3fa       yes             eth0
                                                        vif6.0

[root@CentOS ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:54:B3:FA
          inet6 addr: fe80::a00:27ff:fe54:b3fa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3884 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2832 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:310622 (303.3 KiB)  TX bytes:412047 (402.3 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 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:0 (0.0 b)  TX bytes:0 (0.0 b)

vif6.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF
          inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:928 (928.0 b)  TX bytes:2192 (2.1 KiB)

xenbr0    Link encap:Ethernet  HWaddr 08:00:27:54:B3:FA
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe54:b3fa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2935 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1403 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:188677 (184.2 KiB)  TX bytes:271882 (265.5 KiB)

xm 控制台 xc63

在此处输入图片描述 这意味着我的桥无法工作,因为虚拟机无法调用192.168.1.8

获取 MAC 地址xc63

[root@CentOS xen]# xl network-list xc63
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:21:f4:e1     0     4     10   768/769         /local/domain/0/backend/vif/3/0

并检查 DHCP 状态 在此处输入图片描述

xc63 获取 ip192.168.1.118

从同一主机运行

[root@CentOS xen]# ping 192.168.1.118
PING 192.168.1.118 (192.168.1.118) 56(84) bytes of data.
64 bytes from 192.168.1.118: icmp_seq=1 ttl=64 time=2.28 ms
64 bytes from 192.168.1.118: icmp_seq=2 ttl=64 time=0.907 ms
64 bytes from 192.168.1.118: icmp_seq=3 ttl=64 time=0.724 ms
64 bytes from 192.168.1.118: icmp_seq=4 ttl=64 time=0.809 ms
^C
--- 192.168.1.118 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3171ms
rtt min/avg/max/mdev = 0.724/1.181/2.284/0.640 ms

从本地网络上的任何设备Request timed out

C:\Users\motaz>ping 192.168.1.118

Pinging 192.168.1.118 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.1.118:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

任何人如果能给我一个解决这个问题的办法,我都会很感激。

答案1

首先,如果您使用 VirtualBox 来托管 XEN 服务器,请确保使用以太网而不是无线网络,并将混杂模式设置为“全部允许”。

其次,为了使一切都干净,让我们从使用 XEN 的 CentOS 的全新安装开始,并在其上安装 Bridge Network 和 CentOS VM。

假设您有一个外部服务器 192.168.1.6,其中 CentOS ISO 提取在 /var/www/html/centos/6.3/os/i386/ 上,kickstart 文件在 /var/www/html/centos/6.3/os/i386/ks.cfg 上,并且 /var/www/html/centos/6.3/os/i386/repodata 上的名称正确,与 repodata/TRANS.TBL 文件中的名称匹配

在 XEN 服务器(CentOS+XEN)上安装以下软件包:

yum install -y rsync wget vim-enhanced openssh-clients
yum install -y libvirt python-virtinst libvirt-daemon-xen
yum install -y bridge-utils tunctl

然后编辑 ifcfg-* 文件来创建网桥,在 CentOS 中不需要 NM_CONTROLLED=no:

echo "DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes" > /etc/sysconfig/network-scripts/ifcfg-br0

echo "DEVICE=eth0
HWADDR=XX:XX:XX:XX:XX:XX
ONBOOT=yes
TYPE=Ethernet
IPV6INIT=no
USERCTL=no
BRIDGE=br0" >  /etc/sysconfig/network-scripts/ifcfg-eth0

编辑HWADDR=XX:XX:XX:XX:XX:XX行以匹配您的 MAC 地址。不要在 ssh 控制台上重新启动,请使用 VBox 控制台

reboot

重启后,假设你有 DHCP 服务器,XEN 服务器将获得一个新的 IP,通过 VBox 控制台登录以获取新 IP

ifconfig 结果应该类似于

br0       Link encap:Ethernet  HWaddr 08:00:27:23:54:69  
          inet addr:192.168.1.105  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe23:5469/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5063 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3142 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:34251267 (32.6 MiB)  TX bytes:361205 (352.7 KiB)

eth0      Link encap:Ethernet  HWaddr 08:00:27:23:54:69  
          inet6 addr: fe80::a00:27ff:fe23:5469/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:149910 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5045 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:182020057 (173.5 MiB)  TX bytes:493792 (482.2 KiB)

现在网桥已准备就绪,你可以使用 br0 的 IP 再次获取 ssh 控制台

要在 XEN 上创建使用先前桥接的虚拟机:

cd /var/lib/xen/images/

创建虚拟磁盘:

dd if=/dev/zero of=centos_1.img bs=4K count=0 seek=1024K
qemu-img create -f raw centos_1.img 8G 

然后使用 virt-install 创建虚拟机:

virt-install -d -n TestVM1 -r 512 --vcpus=1 \
--bridge=br0 --disk /var/lib/xen/images/centos_1.img \
--nographics -p -l "http://192.168.1.6/centos/6.3/os/i386" \
--extra-args="text console=com1 utf8 console=hvc0 ks=http://192.168.1.6/centos/6.3/os/i386/ks.cfg"

现在虚拟机应该启动并能够正常从 DHCP 服务器获取 IP,并能够完成无人值守远程安装。

XEN 上的 ifconfig 结果应类似于:

br0       Link encap:Ethernet  HWaddr 08:00:27:23:54:69  
          inet addr:192.168.1.105  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe23:5469/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10247 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8090 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:102264338 (97.5 MiB)  TX bytes:827859 (808.4 KiB)

eth0      Link encap:Ethernet  HWaddr 08:00:27:23:54:69  
          inet6 addr: fe80::a00:27ff:fe23:5469/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:998780 errors:0 dropped:0 overruns:0 frame:0
          TX packets:37992 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:724701715 (691.1 MiB)  TX bytes:2897912 (2.7 MiB)


vif5.0    Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF  
          inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:37 errors:0 dropped:0 overruns:0 frame:0
          TX packets:67 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32 
          RX bytes:4381 (4.2 KiB)  TX bytes:9842 (9.6 KiB)

安装完成后,您可以使用 xen 控制台获取它的 IP,然后可以在其上使用 ssh 控制台。

答案2

1 - 检查您是否可以从网络上的另一台主机 ping xc63 的 IP 地址

2 – 检查该 URL 是否可以从同一网络上的其他主机运行。

3 - 检查你的 Web 服务器日志。或者防火墙规则

相关内容