1. 创建用于创建Xen DomU相关的目录

[root@virt-server ~]# mkdir /xen/{images,config.d,ISO,Kernel/centos6.10} -pv
mkdir: created directory ‘/xen’  # 此目录专门用来处理关于Xen的配置文件、镜像文件等
mkdir: created directory ‘/xen/images’  # 用于存储磁盘映像文件
mkdir: created directory ‘/xen/config.d’  # 用于存储配置文件
mkdir: created directory ‘/xen/ISO’  # 用于存储ISO文件
mkdir: created directory ‘/xen/Kernel’  # 用于加载Kernel
mkdir: created directory ‘/xen/Kernel/centos6.10’  # 可以有很多Kernel,本实验采用centos6

2. 将Centos6镜像文件从本机传输到虚拟机上

[root@virt-server ~]# yum install lrzsz
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile* base: mirrors.njupt.edu.cn* extras: mirrors.nju.edu.cn* updates: mirrors.cn99.com
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved==============================================================================================================================Package                    Arch                        Version                               Repository                 Size
==============================================================================================================================
Installing:lrzsz                      x86_64                      0.12.20-36.el7                        base                       78 kTransaction Summary
==============================================================================================================================
Install  1 PackageTotal download size: 78 k
Installed size: 181 k
Is this ok [y/d/N]: y
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm                                                                        |  78 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : lrzsz-0.12.20-36.el7.x86_64                                                                                1/1 Verifying  : lrzsz-0.12.20-36.el7.x86_64                                                                                1/1 Installed:lrzsz.x86_64 0:0.12.20-36.el7                                                                                               Complete!
[root@virt-server ~]# cd /xen/ISO
[root@virt-server ISO]# rz[root@virt-server ISO]# ls
CentOS-6.10-x86_64-minimal.iso

3. 准备kernel文件和ramdisk文件,使得第一次启动的时候能够加载进来

kernel & ramdisk 一般同时出现,用于借助 Dom0 中的内核文件来引导启动 Guest OS 的安装,即仅在安装 Guest OS (DomU)时使用;

# 首先把ISO镜像挂载到/mnt/下
[root@virt-server ISO]# mount -o loop CentOS-6.10-x86_64-minimal.iso /mnt/
mount: /dev/loop0 is write-protected, mounting read-only# 接着把kernel和ramdisk放进去
# DomU 第一次安装时需要通过 initrd & vmlinuz 完成系统引导与加载
[root@virt-server ISO]# cp /mnt/isolinux/{vmlinuz,initrd.img} ../Kernel/centos6.10/
[root@virt-server ISO]# ls ../Kernel/centos6.10/
initrd.img  vmlinuz
# 这样的话一个基础环境(内核和ramdisk)就准备完了cp

4. 配置网桥

