virt-manager spice spicec

来源:互联网 发布:java utf8转gbk 编辑:程序博客网 时间:2024/05/26 19:16

virt-manager是libvirt的一个图形客户端,而libvirt是个通用的虚拟机管理库(支持kvm、xen、virtualbox、vmware等等)。virsh是libvirt的命令行客户端,用“virsh -c qemu:///system”可以在命令行管理virt-manager创建的虚拟机。

需要先在系统启动一个桥接网卡,才能在虚拟机里装bridged网卡。修改/etc/network/interfaces(debian)如下:

1234567891011121314151617
# Replace "auto eth0 ..." with following lines in /etc/network/interfaces
 
# The primary network interface
auto br0
iface br0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
network xxx.xxx.xxx.xxx
broadcast xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers xxx.xxx.xxx.xxx
dns-search domain.name
bridge_ports eth0
bridge_stp off
bridge_maxwait 0
bridge_fd 0
view rawgistfile1.sh hosted with ❤ by GitHub

Windows 7最多只支持两个CPU socket,每个socket内可以有多个core。kvm缺省每个CPU模拟一个socket,必须修改虚拟机CPU的topology,才能使用超过一个CPU。

spice

virt-manager创建的虚拟机只要加了spice display,就可以用spice协议远程使用虚拟机的控制台。

Linux下的spice客户端叫spicec。

最重要的是Win7里必须安装spice的驱动和服务,才能让性能和功能达到最强。相关程序在这里下载:http://www.spice-space.org/download.html

qxl和virtio-serial驱动是必须安装的。如果安装时提示数字签名无效,驱动不生效,用管理员权限执行cmd.exe,运行下面两行命令并reboot(reboot后桌面会有“测试模式”字样,不影响使用):

12
bcdedit.exe -set loadoptions DDISABLE_INTEGRITY_CHECKS
bcdedit.exe -set TESTSIGNING ON
view rawallow_test_sign.bat hosted with ❤ by GitHub

Windows guest agent服务也必须安装,才能同步剪贴板、屏幕分辨率。解开那个vdagent-xxxxx.zip,在管理员权限命令行执行“vdservice install”,然后reboot。

客户端加上–full-screen=auto-conf参数,就能全屏且同步分辨率了。Shift-F11切换全屏状态

spice性能确实比rdp好太多,看flash、gif基本不卡,视频音画基本同步,鼠标、键盘无延迟。最爽的,可以用招商银行大众版了!

安全的spice

spice缺省使用不安全连接。

用下面脚本创建必须的key

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
#!/bin/bash
 
SERVER_KEY=server-key.pem
 
# creating a key for our ca
if [ ! -e ca-key.pem ]; then
openssl genrsa -des3 -out ca-key.pem 1024
fi
# creating a ca
if [ ! -e ca-cert.pem ]; then
openssl req -new -x509 -days 1095 -key ca-key.pem -out ca-cert.pem -subj "/C=IL/L=Raanana/O=Red Hat/CN=my CA"
fi
# create server key
if [ ! -e $SERVER_KEY ]; then
openssl genrsa -out $SERVER_KEY 1024
fi
# create a certificate signing request (csr)
if [ ! -e server-key.csr ]; then
openssl req -new -key $SERVER_KEY -out server-key.csr -subj "/C=IL/L=Raanana/O=Red Hat/CN=my server"
fi
# signing our server certificate with this ca
if [ ! -e server-cert.pem ]; then
openssl x509 -req -days 1095 -in server-key.csr -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem
fi
 
# now create a key that doesn't require a passphrase
openssl rsa -in $SERVER_KEY -out $SERVER_KEY.insecure
mv $SERVER_KEY $SERVER_KEY.secure
mv $SERVER_KEY.insecure $SERVER_KEY
 
# show the results (no other effect)
openssl rsa -noout -text -in $SERVER_KEY
openssl rsa -noout -text -in ca-key.pem
openssl req -noout -text -in server-key.csr
openssl x509 -noout -text -in server-cert.pem
openssl x509 -noout -text -in ca-cert.pem
 
# copy *.pem file to /etc/pki/libvirt-spice
if [[ ! -d "/etc/pki/libvirt-spice" ]]
then
mkdir -p /etc/pki/libvirt-spice
fi
cp ./*.pem /etc/pki/libvirt-spice
 
# echo --host-subject
echo "your --host-subject is" \"`openssl x509 -noout -text -in server-cert.pem | grep Subject: | cut -f 10- -d " "`\"
 
echo "copy ca-cert.pem to %APPDATA%\spicec\spice_truststore.pem or ~/.spice/spice_truststore.pem in your clients"
view rawkeygen.sh hosted with ❤ by GitHub

根据提示记住–host-subject,拷贝ca-cert.pem到指定位置

关闭虚拟机,重新启动libvirtd(sudo /etc/init.d/libvirt-bin restart)

客户端用“spicec -h HOSTNAME -s TLS-PORT –host-subject HOST-SUBJECT -w PASSWORD”连接

其它

虚拟机硬件配置很容易调整,导致Windows激活经常失效。在线激活失败时,选电话激活,根据提示打电话,跟客服mm稍加解释,就能顺利激活了。(此条只对正版Windows有效)

主要参考

  1. SSLConnection – Spice
  2. QA:Testcase Virtualization Manually set spice listening port with TLS port set
  3. WinQXL – Spice
  4. Networking – KVM
  5. manpages
0 0