Xen 虚拟机的使用:启动、关闭、暂停、回复、重启、进入终端 等

Xen 虚拟机的使用

 

(一) 使用虚拟机配置文件和磁盘文件来手动启动虚拟机系统

 

创建完虚拟机系统后虚拟系统会启动起来,使用xm list 命令能查看到启动的所有虚拟机 但我们下次重新启动系统后,使用xm list 将不能看到创建的虚拟机 网络设备中也不能看到虚拟机对应的网络设备。此时我们需要根据创建虚拟机时产生的配置文件和磁盘文件来手动启动虚拟机系统。

 

[root@gmnode14 software]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     4936     8 r-----    173.4

 

[root@gmnode14 Xen_zkl]# ifconfig     查看网络设备
eth1      Link encap:Ethernet  HWaddr 00:E0:81:C0:52:85 
          inet addr:10.10.113.14  Bcast:10.10.255.255  Mask:255.255.0.0
          inet6 addr: fe80::2e0:81ff:fec0:5285/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13405 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3144 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1701456 (1.6 MiB)  TX bytes:7347870 (7.0 MiB)
          Interrupt:251 Base address:0x2000

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:16436  Metric:1
          RX packets:334 errors:0 dropped:0 overruns:0 frame:0
          TX packets:334 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:23680 (23.1 KiB)  TX bytes:23680 (23.1 KiB)

virbr0     Link encap:Ethernet  HWaddr 00:00:00:00:00:00 
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:142 errors:0 dropped:0 overruns:0 frame:0
          TX packets:122 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:15472 (15.1 KiB)  TX bytes:16625 (16.2 KiB)

 

我们每创建一个虚拟机系统,就会产生两个文件:一个是虚拟机磁盘文件vm01-centos-5.5-pv.img 和一个虚拟机配置文件/etc/xen/vm01-CentOS-5.5, 配置文件内容如下:

------------------------------------------------------------------------------------------------
name = "vm01-CentOS-5.5"  虚拟机名称
uuid = "0283f36d-c95a-521b-737d-e400ca657029"
maxmem = 1024    最大内存
memory = 1024     虚拟机内存
vcpus = 4  cpu个数
bootloader = "/usr/bin/pygrub"
on_poweroff = "destroy" 
on_reboot = "restart"
on_crash = "restart"
disk = [ "tap:aio:/local/Xen_zkl/vm01-CentOS-5.5/vm01-CentOS-5.5.img,xvda,w" ]   磁盘文件
vif = [ "mac=00:16:36:40:43:85,bridge=virbr0,script=vif-bridge" ]  网络设备

-----------------------------------------------------------------------------------------------

 

[root@gmnode14 software]# xm create /etc/xen/vm01-CentOS-5.5   使用配置文件创建一个域
Using config file "/etc/xen/vm01-CentOS-5.5".
Started domain vm01-CentOS-5.5

 

若启动时出错,则参考 安装Xen、创建Xen虚拟机、使用Xen虚拟机过程中经常出现的错误总结


[root@gmnode14 software]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     6984     8 r-----    167.7
vm01-CentOS-5.5                      1     1024     4 -b----      0.6      创建的域的ID为1


[root@gmnode14 software]# xm create /etc/xen/vm02-CentOS-5.5-full 
Using config file "/etc/xen/vm02-CentOS-5.5-full".
Started domain vm02-CentOS-5.5-full


[root@gmnode14 software]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     4936     8 r-----    173.4
vm01-CentOS-5.5                            1     1023     4 r-----     11.4
vm02-CentOS-5.5-full                     2     2048     4 -b----      0.8
    创建的域的ID为2
[root@gmnode14 software]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0     4936     8 r-----    182.8
vm01-CentOS-5.5                      3     1023     4 -b----       19.6
vm02-CentOS-5.5-full                4     2047     4 -b----      34.4
You have new mail in /var/spool/mail/root

 

启动虚拟机后,相应的网络设备也添加了。


[root@gmnode14 Xen_zkl]# ifconfig  查看网络设备
eth1      Link encap:Ethernet  HWaddr 00:E0:81:C0:52:85 
          inet addr:10.10.113.14  Bcast:10.10.255.255  Mask:255.255.0.0
          inet6 addr: fe80::2e0:81ff:fec0:5285/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13758 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3307 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1741480 (1.6 MiB)  TX bytes:7373148 (7.0 MiB)
          Interrupt:251 Base address:0x2000

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:16436  Metric:1
          RX packets:334 errors:0 dropped:0 overruns:0 frame:0
          TX packets:334 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:23680 (23.1 KiB)  TX bytes:23680 (23.1 KiB)

vif1.0     Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF                domain  1 的网络设备
          inet6 addr: fe80::fcff:ffff:feff:ffff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:32
          RX bytes:0 (0.0 b)  TX bytes:4628 (4.5 KiB)

vif2.0     Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF               domain 2 的网络设备
          UP BROADCAST MULTICAST  MTU:1500  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:32
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

virbr0     Link encap:Ethernet  HWaddr FE:FF:FF:FF:FF:FF 
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:142 errors:0 dropped:0 overruns:0 frame:0
          TX packets:122 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:15472 (15.1 KiB)  TX bytes:16625 (16.2 KiB)

 

 

(二) xm 命令详解

 

xm console     <域ID>            # 从宿主机进入虚拟机的终端,退出时按 ctrl + ] 

xm reboot      <域ID>            # 重新启动虚拟机

xm pause       <域ID>             #暂停虚拟机

xm resume     <域ID>            # 恢复被暂停的虚拟机

xm shutdown <域ID>            # 关闭 domain

 

(二)  相关工具


virt-manager  创建、删除、修改虚拟机


virt-viewer  显示安装了图形界面的虚拟机的界面 ,例如 virt-viewer <domain-id>

 

 

 

 

阅读更多
个人分类: 软件使用 Linux
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Xen 虚拟机的使用:启动、关闭、暂停、回复、重启、进入终端 等

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