下面是VirtualBox-4.3,VMware9.0下安装xen4.2
主机 cpu intel i3,BIOS里面开启虚拟化
virtualbox设置
vmware设置
默认已经开启了cpu的虚拟化
请先关闭selinux SELINUX=disabled
yum install gcc gcc-c++ vim wget lrzsz ntpdate sysstat dstat wget -y
# grep pae /proc/cpuinfo
flags: fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush mmx fxsr sse sse2 ht syscall nx lm constant_tsc rep_good nopl pni ssse3 hypervisor lahf_lm
# egrep 'vmx|svm' /proc/cpuinfo #结果为空
yum install centos-release-xen
yum install xen #会安装下列包
device-mapper-1.02.79-8.el6.x86_64 device-mapper-libs-1.02.79-8.el6.x86_64 yajl-1.0.7-3.el6.x86_64 libaio-0.3.107-10.el6.x86_64 xen-licenses-4.2.4-33.el6.centos.alt.x86_64 xen-libs-4.2.4-33.el6.centos.alt.x86_64 glusterfs-libs-3.4.0.57rhs-1.el6_5.x86_64 glusterfs-api-3.4.0.57rhs-1.el6_5.x86_64 kpartx-0.4.9-72.el6_5.3.x86_64 bridge-utils-1.2-10.el6.x86_64 SDL-1.2.14-3.el6.x86_64 libusb1-1.0.9-0.6.rc1.el6.x86_64 usbredir-0.5.1-1.el6.x86_64 2:qemu-img-0.12.1.2-2.415.el6_5.10.x86_64 pciutils-3.1.10-2.el6.x86_64 python-lxml-2.2.3-1.1.el6.x86_64 kernel-firmware-3.10.43-11.el6.centos.alt.noarch kernel-3.10.43-11.el6.centos.alt.x86_64 xen-hypervisor-4.2.4-33.el6.centos.alt.x86_64 xen-runtime-4.2.4-33.el6.centos.alt.x86_64 xen-4.2.4-33.el6.centos.alt.x86_64 kernel-firmware-2.6.32-358.el6.noarch kernel-firmware-3.10.43-11.el6.centos.alt.noarch 2:qemu-img-0.12.1.2-2.415.el6_5.10.x86_64 glusterfs-libs-3.4.0.57rhs-1.el6_5.x86_64 xen-libs-4.2.4-33.el6.centos.alt.x86_64 device-mapper-libs-1.02.79-8.el6.x86_64 kpartx-0.4.9-72.el6_5.3.x86_64 python-lxml-2.2.3-1.1.el6.x86_64 xen-licenses-4.2.4-33.el6.centos.alt.x86_64 usbredir-0.5.1-1.el6.x86_64 xen-hypervisor-4.2.4-33.el6.centos.alt.x86_64 pciutils-3.1.10-2.el6.x86_64 libaio-0.3.107-10.el6.x86_64 xen-4.2.4-33.el6.centos.alt.x86_64 device-mapper-1.02.79-8.el6.x86_64 libusb1-1.0.9-0.6.rc1.el6.x86_64 glusterfs-api-3.4.0.57rhs-1.el6_5.x86_64 xen-runtime-4.2.4-33.el6.centos.alt.x86_64 SDL-1.2.14-3.el6.x86_64 bridge-utils-1.2-10.el6.x86_64 yajl-1.0.7-3.el6.x86_64 kernel-3.10.43-11.el6.centos.alt.x86_64 kernel-firmware-2.6.32-358.el6.noarch
/usr/bin/grub-bootxen.sh
# grep -v ^# /boot/grub/grub.conf default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title CentOS (3.10.43-11.el6.centos.alt.x86_64) root (hd0,0) kernel /xen.gz dom0_mem=1024M,max:1024M loglvl=all guest_loglvl=all module /vmlinuz-3.10.43-11.el6.centos.alt.x86_64 ro root=UUID=4aba9486-86c5-4cb0-87c9-435e38a9ce86 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet module /initramfs-3.10.43-11.el6.centos.alt.x86_64.img title CentOS (2.6.32-358.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=4aba9486-86c5-4cb0-87c9-435e38a9ce86 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-358.el6.x86_64.img
此时vmware重启会一直停留在卡机页面,需要进入虚拟机的安装文件夹,修改CentOS 64-bit.vmx 文件中 vcpu.hotadd = "TRUE" 改为vcpu.hotadd = "FALSE"
reboot #安装完成后重启
# ll /boot/xen.gz lrwxrwxrwx 1 root root 19 Aug 13 06:42 /boot/xen.gz -> xen-4.2.4-33.el6.gz # xm info host : localhost.localdomain release : 3.10.43-11.el6.centos.alt.x86_64 version : #1 SMP Mon Jun 16 14:22:02 UTC 2014 machine : x86_64 nr_cpus : 4 nr_nodes : 1 cores_per_socket : 4 threads_per_core : 1 cpu_mhz : 3353 hw_caps : 178bfbff:28100800:00000000:00000140:00000201:00000000:00000001:00000000 virt_caps : total_memory : 2047 free_memory : 998 free_cpus : 0 xen_major : 4 xen_minor : 2 xen_extra : .4-33.el6 xen_caps : xen-3.0-x86_64 xen-3.0-x86_32p xen_scheduler : credit xen_pagesize : 4096 platform_params : virt_start=0xffff800000000000 xen_changeset : unavailable xen_commandline : dom0_mem=1024M,max:1024M loglvl=all guest_loglvl=all cc_compiler : gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4) cc_compile_by : mockbuild cc_compile_domain : centos.org cc_compile_date : Mon Jun 16 17:22:14 UTC 2014 xend_config_format : 4
# xm list Name ID Mem VCPUs State Time(s) Domain-0 0 1024 4 r----- 113.9
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-br0 # cat /etc/sysconfig/network-scripts/ifcfg-br0 DEVICE=br0 TYPE=Bridge ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none IPADDR=192.168.22.242 PREFIX=24 GATEWAY=192.168.22.253 DNS1=114.114.114.114 DOMAIN=114.114.114.114 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="System br0" # cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none BRIDGE=br0 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="System eth0" # service network restart # brctl show bridge name bridge id STP enabled interfaces br0 8000.0800278072e5 no eth0 virbr0 8000.feffffffffff yes vif4.0
# service xend start # yum install libvirt python-virtinst libvirt-daemon-xen virt-manager virt-viewer # /etc/init.d/libvirtd start #或者service libvirtd start # chkconfig libvirtd on
# yum install httpd # mount -o loop /data/CentOS-6.5-x86_64-minimal.iso /mnt/ # mkdir -p /var/www/html/centos # cp -r /mnt /var/www/html/centos # vim /var/www/html/centos/mnt/.treeinfo [images-x86_64] initrd = images/pxeboot/initrd.img [images-xen] kernel = isolinux/vmlinuz initrd = isolinux/initrd.img vim /etc/httpd/conf/httpd.conf 292 #DocumentRoot "/var/www/html" 293 DocumentRoot "/var/www/html/centos/mnt/" 317 #<Directory "/var/www/html"> 318 <Directory "/var/www/html/centos/mnt/"> vim /etc/httpd/conf.d/welcome.conf <LocationMatch "^/+$"> Options +Indexes ErrorDocument 403 /error/noindex.html </LocationMatch> service httpd start
开启iptables的80端口,用virt-install安装guest
virt-install -n vm01 -r 512 --vcpus=2 --disk /data/images/vm01.img,size=10 --nographics -p -l "http://192.168.22.242" -w bridge:br0 --extra-args="text console=com1 utf8 console=hvc0"
name vm01
内存 512M
cpu 2颗
磁盘文件 /data/images/vm01.img
磁盘大小 10G
如果安装的过程中出现下面提示,不往下走了
running install...
running /sbin/loader
detecting hardware...
waiting for hardware to initialize...
那么稍等一会,这个不是错误
# xl list Name ID Mem VCPUsStateTime(s) Domain-0 0 726 4 r----- 769.9 vm01 6 512 2 -b---- 39.0
xl console vm01 #连接vm1
也可以选择交互式安装 virt-install --prompt
# virt-install --help Usage: virt-install --name NAME --ram RAM STORAGE INSTALL [options] Options: --version show program's version number and exit -h, --help show this help message and exit --connect=URI Connect to hypervisor with libvirt URI General Options: -n NAME, --name=NAME Name of the guest instance -r MEMORY, --ram=MEMORY Memory to allocate for guest instance in megabytes --vcpus=VCPUS Number of vcpus to configure for your guest. Ex: --vcpus 5 --vcpus 5,maxcpus=10 --vcpus sockets=2,cores=4,threads=2 --cpuset=CPUSET Set which physical CPUs domain can use. --cpu=CPU CPU model and features. Ex: --cpu coreduo,+x2apic --description=DESCRIPTION Human readable description of the VM to store in the generated XML. --security=SECURITY Set domain security driver configuration. --numatune=NUMATUNE Tune NUMA policy for the domain process. Installation Method Options: -c CDROM, --cdrom=CDROM CD-ROM installation media -l LOCATION, --location=LOCATION Installation source (eg, nfs:host:/path, http://host/path, ftp://host/path) --pxe Boot from the network using the PXE protocol --import Build guest around an existing disk image --init=INIT Path to init binary for container guest. Ex: --init /path/to/app (to contain an application) --init /sbin/init (for a full OS container) --livecd Treat the CD-ROM media as a Live CD -x EXTRA, --extra-args=EXTRA Additional arguments to pass to the install kernel booted from --location --initrd-inject=INITRD_INJECTIONS Add given file to root of initrd from --location --os-type=DISTRO_TYPE The OS type being installed, e.g. 'linux', 'unix', 'windows' --os-variant=DISTRO_VARIANT The OS variant being installed guests, e.g. 'fedora6', 'rhel5', 'solaris10', 'win2k' --boot=BOOTOPTS Optionally configure post-install boot order, menu, permanent kernel boot, etc. Storage Configuration: --disk=DISKOPTS Specify storage with various options. Ex. --disk path=/my/existing/disk --disk path=/my/new/disk,size=5 (in gigabytes) --disk vol=poolname:volname,device=cdrom,bus=scsi,... --nodisks Don't set up any disks for the guest. --filesystem=FILESYSTEMS Pass host directory to the guest. Ex: --filesystem /my/source/dir,/dir/in/guest --filesystem template_name,/,type=template Networking Configuration: -w NETWORK, --network=NETWORK Configure a guest network interface. Ex: --network bridge=mybr0 --network network=my_libvirt_virtual_net --network network=mynet,model=virtio,mac=00:11... --nonetworks Don't create network interfaces for the guest. Graphics Configuration: --graphics=GRAPHICS Configure guest display settings. Ex: --graphics vnc --graphics spice,port=5901,tlsport=5902 --graphics none --graphics vnc,password=foobar,port=5910,keymap=ja --noautoconsole Don't automatically try to connect to the guest console Device Options: --serial=SERIALS Configure a guest serial device --parallel=PARALLELS Configure a guest parallel device --channel=CHANNELS Configure a guest communication channel --console=CONSOLES Configure a text console connection between the guest and host --host-device=HOSTDEVS Configure physical host devices attached to the guest --soundhw=SOUNDHW Configure guest sound device emulation --watchdog=WATCHDOG Configure a guest watchdog device --video=VIDEO Configure guest video hardware. --smartcard=SMARTCARD Configure a guest smartcard device. Ex: --smartcard mode=passthrough Virtualization Platform Options: -v, --hvm This guest should be a fully virtualized guest -p, --paravirt This guest should be a paravirtualized guest --container This guest should be a container guest --virt-type=HV_TYPE Hypervisor name to use (kvm, qemu, xen, ...) --arch=ARCH The CPU architecture to simulate --machine=MACHINE The machine type to emulate --noapic Disables APIC for fully virtualized guest (overrides value in os-type/os-variant db) --noacpi Disables ACPI for fully virtualized guest (overrides value in os-type/os-variant db) -u UUID, --uuid=UUID UUID for the guest. Miscellaneous Options: --autostart Have domain autostart on host boot up. --print-xml Print the generated domain XML rather than define the guest. --print-step=XMLSTEP Print XML of a specific install step (1, 2, 3, all) rather than define the guest. --noreboot Don't boot guest after completing install. --wait=WAIT Time to wait (in minutes) --dry-run Run through install process, but do not create devices or define the guest. --force Forces 'yes' for any applicable prompts, terminates for all others -q, --quiet Suppress non-error output --prompt Request user input for ambiguous situations or required options. -d, --debug Print debugging information