RHEL5 提供一系列的virt commands 来使用,第一个就是在X-window 下面所使用的图形管理介面virt-manager
[root@benjr ~]# virt-manager |

其他要介绍的大都是在文字介面来使用的!
1.virt-install指令安装Guest的方法
Linux的传统就是指令集,所以不能避免的就是安装Guest也可以用指令"virt-install"方式如下所示:
[root@benjr xen]# virt-install Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems. no #yes为fully virtualized guest,no为para-virtualized guest What is the name of your virtual machine? rhel4.6 #虚拟主机名称 How much RAM should be allocated (in megabytes)? 256 #要指定多少记忆体空间给Guest.单位为MBs What would you like to use as the disk (file path )? /var/lib/xen/images/rhel4.6.img #虚拟磁碟(virtual disk) ,disk或是image皆可! 要使用nonsparse image disk请先加入参数virt-install -nonsparse. How large would you like the disk (/var/lib/xen/images/rhel4.6.img) to be (in gigabytes)? 8 # 虚拟磁碟(virtual disk) 空间大小 Would you like to enable graphics support? (yes or no ) yes #是否要图形介面 What is the install location? nfs:192.8.1.1:/var/ftp/rhel4-as-u6-64 #NFS : nfs:主机IP:Linux实际可以安装的目录 #WWW : http ://主机IP/可以安装的目录 #FTP : ftp://主机IP/可以安装的目录 Starting install... |
note:
由FTP来安装,请确定ftp的服务已经开预设路径为/var/ftp,并且目录/var/ftp/rhel4-as-u6-64/存放着RHEL4光碟的所有内容.
[root@benjr ~]# service vsftpd restart |
由NFS 来安装,编辑"/etc/exports" 并将"/var/ftp/as3u2" 目录分享(因为我们将把光碟内的档案放在此目录下,此为FTP预设的分享目录)
[root@benjr ~]# vi /etc/exports /var/ftp/ 192.8.1.*(ro,all_squash) [root@benjr ~]# service nfs start |
由HTTP来安装
编辑"/etc/httpd/conf/httpd.conf"并将Document设为/var/ftp(因为我们将把光碟内的档案放在此目录下,此为FTP预设的分享目录)
[root@benjr ~]# vi /etc/httpd/conf/httpd.conf Document Root "/var/ftp" [root@benjr ~]# service httpd restart |
2.virt-clone Clone Guest OS
如同Vmware ESX(i)或是XEN Source在RHEL5的XEN同样可以做clone,不过在图型介面好像看不到这一个选项!!似乎只有文字介面的工具"virt-clone"幸好使用上也不太难!!跟着下面步骤即可.
先安装好你将来要Cloning的Guest设定好并将他关机.目前我所有的Guest OS是rhel4 / rhel5
我要clone的是rhel5
#目前正在运行的Guest有两个RHEL4 / RHEL5我想用RHEL5 ,所以先将RHEL5关机吧!! [root@benjr ~]# xm shutdown rhel5 #or xm shutdown domain(domain ID) [root@benjr ~] # xm shutdown 4 #这动作相当于按下Guest OS的power button [root@benjr ~]# virt-clone #新的Guest的image位置名称. What would you like to use as the cloned disk (file path)? /var/lib/xen/images/rhel5_1.img #即将要被clone的Guest可以是名称或是uuid What is the name or uuid of the original virtual machine? rhel5 #新的Guest将被命名. What is the name for the cloned virtual machine? rhel5_1 Cloning from /var/lib/xen/images/rhel5.img to /var/lib/xen/images/rhel5_1.img Cloning domain... | 9.8 GB 04:07 |
当clone好一个系统时,有2种东西必须要修改.
1.Machine(Host) name
有些程式如samba会用Machine(Host) name当作NETBIOS名称解析,所以如果你网域上有相同的Machine( Host) name那你就麻烦了.
2.IP address
如果Cloning的系统使用的是DHCP那就没这问题了,当你设定的是固定IP不要忘记将你的系统IP修改以免和其他VM冲突到.至于MAC address , UUID系统在clone就会帮你修改,就不需要再特别重新改过
3.virt-image指令安装Guest的方法
老实说不是很想介绍这个指令,因为这个指令不是很好用,这个指令需要搭配一个XML档案,除非你是想用在大量部署Guest OS上面.
范例内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<image>
<name>sysresccd</name>
<domain>
<boot type="hvm">
<guest>
<arch>i686</arch>
</guest>
<os>
<loader dev="cdrom"/>
</os>
<drive disk="root.raw" target="hda"/>
<drive disk="sysresc"/>
</boot>
<devices>
<vcpu>1</vcpu>
<memory>262144</memory>
<interface/>
<graphics/>
</devices>
</domain>
<storage>
<disk file="root.raw" use="scratch" size="100" format="raw"/>
<disk id="sysresc" file="isos/systemrescuecd.iso"
use="system" format="iso"/>
</storage>
</image>
檔案內容很簡單,
<arch>i686</arch>
Platform i686 / x86_64 或是 ppc
<loader dev="cdrom"/>
實際可以安裝的媒體
<drive disk="root.raw" target="hda"/>
<drive disk="sysresc"/>
1 </vcpu>
指定vcpu个数 <memory>
262144 </memory>
指定多少记忆体空间给Guest.单位为kMBs
<disk file="root.raw" use="scratch" size="100" format="raw"/>
<disk id="sysresc" file="isos/systemrescuecd.iso" use="system" format="iso"/>
虛擬磁碟(virtual disk) 空間大小,裡面要注意的就是 Disk 的 isos/systemrescuecd.iso 檔案要先安建立好.
[root@Benjr ~]# mkdir isos [root@Benjr ~]# dd if=/dev/zero of= isos/systemrescuecd.iso count bs=512k count=20480 512kB*20480=10GB |
将这个档案存成image.xml 执行下面的指令.
[root@Benjr ~]# virt-image --vnc image.xml |
如果你只想安装几个Guest OS ,还是使用virt-manager / virt-install 会比较直觉.