Linux下使用Xen搭建虚拟机心得

  • Linux下使用Xen搭建虚拟机心得 本文讲解了如下内容1、xen的安装步骤;2、如何使用xen搭建自己的虚拟机;3、在安装过程中遇到的问题。一、安装前检查1)查看你的主机cpu是否支持虚拟化:输入命令 cat /proc/cpuinfo | grep flags ,查看结果中有没有 pae ,若有则支持半虚拟化,再看有没有 vmx(intel) 或 svm((amd) ,若有,则支持全虚拟化。这个要在 xen 安装之前做,安装后默认就看不到 vms/svm 了。2)确认 BIOS 里虚拟化开关打开。为了快速安装Xen虚拟化软件此处笔者使用了yum对其进行了快速安装部署。
     二、Xen的安装步骤如下所示:  www.2cto.com  首先使用rpm –qa|grep xen检查系统是否已经安装了xen相关程序包如没有安装则继续以下操作1、安装xen虚拟化基本功能程序yum install xen*2、安装虚拟化管理程序包yum -y install virt-manager3、安装xen运行内核   yum install kernel-xen*4、修改系统启动内核为支持xen的kernel编辑/etc/grub.conf把default改成0,表示启动第一个内核具体修改内容见红色字体如下:# grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to this file# NOTICE:  You have a /boot partition.  This means that#          all kernel and initrd paths are relative to /boot/, eg.#          root (hd0,0)  www.2cto.com  #          kernel /vmlinuz-version ro root=/dev/sda2#          initrd /initrd-version.img#boot=/dev/sdadefault=0timeout=5splashimage=(hd0,0)/grub/splash.xpm.gzhiddenmenutitle Red Hat Enterprise Linux Server (2.6.18-308.8.2.el5xen)        root (hd0,0)        kernel /xen.gz-2.6.18-308.8.2.el5        module /vmlinuz-2.6.18-308.8.2.el5xen ro root=LABEL=/ rhgb quiet        module /initrd-2.6.18-308.8.2.el5xen.imgtitle Red Hat Enterprise Linux Server (2.6.18-8.el5)        root (hd0,0)        kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet        initrd /initrd-2.6.18-8.el5.img
     5、保存后退出系统并reboot主机使加载支持xen虚拟化的kernel6、检查系统是否已经成功加载支持虚拟化的kernel  使用 uname –a命令验证内核是否支持xen回显如下信息Linux sdlp.com 2.6.18-308.8.2.el5xen #1 SMP Tue Jun 12 11:16:34 EDT 2012 i686 i686 i386 GNU/Linux  www.2cto.com  根据回显信息证实xen已经安装成功。7、小提示:xen启动停止命令 xend start|stop|restart三、使用xen搭建自己的虚拟机1、使用xm list 命令确认xen的工作状态 回显信息如下所示Name                                      ID Mem(MiB) VCPUs State   Time(s)Domain-0                                   0      879     1 r-----    447.8表示虚拟域正常。
     2、 确认安装路径及安装空间,安装空间可以是一个文件、块设备或者虚拟磁盘或者指定的目录3、搭建nfs为提供安装系统镜像做好准备(本文因使用的半虚拟化所以需要使用ftp、http或者nfs进行安装因nfs搭建最为简单所以笔者采用了nfs的方式)4、使用xen安装虚拟机virt-install -n hello -r 256 --vcpus=1 --prompt --disk path=/dev/sdb / -l nfs:102.102.188.55:/m#安装了一个名为hello 内存256 安装路径/dev/sdb 以nfs交互式安装的windows操作系统5、虚拟机维护命令启动xm create hello关闭xm shutdown hello四、遇到的问题1、安装完毕重启主机后查看xm,竟然报错如下:ERROR Internal error: Could not obtain handle on privileged command interface (2 = No such file or directory)后面还有一行。解决办法:  www.2cto.com  # less /proc/cpuinfo如果是Intel的CPU,在flag栏中,应该有vmx 或者tm如果是AMD的CPU,在flag栏中,因该有svm 或者tm如果没有那就是你的主机不支持虚拟化了。
     反之你可能忘记将grub.conf文件中的default 的值改为带有xen核心启动的值了,注意是以0开始的。2、报如下错误  File "/usr/sbin/virt-install", line 31, in ?  import libvirt  File "/usr/lib/python2.4/site-packages/libvirt.py", line 25, in ? raise lib_eImportError: /usr/lib/libvirt.so.0: undefined symbol: audit_encode_nv_string解决办法安装yum install audit-libs-python.i386后问题解决  作者 fengzhanhai

     

  • 点这里复制本页地址发送给您QQ/MSN上的好友
  • 300*300广告