linux 虚拟化Xen初体验

简介:

Xen的虚拟化分为半虚拟化以及全虚拟化技术,其中半虚拟化主要是通过修改 Linux 核心来完成的虚拟化技术。Xen 的半虚拟化技术主要是用在相同发行版本的 Linux 上,如果你想要使用半虚拟化的方式启动多个虚拟机器,那么虚拟机器全部都必须是相同的操作系统,甚至要求相同版本与相同核心的 Linux 发行版本。如果你想要安装不同版本的 Linux 或者是其他的 OS ( Windows XP) 时,那就得要使用全虚拟化技术了。

全虚拟化技术必须满足以下条件:

 
  1. 硬件支持 Intel 的 VT 技术 (Virtualization Technology, Intel-VT);  
  2. 硬件支持 AMD 的 SVM 技术 (Secure Virtual Machine, AMD-SVM or, AMD-V)。  


下面来切实体验一下xen

 一、确定你的cpu是否支持虚拟化技术

 
  1. # cat /proc/cpuinfo |grep flags |egrep -o 'pae|vmx|svm' 
  2. pae 
  3. svm 
  4. pae 
  5. svm 

显示了PAE以及SVM,说明我的CPU支持全虚拟化技术。

二、安装Xen

1.安装Xen的基本程序

 
  1. # yum install -y xen* 

2.安装Xen的内核

 
  1. # yum install -y kernel-xen* 

3.安装Xen的虚拟管理程序

 
  1. # yum install -y virt-manager 

以上安装完毕,就来配置Xen的环境了

三、配置Xen环境

修改grub.conf文件,以Xen的内核来启动系统

 
  1. # grub.conf generated by anaconda 
  2. # Note that you do not have to rerun grub after making changes to this file 
  3. # NOTICE:  You do not have a /boot partition.  This means that 
  4. #          all kernel and initrd paths are relative to /, eg. 
  5. #          root (hd0,0) 
  6. #          kernel /boot/vmlinuz-version ro root=/dev/sda1 
  7. #          initrd /boot/initrd-version.img 
  8. #boot=/dev/sda 
  9. default=0 
  10. timeout=5 
  11. splashimage=(hd0,0)/boot/grub/splash.xpm.gz 
  12. hiddenmenu 
  13. title CentOS (2.6.18-238.12.1.el5xen) 
  14.         root (hd0,0) 
  15.         kernel /boot/xen.gz-2.6.18-238.12.1.el5 
  16.         module /boot/vmlinuz-2.6.18-238.12.1.el5xen ro root=LABEL=/ 
  17.         module /boot/initrd-2.6.18-238.12.1.el5xen.img 
  18. title CentOS (2.6.18-238.el5) 
  19.         root (hd0,0) 
  20.         kernel /boot/vmlinuz-2.6.18-238.el5 ro root=LABEL=/ 
  21.         initrd /boot/initrd-2.6.18-238.el5.img 

修改完毕,重启系统,shell界面就可以看到

 
  1. # uname -a 
  2. Linux Xen 2.6.18-238.12.1.el5xen #1 SMP Tue May 31 14:02:29 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux 

再看一下

 
  1. # xm list 
  2. Name                                      ID Mem(MiB) VCPUs State   Time(s) 
  3. Domain-0                                   0     1228     2 r-----    444.8

Xen的log所在地

 
  1. # ll /var/log/xen/ 
  2. total 44 
  3. drwx------ 2 root root  4096 May 10 05:30 console 
  4. -rw-r--r-- 1 root root  9653 Jun 10 15:07 domain-builder-ng.log 
  5. -rw-r--r-- 1 root root    36 Jun 10 14:53 xend-debug.log 
  6. -rw-r--r-- 1 root root 17855 Jun 10 15:07 xend.log 
  7. -rw-r--r-- 1 root root    36 Jun 10 15:07 xen-hotplug.log 

四、建立虚拟机

准备工作

这里我们安装虚拟机采用NFS的方式,如果你对你的网络比较自信,也可以采用网络安装的方式,视具体情况而定。