# 首先创建其网卡配置文件,修改其中的内容
[root@virt-server ISO]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-xenbr0
[root@virt-server ISO]# vim /etc/sysconfig/network-scripts/ifcfg-xenbr0
[root@virt-server ISO]# cat /etc/sysconfig/network-scripts/ifcfg-xenbr0
TYPE=Bridge
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=xenbr0
DEVICE=xenbr0
ONBOOT=yes
IPADDR=192.168.245.131
GATEWAY=192.168.245.2
PEERDNS=no
PREFIX=24# 现在网桥已经配置完了,接下来要将物理地址删除掉(即删除eth0的地址)
[root@virt-server ISO]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@virt-server ISO]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
PEERDNS=no
BRIDGE=xenbr0# 到这里网桥就已经配置完了,我们来重启网络并查看一下
[root@virt-server ISO]# systemctl restart network
[root@virt-server ISO]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet6 fe80::20c:29ff:fe28:bf21  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:28:bf:21  txqueuelen 1000  (Ethernet)RX packets 669  bytes 52448 (51.2 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 419  bytes 50920 (49.7 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0xenbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.245.131  netmask 255.255.255.0  broadcast 192.168.245.255inet6 fe80::20c:29ff:fe28:bf21  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:28:bf:21  txqueuelen 1000  (Ethernet)RX packets 21  bytes 1236 (1.2 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 29  bytes 2838 (2.7 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@virt-server ISO]# brctl show
bridge name bridge id       STP enabled interfaces
xenbr0      8000.000c2928bf21   no      eth0

5. 创建硬盘(使用qemu-img命令)

# 创建硬盘
[root@virt-server ISO]# qemu-img create -f qcow2 -o size=10G /xen/images/CentOS6-10-4dom1.img
Formatting '/xen/images/CentOS6-10-4dom1.img', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 lazy_refcounts=off # 创建好后查看一下
[root@virt-server ISO]# qemu-img info /xen/images/CentOS6-10-4dom1.img
image: /xen/images/CentOS6-10-4dom1.img
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:compat: 1.1lazy refcounts: false

6. 创建DomU配置文件

[root@virt-server ISO]# vim /xen/config.d/centos6-10.cfg
[root@virt-server ISO]# cat /xen/config.d/centos6-10.cfg
builder = "generic"
name = "CentOS6.10-001"
memory = 1024
vcpus = 1
kernel = "/xen/Kernel/centos6.10/vmlinuz"
ramdisk = "/xen/Kernel/centos6.10/initrd.img"
vif = [ 'mac=00:16:3E:00:00:01', 'mac=00:16:3e:00:00:02,bridge=xenbr0' ]  # 指定mac地址、桥到哪个设备上等信息
disk = [ '/xen/images/CentOS6-10-4dom1.img,qcow2,xvda', '/xen/ISO/CentOS-6.10-x86_64-minimal.iso,,xvdb,cdrom,r' ]  # 目标地址(磁盘映像文件)、格式、在DomU中显示的名称、磁盘映像的访问权限(ro、r表示read-only, rw、w表示read/write)
boot = [ 'cd' ]  # 表示设定系统启动次序(c表示硬盘启动、d表示光盘启动、n表示网络启动、cd表示先尝试硬盘启动,不成功再尝试光盘启动)
vnc = 1
vnclisten = "0.0.0.0"
vncdisplay = 0
vncpasswd = "supersecret"

7. 现在就可以创建虚拟机了(用xl create命令)

# -n参数(--dryrun)可先把配置文件跑一下试试,不会加载实例,但能检测语法有没有错误
[root@virt-server ISO]# xl create -n /xen/config.d/centos6-10.cfg
Parsing config from /xen/config.d/centos6-10.cfg
{"c_info": {"type": "pv","name": "CentOS6.10-001","uuid": "8eb39814-6a54-44eb-834d-3b92f5937cb2","run_hotplug_scripts": "True"},"b_info": {"max_vcpus": 1,"avail_vcpus": [0],"max_memkb": 1048576,"target_memkb": 1048576,"shadow_memkb": 9216,"sched_params": {},"claim_mode": "True","kernel": "/xen/Kernel/centos6.10/vmlinuz","ramdisk": "/xen/Kernel/centos6.10/initrd.img","type.pv": {},"arch_arm": {}},"disks": [{"pdev_path": "/xen/images/CentOS6-10-4dom1.img","vdev": "xvda","format": "qcow2","readwrite": 1},{"pdev_path": "/xen/ISO/CentOS-6.10-x86_64-minimal.iso","vdev": "xvdb","format": "raw","removable": 1,"is_cdrom": 1}],"nics": [{"devid": 0,"mac": "00:16:3e:00:00:01"},{"devid": 1,"mac": "00:16:3e:00:00:02","bridge": "xenbr0"}],"vfbs": [{"devid": 0,"vnc": {"enable": "True","listen": "0.0.0.0","passwd": "supersecret"},"sdl": {}}],"vkbs": [{"devid": 0}],"on_reboot": "restart","on_soft_reset": "soft_reset"
}# 现在来真正创建虚拟机
[root@virt-server ISO]# xl create /xen/config.d/centos6-10.cfg
Parsing config from /xen/config.d/centos6-10.cfg# 这时候用netstat命令查看包含网络状态和协议统计信息的显示内容,发现出现5900,这是因为配置中的vncdisplay为0,而监听端口=vnc编号+5900
[root@virt-server ISO]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      2368/qemu-system-i3
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1100/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1227/master
tcp6       0      0 :::22                   :::*                    LISTEN      1100/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1227/master

8. 接下来用VNCViewer连接一下

# 首先需要关闭防火墙
# 查看防火墙状态(可知处于活跃状态)
[root@virt-server ISO]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: active (running) since Fri 2022-03-11 22:49:25 CST; 1h 2min agoDocs: man:firewalld(1)Main PID: 803 (firewalld)CGroup: /system.slice/firewalld.service└─803 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopidMar 11 22:49:16 virt-server systemd[1]: Starting firewalld - dynamic firewall daemon...
Mar 11 22:49:25 virt-server systemd[1]: Started firewalld - dynamic firewall daemon.
Mar 11 22:49:26 virt-server firewalld[803]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure con...t now.
Hint: Some lines were ellipsized, use -l to show in full.# 接下来把防火墙关掉并disable掉
[root@virt-server ISO]# systemctl stop firewalld
[root@virt-server ISO]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.# 接下来还要关掉enforce
[root@virt-server ISO]# getenforce
Enforcing
[root@virt-server ISO]# setenforce 0
[root@virt-server ISO]# getenforce
Permissive# 对于enforce来说,或者也可在文件中将其永久关掉
[root@virt-server ISO]# vim /etc/sysconfig/selinux
[root@virt-server ISO]# cat /etc/sysconfig/selinux # This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

现在就可以用vncviewer连接
然后是安装虚拟机系统。

在reboot之前需要修改一下DomU配置文件,即要kernel和ramdisk给注释掉。这是因为我们已经安装完操作系统了,而操作系统本身是有这两个文件的

[root@virt-server ISO]# vim /xen/config.d/centos6-10.cfg
[root@virt-server ISO]# cat /xen/config.d/centos6-10.cfg
builder = "generic"
name = "CentOS6.10-001"
memory = 1024
vcpus = 1
bootloader = "pygrub"
#kernel = "/xen/Kernel/centos6.10/vmlinuz"
#ramdisk = "/xen/Kernel/centos6.10/initrd.img"
vif = [ 'mac=00:16:3E:00:00:01', 'mac=00:16:3e:00:00:02,bridge=xenbr0' ]
disk = [ '/xen/images/CentOS6-10-4dom1.img,qcow2,xvda', '/xen/ISO/CentOS-6.10-x86_64-minimal.iso,,xvdb,cdrom,r' ]
boot = [ 'cd' ]
vnc = 1
vnclisten = "0.0.0.0"
vncdisplay = 0
vncpasswd = "supersecret"

现在就可以点上图的reboot进行重启了,重启完成后那个小页面就消失了。

接下来需要修改配置文件后重新创建一下。

# 用xl list查看当前虚拟机状态
[root@virt-server ~]# xl list
Name                                        ID   Mem VCPUs  State   Time(s)
Domain-0                                     0  1024     2     r-----      84.4
CentOS6.10-001                               2  1024     1     --p---       0.0# 销毁CentOS6.10-001,重新创建
[root@virt-server images]# xl destroy CentOS6.10-001
[root@virt-server images]# xl list
Name                                        ID   Mem VCPUs  State   Time(s)
Domain-0                                     0  1024     2     r-----      86.5# 修改配置文件
[root@virt-server images]# vim /xen/config.d/centos6-10.cfg
[root@virt-server images]# cat /xen/config.d/centos6-10.cfg
builder = "generic"
name = "CentOS6.10-001"
memory = 1024
vcpus = 1
#kernel = "/xen/Kernel/centos6.10/vmlinuz"
#ramdisk = "/xen/Kernel/centos6.10/initrd.img"
bootloader = "pygrub"
vif = [ 'mac=00:16:3E:00:00:01', 'mac=00:16:3e:00:00:02,bridge=xenbr0' ]
disk = [ '/xen/images/CentOS6-10-4dom1.img,qcow2,xvda' ]
boot = [ 'cd' ]
vnc = 1
vnclisten = "0.0.0.0"
vncdisplay = 0
vncpasswd = "supersecret"# 重新创建
[root@virt-server images]# xl create /xen/config.d/centos6-10.cfg
Parsing config from /xen/config.d/centos6-10.cfg
[root@virt-server images]# xl list
Name                                        ID   Mem VCPUs  State   Time(s)
Domain-0                                     0  1024     2     r-----      90.1
CentOS6.10-001                               6  1024     1     -b----       2.0# 查看是否监听在5900端口
[root@virt-server images]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      12631/qemu-system-i
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1016/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1152/master
tcp6       0      0 :::22                   :::*                    LISTEN      1016/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1152/master

可以看到已经监听在5900端口了,接下来用VNCViewer进行连接

可以直接启动,且能看到有两个网卡,eth0和eth1,但它们的状态是默认没有启动的,只需要在网卡配置文件中把ONBOOT改为yes即可

接着重启网络,CentOS6的命令和CentOS7有所不同

service network restart



此时我们是可以ping得通外网的

也是可以ping得通网关的(网关地址在宿主机的网桥配置文件中查看,即[root@virt-server images]# cat /etc/sysconfig/network-scripts/ifcfg-xenbr0

这说明了,这个新创建的CentOS6虚拟机和我们的宿主机(CentOS7)是在同一个网络内的,而且是可以和外网相通的(宿主机和外网相通、路由器和外网相通,这个新创建的虚拟机就和外网相通,这就是桥接模型)。

此时再回到宿主机上,看下网桥信息

[root@virt-server images]# brctl show
bridge name bridge id       STP enabled interfaces
xenbr0      8000.000c2928bf21   no      eth0vif6.0vif6.1

可以发现多了个6.0和6.1(因为xl list的ID已经到了第6个,前几个没有创建成功)
下面的xen_netback说明是虚拟机的后半段

[root@virt-server images]# lsmod | grep net
nfnetlink              16384  1 ip_set
xen_netback            53248  2

然后再开一个会话,远程连接dom1,即连接新创建的虚拟机的eth1,即192.168.245.133

[C:\~]$ Connecting to 192.168.245.133:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Fri Apr  8 20:04:30 2022
[root@localhost ~]# lsmod | grep net
xen_netfront           18930  0

可看到它是前半段。
即,我们的虚拟网卡被拆分成前半段和后半段,也就是xen的IO模型,在domU主机上存在IO设备的前半段信息,在宿主机的用户文件上存在它的后半段信息。

9. 再加一块网卡

现在虚拟机有两块网卡eth0和eth1,我们来给它加第三块网卡

[root@virt-server images]# xl network-attach 6 mac=00:16:3e:aa:bb:cc bridge=xenbr0
# 因为我们的虚拟机ID是6,所以用xl network-list 6来查看它的网卡信息
# 可以看到现在已经有三块网卡了
[root@virt-server images]# xl network-list 6
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:00:00:01     0     4     11   768/769         /local/domain/0/backend/vif/6/0
1   0  00:16:3e:00:00:02     1     4     12  1280/1281        /local/domain/0/backend/vif/6/1
2   0  00:16:3e:aa:bb:cc     2     4     13  1792/1793        /local/domain/0/backend/vif/6/2

其实在宿主机用ifconfig命令也可以看得到

[root@virt-server images]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet6 fe80::20c:29ff:fe28:bf21  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:28:bf:21  txqueuelen 1000  (Ethernet)RX packets 345151  bytes 454832210 (433.7 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 93589  bytes 15940043 (15.2 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1  (Local Loopback)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 0  bytes 0 (0.0 B)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0vif6.0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet6 fe80::fcff:ffff:feff:ffff  prefixlen 64  scopeid 0x20<link>ether fe:ff:ff:ff:ff:ff  txqueuelen 32  (Ethernet)RX packets 132  bytes 14534 (14.1 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 532  bytes 62428 (60.9 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0vif6.1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet6 fe80::fcff:ffff:feff:ffff  prefixlen 64  scopeid 0x20<link>ether fe:ff:ff:ff:ff:ff  txqueuelen 32  (Ethernet)RX packets 20  bytes 1844 (1.8 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 383  bytes 44262 (43.2 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0vif6.2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet6 fe80::fcff:ffff:feff:ffff  prefixlen 64  scopeid 0x20<link>ether fe:ff:ff:ff:ff:ff  txqueuelen 32  (Ethernet)RX packets 0  bytes 0 (0.0 B)RX errors 0  dropped 0  overruns 0  frame 0TX packets 64  bytes 6581 (6.4 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0xenbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.245.131  netmask 255.255.255.0  broadcast 192.168.245.255inet6 fe80::20c:29ff:fe28:bf21  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:28:bf:21  txqueuelen 1000  (Ethernet)RX packets 31354  bytes 1598979 (1.5 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 31742  bytes 9047665 (8.6 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

原来只有vif6.0和vif6.1,现在添加了个vif6.2。

我们在DomU上查看一下,

[root@localhost ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:16:3E:00:00:01  inet addr:192.168.245.132  Bcast:192.168.245.255  Mask:255.255.255.0inet6 addr: fe80::216:3eff:fe00:1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:631 errors:0 dropped:0 overruns:0 frame:0TX packets:179 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:63447 (61.9 KiB)  TX bytes:22696 (22.1 KiB)Interrupt:245 eth1      Link encap:Ethernet  HWaddr 00:16:3E:00:00:02  inet addr:192.168.245.133  Bcast:192.168.245.255  Mask:255.255.255.0inet6 addr: fe80::216:3eff:fe00:2/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:405 errors:0 dropped:0 overruns:0 frame:0TX packets:20 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:41627 (40.6 KiB)  TX bytes:2124 (2.0 KiB)Interrupt:244 eth2      Link encap:Ethernet  HWaddr 00:16:3E:AA:BB:CC  BROADCAST MULTICAST  MTU:1500  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)Interrupt:243 lo        Link encap:Local Loopback  inet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

可看到添加了个eth2.
现在我们把eth2启用一下(现在没有启用,只用ifconfig命令的话,不会显示eth2)

[root@localhost ~]# ifconfig eth2 192.168.245.134 up
[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:00:00:01  inet addr:192.168.245.132  Bcast:192.168.245.255  Mask:255.255.255.0inet6 addr: fe80::216:3eff:fe00:1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:763 errors:0 dropped:0 overruns:0 frame:0TX packets:234 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:74081 (72.3 KiB)  TX bytes:30446 (29.7 KiB)Interrupt:245 eth1      Link encap:Ethernet  HWaddr 00:16:3E:00:00:02  inet addr:192.168.245.133  Bcast:192.168.245.255  Mask:255.255.255.0inet6 addr: fe80::216:3eff:fe00:2/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:442 errors:0 dropped:0 overruns:0 frame:0TX packets:20 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:45203 (44.1 KiB)  TX bytes:2124 (2.0 KiB)Interrupt:244 eth2      Link encap:Ethernet  HWaddr 00:16:3E:AA:BB:CC  inet addr:192.168.245.134  Bcast:192.168.245.255  Mask:255.255.255.0inet6 addr: fe80::216:3eff:feaa:bbcc/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:66 errors:0 dropped:0 overruns:0 frame:0TX packets:3 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:5837 (5.7 KiB)  TX bytes:238 (238.0 b)Interrupt:243 lo        Link encap:Local Loopback  inet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

这个网卡是可以PING得通baidu.com的(用命令```ping baidu.com -I 192.168.245.134来指定从该网卡ping外网),且宿主机也是ping得通这个新加的网卡的。

10. 删除网卡

在宿主机上,删除网卡

[root@virt-server images]# xl network-list 6
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:00:00:01     0     4     11   768/769         /local/domain/0/backend/vif/6/0
1   0  00:16:3e:00:00:02     1     4     12  1280/1281        /local/domain/0/backend/vif/6/1
2   0  00:16:3e:aa:bb:cc     2     4     13  1792/1793        /local/domain/0/backend/vif/6/2
[root@virt-server images]# xl network-detach 6 2
[root@virt-server images]# xl network-list 6
Idx BE Mac Addr.         handle state evt-ch   tx-/rx-ring-ref BE-path
0   0  00:16:3e:00:00:01     0     4     11   768/769         /local/domain/0/backend/vif/6/0
1   0  00:16:3e:00:00:02     1     4     12  1280/1281        /local/domain/0/backend/vif/6/1

然后我们可以到虚拟机上去查看一下

[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:00:00:01  inet addr:192.168.245.132  Bcast:192.168.245.255  Mask:255.255.255.0inet6 addr: fe80::216:3eff:fe00:1/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:2060 errors:0 dropped:0 overruns:0 frame:0TX packets:811 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:177159 (173.0 KiB)  TX bytes:117744 (114.9 KiB)Interrupt:245 eth1      Link encap:Ethernet  HWaddr 00:16:3E:00:00:02  inet addr:192.168.245.133  Bcast:192.168.245.255  Mask:255.255.255.0inet6 addr: fe80::216:3eff:fe00:2/64 Scope:LinkUP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1RX packets:694 errors:0 dropped:0 overruns:0 frame:0TX packets:159 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:67798 (66.2 KiB)  TX bytes:15262 (14.9 KiB)Interrupt:244 lo        Link encap:Local Loopback  inet addr:127.0.0.1  Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING  MTU:65536  Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

可以看到第三块网卡已经被删除了

构建Xen实例之创建DomU相关推荐

  1. 虚拟化之安装Xen实例

    -----本文大纲 Xen简介 Xen体系结构 Xen布署(Centos 6.5) ------------- 一.Xen简介 Xen 是一个开放源代码虚拟机监视器,由剑桥大学开发.它打算在单个计算机 ...

  2. Oracle数据库实例的创建、删除、修改

    以SUSE10SP2.Oracle10gR2为例. 本文中的数据库实例这一称谓应该换做数据库更为准确,数据库可以理解为是一个物理的静态概念,主要包括一些物理存在的数据库文件,而数据库实例则是一个动态概 ...

  3. 魔方APP项目-02-服务端项目搭建,创建manage.py文件、构建全局初始化函数创建app应用对象、通过终端脚本启动项目、项目加载配置、数据库初始化、日志初始化、蓝图初始化

    服务端项目搭建 新建项目目录mofangapi,并创建虚拟环境 mkvirtualenv mofang 安装开发中使用的依赖模块 pip install flask==0.12.4 pip insta ...

  4. python功能性爬虫案例_Python使用requests及BeautifulSoup构建爬虫实例代码

    本文研究的主要是Python使用requests及BeautifulSoup构建一个网络爬虫,具体步骤如下. 功能说明 在Python下面可使用requests模块请求某个url获取响应的html文件 ...

  5. go面向对象编程:结构体struct详解、结构体实例的创建方式、结构体之间的转换(type取别名的使用)、方法的注意事项及与函数的区别

    入门示例 package main import "fmt" //定义老师结构体,将老师中的各个属性 统一放入结构体中管理: type Teacher struct{//变量名字大 ...

  6. 阿里云ecs实例中创建数据库

    阿里云ecs实例中创建数据库 安装mysql 创建数据库 1.登录 2.新建数据库 3.执行.sql文件 4.查询表,验证是否创建成功 4.退出数据库 安装mysql 参考https://blog.c ...

  7. idea maven创建java项目_新版本IntelliJ IDEA 构建maven,并用Maven创建一个web项目(图文教程)...

    之前都没试过用maven来管理过项目,但是手动找包导包确实不方便,于是今天用2016版的IDEA进行了maven的初尝试. 打开IDEA,创建新项目: 然后选择Maven,以及选择自己电脑的jdk: ...

  8. Python调用kafka构建完整实例分析与应用!

    近期遇到一个需求就是我们需要把当前比较耗费资源的接口开发成异步通讯的机制,简单来说就是有一个消息队列来不停地进行消息的集中分发与任务处理,这里应用端给出的方案是使用kafka来做,但是这个我在之前没有 ...

  9. windows下kafka环境完整搭建,Python调用kafka构建完整实例分析与应用

    今天临近下班的时候来了一个需求就是我们需要把当前比较耗费资源的接口开发成异步通讯的机制,简单来说就是有一个消息队列来不停地进行消息的集中分发与任务处理,这里应用端给出的方案是使用kafka来做,但是这 ...

最新文章

  1. 全国计算机一级考试理论部分,计算机一级考试理论试题:第七部分 单选
  2. windows常用进程
  3. 查询前10条_98条铁路!2021年底前计划开工建设铁路进度一览(10月8日更新)
  4. 【转】使用CSS 禁止文本选择
  5. 记一次工作中的小坑(关于celery)
  6. 拓端tecdat|R语言在不同样本量下的Little‘s MCAR检验
  7. Atitit 架构之道 attilax著 1. 架构的目的是什么??提高架构可读性。。提高扩展性。。对兼容性也有一定提升。。 3 1.1. 伸缩性架构设计 3 1.2. 提升性能架构 3 1.3.
  8. Oracle 执行计划(explain plan for)
  9. Linux服务器网络运维监控软件
  10. Python+networkx 网络可视化方法
  11. 私域流量客服社群运营员工工作绩效表格方案计划手册指南宝典
  12. C语言中的绝对值函数
  13. 初级会计资料-常用会计公式(三)
  14. 【word】系统内置样式
  15. 2019_GDUT_新生专题V算法优化 F. Expedition POJ 2431
  16. vue中is属性搭配vuedraggable插件实现可拖动可视化大屏展示组件的自定义配置功能
  17. jsfl批量导出swf
  18. java calendar 2月份_Calendar.MONTH 2月29号加一个月 问题
  19. Sipp工具实现呼叫中心的性能测试
  20. PMP认证与NPDP认证哪个含金量高?

热门文章

  1. (SOLIDWORKS)装配体轻化
  2. kali linux安装到U盘 无法启动,vmware 安装 kali linux 系统到U盘 启动错误(initramfs:) 修复方法...
  3. 肘关节附属运动测试软件,肘关节功能锻炼方法
  4. js引擎执行js代码的过程
  5. springboot引入nacos
  6. 几张图彻底搞定Seq2Seq
  7. 移动端JQ插件hammer使用详解
  8. php button onclick,php实现button的onclick事件的方法
  9. 四、PowerShell运行命令
  10. windows系统之powershell基础