1. 硬件要求
硬件需要滿足如下要求:
1. 至少2G內存
2. 6G的硬盤空間
3. 對於全虛擬化需要CPU支持虛擬化技術
使用如下命令確認CPU的參數設置
- [root@test-19-227 ~]# cat /proc/cpuinfo | grep vmx
- flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx pdpe1gb rdtscp lm constant_tsc ida nonstop_tsc arat pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr sse4_1 sse4_2 popcnt lahf_lm
若要支持全虛擬機,則需要打開VT功能,如果沒有開啓VT,則需要進BIOS開啓該功能
2. 使用Yum安裝Xen
需要安裝Xen 和 kernel-Xen軟件包
Xen包:包含了Xen hypervisor 和Xen tools
kernel-xen: 是一個可以運行在Xen hypervisor虛擬機的linux內核
其他推薦工具:
- [root@test-19-227 ~]# yum install xen kernel-xen
python-virtinst:提供virt-install命令安裝虛擬機
libvirt-python:提供了用python語言腳本管理Xen的接口
libvirt:提供了命令行工具管理Xen虛擬機
virt-manager:提供了圖形化管理Xen虛擬機的工具
bridge-utils :該程序包存放的是用於配置以太網橋的實用程序,以太網橋的作用是將多個以太網設備連在一起。
Xen-libs :該程序包存放的是Xen的管理程序所需的程序庫。
3. 編輯grub,使用Xen內核啓動
修改前的grub文件:
- [root@test-19-227 ~]# vim /etc/grub.conf
- # 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)
- # kernel /vmlinuz-version ro root=/dev/vg_root/lv_root
- # initrd /initrd-version.img
- #boot=/dev/sda
- default=1
- timeout=5
- splashimage=(hd0,0)/grub/splash.xpm.gz
- hiddenmenu
- title CentOS (2.6.18-238.12.1.el5xen)
- root (hd0,0)
- kernel /xen.gz-2.6.18-238.12.1.el5
- module /vmlinuz-2.6.18-238.12.1.el5xen ro root=/dev/vg_root/lv_root
- module /initrd-2.6.18-238.12.1.el5xen.img
- title CentOS (2.6.18-194.el5)
- root (hd0,0)
- kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/vg_root/lv_root
- initrd /initrd-2.6.18-194.el5.img
注意default=1,默認情況下用第二個內核啓動,即使用title CentOS (2.6.18-194.el5)啓動;
應該使用title CentOS (2.6.18-238.12.1.el5xen)啓動,所以將default的值改爲0。
修改後的grub文件:
- # 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)
- # kernel /vmlinuz-version ro root=/dev/vg_root/lv_root
- # initrd /initrd-version.img
- #boot=/dev/sda
- default=0
- timeout=5
- splashimage=(hd0,0)/grub/splash.xpm.gz
- hiddenmenu
- title CentOS (2.6.18-238.12.1.el5xen)
- root (hd0,0)
- kernel /xen.gz-2.6.18-238.12.1.el5
- module /vmlinuz-2.6.18-238.12.1.el5xen ro root=/dev/vg_root/lv_root
- module /initrd-2.6.18-238.12.1.el5xen.img
- title CentOS (2.6.18-194.el5)
- root (hd0,0)
- kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/vg_root/lv_root
- initrd /initrd-2.6.18-194.el5.img
啓動參數的含義:
- title CentOS (2.6.18-238.12.1.el5xen) ##定義了內核的名稱,該名稱將在引導菜單時顯示
- root (hd0,0) ##定義了引導系統的根分區
- kernel /xen.gz-2.6.18-238.12.1.el5 ##指定了需要引導的內核
- module /vmlinuz-2.6.18-238.12.1.el5xen ro root=/dev/vg_root/lv_root ##定義了用於DOM0的內核
- module /initrd-2.6.18-238.12.1.el5xen.img ##定義了內核初始化時加載的初始RAM磁盤鏡像
4. 重啓機器,檢查是否是XEN內核
重啓前使用的內核:
- [root@test-19-227 ~]# uname -rm
- 2.6.18-194.el5 x86_64
重啓後使用的內核:
- [root@test-19-227 ~]# uname -rm
- 2.6.18-238.12.1.el5xen x86_64
檢查xend是否運行
- [root@test-19-227 ~]# ps -ef|grep xend
- root 5431 1 0 15:04 ? 00:00:00 /usr/bin/python /usr/sbin/xend start
- root 5432 5431 0 15:04 ? 00:00:00 /usr/bin/python
- root 5882 5846 0 15:09 pts/0 00:00:00 grep xend
檢查domain0是否運行
- [root@test-19-227 ~]# xm list
- Name ID Mem(MiB) VCPUs State Time(s)
- Domain-0 0 15651 16 r----- 32.7
檢查log輸出
- [root@test-19-227 xen]# more xend-debug.log
- Nothing to flush.
- Nothing to flush
5. 簡單製作網絡安裝環境
將centos的鏡像文件掛載到服務器上,並且將文件複製到配置好的HTTP目錄下即可。
6. 配置Xend的vnc服務
安裝vnc和vnc server
- [root@test-19-227 ~]# yum install vnc vnc-server
配置xend,配置如下選項
- [root@test-19-227 xen]# vim /etc/xen/xend-config.sxp
- (vnc-listen '192.168.19.227')
- (vncpasswd '')
重新啓動Xend,如果重啓不成功則需要重啓機器
- [root@test-19-227 xen]# service xend restart
7. 用virt-install命令全虛擬化安裝CentOS客戶機
- [root@test-19-227 CentOS]# virt-install -n Centos_xen -r 8196 --vcpus=16 -f /opt/xen_centos/Centos_xen.disk -s 120 -v --os-type=linux --os-variant=rhel5 -l http://192.168.19.215/centos/
使用VNC客戶端連接,開始安裝
下面的過程和正常安裝系統是一樣的