创建一个NFS Server并将光盘根目录下的文件copy 进去,同时分享出来并允许Xen宿主机访问,这个不是重点,就不写过程了

下面进入真正的虚拟机安装阶段

 
  1. # virt-install -n centos -r 512 --vcpus=1 \ 
  2. > --nographic -f /opt/vm/centos.img -s 20 -p \ 
  3. > -l nfs:192.168.1.249:/home/netinstall 

解释一下各参数的意义:

 
  1. -n           代表虚拟机的名字 
  2. -r           分配给虚拟机的内存 
  3. --vcpus      分配给虚拟机的CPU 
  4. --nographic  不适用图形界面 
  5. -f           虚拟机磁盘映像的所在地 
  6. -s           虚拟机磁盘映像的大小,单位记得是GB 
  7. -p           半虚拟化的方式 
  8. -l           安装映像的路径 

PS:上面是采用NFS的方式,如果internet比较快,就换成internet上的源,门户网站sohu,163均有开源的镜像站点,另外中国科技大学的镜像站点也不错

 
  1. # 开源镜像站点 
  2. 163  http://mirrors.163.com 
  3. sohu http://mirrors.sohu.com 
  4. 科大  http://mirrors.ustc.edu.cn 

运行上面的安装虚拟机命令后,会提示以下的信息

 
  1. Starting install... 
  2. Retrieving file vmlinuz...                                                                 | 2.1 MB     00:00 
  3. Retrieving file initrd.img...              85% [===========================     ] 5.6 MB/s | 6.7 MB     00:00 ETA 
  4. Message from syslogd@ at Fri Jun 10 15:07:07 2011 ... 
  5. Xen kernel: Disabling IRQ #16 
  6. Retrieving file initrd.img...                                                              | 7.9 MB     00:00 
  7. Creating storage file...                                                                   |  20 GB     00:00 
  8. Creating domain...                                                                         |    0 B     00:00 
  9. Connected to domain centos 
  10. Escape character is ^] 
  11. Bootdata ok (command line is  method=nfs:192.168.1.249:/home/netinstall) 
  12. Linux version 2.6.18-238.el5xen (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Thu Jan 13 16:41:45 EST 2011 
  13. BIOS-provided physical RAM map: 
  14.  Xen: 0000000000000000 - 0000000020800000 (usable) 
  15. No mptable found. 
  16. Built 1 zonelists.  Total pages: 133120 
  17. Kernel command line:  method=nfs:192.168.1.249:/home/netinstall 
  18. Initializing CPU#0 
  19. PID hash table entries: 4096 (order: 12, 32768 bytes) 
  20. Xen reported: 2812.790 MHz processor. 
  21. Console: colour dummy device 80x25 
  22. Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes) 
  23. Inode-cache hash table entries: 65536 (order: 7, 524288 bytes) 
  24. Software IO TLB disabled 
  25. Memory: 496384k/532480k available (2529k kernel code, 27260k reserved, 1736k data, 196k init) 
  26. Calibrating delay using timer specific routine.. 7050.28 BogoMIPS (lpj=14100572
  27. Security Framework v1.0.0 initialized 
  28. SELinux:  Initializing. 
  29. selinux_register_security:  Registering secondary module capability 
  30. Capability LSM initialized as secondary 
  31. Mount-cache hash table entries: 256 
  32. CPU: L1 I Cache: 64K (64 bytes/line), D cache 64K (64 bytes/line) 
  33. CPU: L2 Cache: 1024K (64 bytes/line) 
  34. CPU: Physical Processor ID: 0 
  35. CPU: Processor Core ID: 1 
  36. (SMP-)alternatives turned off 
  37. Brought up 1 CPUs 
  38. checking if image is initramfs... it is 
  39. Grant table initialized 
  40. NET: Registered protocol family 16 
  41. Brought up 1 CPUs 
  42. PCI: setting up Xen PCI frontend stub 
  43. ACPI: Interpreter disabled. 
  44. Linux Plug and Play Support v0.97 (c) Adam Belay 
  45. pnp: PnP ACPI: disabled 
  46. xen_mem: Initialising balloon driver. 
  47. usbcore: registered new driver usbfs 
  48. usbcore: registered new driver hub 
  49. PCI: System does not support PCI 
  50. PCI: System does not support PCI 
  51. NetLabel: Initializing 
  52. NetLabel:  domain hash size = 128 
  53. NetLabel:  protocols = UNLABELED CIPSOv4 
  54. NetLabel:  unlabeled traffic allowed by default 
  55. NET: Registered protocol family 2 
  56. IP route cache hash table entries: 32768 (order: 6, 262144 bytes) 
  57. TCP established hash table entries: 131072 (order: 9, 2097152 bytes) 
  58. TCP bind hash table entries: 65536 (order: 8, 1048576 bytes) 
  59. TCP: Hash tables configured (established 131072 bind 65536) 
  60. TCP reno registered 
  61. audit: initializing netlink socket (disabled) 
  62. type=2000 audit(1307689628.858:1): initialized 
  63. VFS: Disk quotas dquot_6.5.1 
  64. Dquot-cache hash table entries: 512 (order 0, 4096 bytes) 
  65. Initializing Cryptographic API 
  66. alg: No test for crc32c (crc32c-generic) 
  67. ksign: Installing public key data 
  68. Loading keyring 
  69. - Added public key C099FB4D84A418B6 
  70. - User ID: CentOS (Kernel Module GPG key) 
  71. io scheduler noop registered 
  72. io scheduler anticipatory registered 
  73. io scheduler deadline registered 
  74. io scheduler cfq registered (default) 
  75. pci_hotplug: PCI Hot Plug PCI Core version: 0.5 
  76. rtc: IRQ 8 is not free. 
  77. Non-volatile memory driver v1.2 
  78. Linux agpgart interface v0.101 (c) Dave Jones 
  79. brd: module loaded 
  80. Xen virtual console successfully installed as xvc0 
  81. Bootdata ok (command line is  method=nfs:192.168.1.249:/home/netinstall) 
  82. Linux version 2.6.18-238.el5xen (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Thu Jan 13 16:41:45 EST 2011 
  83. BIOS-provided physical RAM map: 
  84.  Xen: 0000000000000000 - 0000000020800000 (usable) 
  85. No mptable found. 
  86. Built 1 zonelists.  Total pages: 133120 
  87. Kernel command line:  method=nfs:192.168.1.249:/home/netinstall 
  88. Initializing CPU#0 
  89. PID hash table entries: 4096 (order: 12, 32768 bytes) 
  90. Xen reported: 2812.790 MHz processor. 
  91. Console: colour dummy device 80x25 
  92. Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes) 
  93. Inode-cache hash table entries: 65536 (order: 7, 524288 bytes) 
  94. Software IO TLB disabled 
  95. Memory: 496384k/532480k available (2529k kernel code, 27260k reserved, 1736k data, 196k init) 
  96. Calibrating delay using timer specific routine.. 7050.28 BogoMIPS (lpj=14100572
  97. Security Framework v1.0.0 initialized 
  98. SELinux:  Initializing. 
  99. selinux_register_security:  Registering secondary module capability 
  100. Capability LSM initialized as secondary 
  101. Mount-cache hash table entries: 256 
  102. CPU: L1 I Cache: 64K (64 bytes/line), D cache 64K (64 bytes/line) 
  103. CPU: L2 Cache: 1024K (64 bytes/line) 
  104. CPU: Physical Processor ID: 0 
  105. CPU: Processor Core ID: 1 
  106. (SMP-)alternatives turned off 
  107. Brought up 1 CPUs 
  108. checking if image is initramfs... it is 
  109. Grant table initialized 
  110. NET: Registered protocol family 16 
  111. Brought up 1 CPUs 
  112. PCI: setting up Xen PCI frontend stub 
  113. ACPI: Interpreter disabled. 
  114. Linux Plug and Play Support v0.97 (c) Adam Belay 
  115. pnp: PnP ACPI: disabled 
  116. xen_mem: Initialising balloon driver. 
  117. usbcore: registered new driver usbfs 
  118. usbcore: registered new driver hub 
  119. PCI: System does not support PCI 
  120. PCI: System does not support PCI 
  121. NetLabel: Initializing 
  122. NetLabel:  domain hash size = 128 
  123. NetLabel:  protocols = UNLABELED CIPSOv4 
  124. NetLabel:  unlabeled traffic allowed by default 
  125. NET: Registered protocol family 2 
  126. IP route cache hash table entries: 32768 (order: 6, 262144 bytes) 
  127. TCP established hash table entries: 131072 (order: 9, 2097152 bytes) 
  128. TCP bind hash table entries: 65536 (order: 8, 1048576 bytes) 
  129. TCP: Hash tables configured (established 131072 bind 65536) 
  130. TCP reno registered 
  131. audit: initializing netlink socket (disabled) 
  132. type=2000 audit(1307689628.858:1): initialized 
  133. VFS: Disk quotas dquot_6.5.1 
  134. Dquot-cache hash table entries: 512 (order 0, 4096 bytes) 
  135. Initializing Cryptographic API 
  136. alg: No test for crc32c (crc32c-generic) 
  137. ksign: Installing public key data 
  138. Loading keyring 
  139. - Added public key C099FB4D84A418B6 
  140. - User ID: CentOS (Kernel Module GPG key) 
  141. io scheduler noop registered 
  142. io scheduler anticipatory registered 
  143. io scheduler deadline registered 
  144. io scheduler cfq registered (default) 
  145. pci_hotplug: PCI Hot Plug PCI Core version: 0.5 
  146. rtc: IRQ 8 is not free. 
  147. Non-volatile memory driver v1.2 
  148. Linux agpgart interface v0.101 (c) Dave Jones 
  149. brd: module loaded 
  150. Xen virtual console successfully installed as xvc0 
  151. Event-channel device installed. 
  152. Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2 
  153. ide: Assuming 50MHz system bus speed for PIO modes; override with idebus=xx 
  154. ide-floppy driver 0.99.newide 
  155. usbcore: registered new driver hiddev 
  156. usbcore: registered new driver usbhid 
  157. drivers/usb/input/hid-core.c: v2.6:USB HID core driver 
  158. PNP: No PS/2 controller found. Probing ports directly. 
  159. i8042.c: No controller found. 
  160. mice: PS/2 mouse device common for all mice 
  161. md: md driver 0.90.3 MAX_MD_DEVS=256MD_SB_DISKS=27 
  162. md: bitmap version 4.39 
  163. TCP bic registered 
  164. Initializing IPsec netlink socket 
  165. NET: Registered protocol family 1 
  166. NET: Registered protocol family 17 
  167. XENBUS: Device with no driver: device/vbd/51712 
  168. XENBUS: Device with no driver: device/vif/0 
  169. Initalizing network drop monitor service 
  170. Write protecting the kernel read-only data: 498k 
  171.  
  172. Greetings. 
  173. anaconda installer init version 11.1.2.224 starting 
  174. mounting /proc filesystem... done 
  175. creating /dev filesystem... done 
  176. mounting /dev/pts (unix98 pty) filesystem... done 
  177. mounting /sys filesystem... done 
  178. anaconda installer init version 11.1.2.224 using /dev/xvc0 as console 
  179. trying to remount root filesystem read write... done 
  180. mounting /tmp as ramfs... done 
  181. running install... 
  182. running /sbin/loader 

接下来的安装就和平时的差不多了,顺便也贴一下图。

选择语言,english

网络的配置界面

具体的IP信息

这里选择文本模式

欢迎界面

是否要初始化disk,当然要

这步,不要啥操作,选择OK

选YES,就不翻译了

选择NO

也是NO

选择OK

设置主机名

时区的配置

root口令设置

自定义软件包

检查依赖关系

格式化文件系统

安装过程

安装完毕,最后重启。虚拟机完装好了,安装过程中可以通过ctrl+]回到宿主机。

五、虚拟机的一些管理命令

 
  1. xm dm xen的dmesg信息 
  2. xm create centos 启动虚拟机centos 
  3. xm console centos 以文本方式连接至虚拟机 
  4. xm reboot centos 重启虚拟机 
  5. xm shutdown centos 关闭虚拟机 
  6. xm pause centos 暂停虚拟机 
  7. xm resume centos 恢复被暂停的虚拟机 
  8. ………

虚拟机的配置文件位于/etc/xen下以虚拟机的名字为名称

 
  1. name = "centos" 
  2. uuid = "5ec1488a-42ec-87a7-8001-49243f29497f" 
  3. maxmem = 512 
  4. memory = 512 
  5. vcpus = 1 
  6. bootloader = "/usr/bin/pygrub" 
  7. on_poweroff = "destroy" 
  8. on_reboot = "restart" 
  9. on_crash = "restart" 
  10. disk = [ "tap:aio:/opt/vm/centos.img,xvda,w" ] 
  11. vif = [ "mac=00:16:36:45:e1:b1,bridge=xenbr0,script=vif-bridge" ] 
要想Xen虚拟机随开机自启动,要这样做
  1. # ln -s /etc/xen/centos /etc/xen/auto/ 
  2. # /etc/init.d/xendomains start 
  3. Starting auto Xen domains: centosUsing <class 'grub.GrubConf.GrubConfigFile'> to parse /grub/menu.lst 
  4. (skip)[done]                                               [  OK  ] 

本文转自dongfang_09859 51CTO博客,原文链接:http://blog.51cto.com/hellosa/585091,如需转载请自行联系原作者
相关文章
|
10天前
|
安全 Linux 虚拟化
网络名称空间在Linux虚拟化技术中的位置
网络名称空间(Network Namespaces)是Linux内核特性之一,提供了隔离网络环境的能力,使得每个网络名称空间都拥有独立的网络设备、IP地址、路由表、端口号范围以及iptables规则等。这一特性在Linux虚拟化技术中占据了核心位置🌟,它不仅为构建轻量级虚拟化解决方案(如容器📦)提供了基础支持,也在传统的虚拟机技术中发挥作用,实现资源隔离和网络虚拟化。
网络名称空间在Linux虚拟化技术中的位置
|
7月前
|
关系型数据库 Linux 虚拟化
掌握Linux服务器管理技巧与容器化应用 - 从软件服务到虚拟化技术全面解析
掌握Linux服务器管理技巧与容器化应用 - 从软件服务到虚拟化技术全面解析
91 0
|
10天前
|
Linux Shell 虚拟化
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
15 0
|
6月前
|
监控 Linux KVM
10 个最佳的 Linux 虚拟化软件,你用过哪些?
10 个最佳的 Linux 虚拟化软件,你用过哪些?
157 0
10 个最佳的 Linux 虚拟化软件,你用过哪些?
|
10月前
|
XML 存储 安全
【KVM虚拟化】· 命令行KVM安装linux
【KVM虚拟化】· 命令行KVM安装linux
125 0
|
10月前
|
存储 安全 Linux
【KVM虚拟化】· 图形化KVM安装linux
【KVM虚拟化】· 图形化KVM安装linux
192 0
|
10月前
|
存储 Linux 调度
Linux部署KVM虚拟化平台
Linux部署KVM虚拟化平台
262 0
|
11月前
|
运维 Kubernetes Cloud Native
本周精彩!关于 Linux 内核宕机和超融合 Kata 虚拟化容器技术介绍 | 第 77-78 期
龙蜥大讲堂精彩预告来了,本周在线分享Linux内核宕机和超融合技术。
|
弹性计算 安全 Linux
CentOS7下KVM虚拟化环境中体验Aliyun Linux 2系统
CentOS7下KVM虚拟化环境中体验Aliyun Linux 2系统
265 0
CentOS7下KVM虚拟化环境中体验Aliyun Linux 2系统
|
Web App开发 监控 安全
开发者曝 Android 13 “彩蛋”功能!虚拟化支持运行 Windows 11 和桌面版 Linux
开发者曝 Android 13 “彩蛋”功能!虚拟化支持运行 Windows 11 和桌面版 Linux
510 0
开发者曝 Android 13 “彩蛋”功能!虚拟化支持运行 Windows 11 和桌面版 Linux