Red Hat开源SPICE虚拟桌面协议
2009-12-28 10:05:44 阿炯

Linux供应商Red Hat开源了SPICE(Simple Protocol for Independent Computing Environment)虚拟桌面协议,以加快这项技术的应用。

SPICE是去年Red Hat收购Qumranet后获得虚拟技术,被Qumranet使用在其商业虚拟桌面产品SolidIce中。SPICE能用于在服务器和远程计算机如桌面和瘦客户端设备上部署虚拟桌面。它类似于其它用于远程桌面管理的渲染协议,如微软的Remote Desktop Protocol或Citrix的Independent Computing Architecture。它支持Windows XP、Windows 7和Red Hat Enterprise Linux等虚拟机实例。大部分SPICE代码是采用GPLv2许可证发布,部分代码是采用LGPL许可证。


SPICE could be divided into 4 different components: Protocol, Client, Server and Guest.


The protocol is the specification in the communication of the three other components; A client such as remote-viewer is responsible to send data and translate the data from the Virtual Machine (VM) so you can interact with it; The SPICE server is the library used by the hypervisor in order to share the VM under SPICE protocol; And finally, the Guest side is all the software that must be running in the VM in order to make SPICE fully functional, such as the QXL driver and SPICE VDAgent.
 
Spice(独立计算环境简单协议)是红帽企业虚拟化桌面版的主要技术组件之一,具有自适应能力的远程提交协议,能够提供与物理桌面完全相同的最终用户体验。其包含三个组件:
SPICE Driver :SPICE驱动器 存在于每个虚拟桌面内的组件;

SPICE Device:SPICE设备 存在于红帽企业虚拟化Hypervisor内的组件;

SPICE Client:SPICE客户端 存在于终端设备上的组件,可以是瘦客户机或专用的PC,用于接入每个虚拟桌面。


这三个组件协作运行,确定处理图形的最高效位置,以能够最大程度改善用户体验并降低系统负荷。如果客户机足够强大,SPICE向客户机发送图形命令,并在客户机中对图形进行处理,显著减轻服务器的负荷。另一方面,如果客户机不够强大,SPICE在主机处理图形,从CPU的角度讲,图形处理并不需要太多费用。

安装与连接

1、软件安装与kvm xml 文件配置

可通过yum安装
# yum install spice-protocol spice-client spice-server

在kvm虚拟机的xml 文件中可以通过增加如下内容进行支持:
# virsh edit rhca
//增加如下内容
<graphics type='spice' port='5930' autoport='no' listen='192.168.0.102 ' passwd='password'/>
  <video>
<model type='qxl' vram='32768' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>

需要启用声卡时,还需要在配置文件中增加如下内容:
<sound model='ac97'>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</sound>

安装时就启用spice协议:
#virt-install \
-n windows \
-r 4096 \
-f /kvm/images/windows.img \
-s 50 \
--vcpus=2 \
--os-type windows \
--os-variant=win7 \
--network bridge=br0 \
--graphics spice,port=5940,listen=192.168.10.110,password=password \
--video qxl \
--channel spicevmc \
--cdrom /dev/cdrom

注:默认虚拟机使用的显卡是虚拟显卡,而使用spice协议时可以将虚拟网卡更换为qxl网卡,这会加快视频传输的质量。未使用virt进行管理的虚拟机,可以使用qemu 命令启动时进行指定:
qemu-kvm -m 15000 -cpu Nehalem,+vmx \
-net nic,vlan=0,macaddr=72:59:00:12:ab:22 \
-net tap,vlan=0,ifname=tap0  \
-smp 8,sockets=1,cores=8,threads=1 \
-drive file=/data/imgs/rhca/rhca.qcow2 \
-spice port=5930,disable-ticketing &

参数disable-ticketing的作用就是不使用密码(空密码)的方式连接。

2、spice连接

linux下的连接

连接guest的主机需要安装spice-client
# yum -y install spice-client
# /usr/libexec/spicec -h 192.168.10.102 -p 5930 -w password

windows连接guest

windows下也需要安装相当的客户端软件,具体可以到下载页面下载windows-spice。连接以后,还会在最近的连记录里。

浏览器连接

浏览器连接需要在连接端安装spice-xpi 浏览器插件,该插件支持firefox与Chromium浏览器,不过该插件目前仅支持linux系统。这个在后面的rh318 rhev红帽虚拟化平台上就有体现。

参考来源:

远程桌面协议浅析-VNC-SPICE-RDP