CentOS6.5环境下spice配置和连接

一、实验环境:

主机名                IP(Static)                        系统                                               配置                                 用途
KVMServer       192.168.100.109        CentOS-6.5-x86_64-DVD        4CPU,8G RAM,146G DISK,2网卡         Spice test

二、KVMServer安装和配置:

1.安装

KVMServer采用CentOS-6.5-x86_64-DVD.iso光盘安装,并安装桌面。

2.关闭selinux和iptables

[root@KVMServer ~]# vi /etc/selinux/config

SELINUX=disabled

[root@KVMServer ~]# iptables –F

[root@KVMServer ~]# service iptables stop

[root@KVMServer ~]# service ip6tables stop

[root@KVMServer ~]# chkconfig iptables off

[root@KVMServer ~]# chkconfig ip6tables off

3.设置桥接网络

(1).编辑/etc/sysconfig/network内容如下:

[root@KVMServer ~]# vi /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=node01

GATEWAY=br0

(2).编辑/etc/sysconfig/network-scripts/ifcfg-em1内容如下,HWADDR可注释掉:

[root@KVMServer ~]# vi /etc/sysconfig/network-scripts/ifcfg-em1 

DEVICE="eth0"

ONBOOT=yes

BRIDGE=br0

(3).创建ifcfg-br0文件,内容如下:

[root@KVMServer ~]# vi /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0

BOOTPROTO=static

ONBOOT=yes

TYPE=Bridge

IPADDR=192.168.100.109

NETMASK=255.255.255.0

GATEWAY=192.168.100.254

BROADCAST=192.168.100.255

DELAY=0

(4).重启网络服务:

[root@KVMServer ~]# service network restart

[root@KVMServer ~]# reboot

4.yum安装KVM、libvirt等组件

[root@KVMServer ~]# yum -y install gcc gcc-c++ kvm libvirt python-virtinst ruby ruby-devel ruby-docs ruby-ri flex bison xmlrpc-c-devel libxslt-devel

5.配置libvirt.conf和qemu.conf

编辑/etc/libvirt/libvirtd.conf配置libvirt,将操作权限授予给cloud组,并将listen_tcp = 1unix_sock_rw_permsauth_unix_roauth_unix_rw“#”注释去掉。

[root@KVMServer ~]# vi /etc/libvirt/libvirtd.conf

listen_tcp = 1

unix_sock_group = "root"

unix_sock_rw_perms = "0770"

auth_unix_ro = "none"

auth_unix_rw = "none"

编辑/etc/libvirt/qemu.conf,设置VNC

[root@KVMServer ~]# vi /etc/libvirt/qemu.conf

vnc_listen = “0.0.0.0″

user = "root"                      /*root用户管理虚拟机*/

group = "root"

dynamic_ownership = 0              /*禁止虚拟镜像动态调整所有权限*/

6.yum安装virt-manager和spice等组件

[root@KVMServer ~]# yum -y install virt-manager cairo-spice ffmpeg-spice-libs ngspice pixman-spice spice-glib spice-gtk spice-gtk-python spice-gtk-tools spice-xpi spice-client

7.安装虚拟机

(1).将现有qcow2格式的Windows2K3镜像拷贝到kvm存储目录:

[root@KVMServer ~]# cd /srv/cloud/one/images/

[root@KVMServer ~]# ls

Windows2k3-64bit.qcow2

[root@KVMServer ~]# cp -av Windows2k3-64bit.qcow2 /var/lib/libvirt/images/

(2).在宿主机图形界面下执行virt-manager进行虚拟机的配置安装

[root@KVMServer ~]# virt-manager

点击下图的小电脑图标创建虚拟机:

填写虚拟机名称和安装系统的方式:


点击“浏览”选择刚才上传的qcow2镜像,指定操作系统类型和版本:

指定虚拟机内存大小和CPU个数:

选择“在安装前自定义配置”,并查看“高级选项”检查是否符合该虚拟机的配置要求:

进入“自定义配置界面”,在“显示”项选择Spice显示类型:

在“视频”选项,选择“qxl”类型:

点击“Begin Installation”完成配置。

8.修改配置脚本

创建虚拟机后,默认情况下只允许本地(127.0.0.1)访问,需要更改配置文件允许其他主机访问,具体有如下几步:

(1).登陆虚拟机,将虚拟机关机。

(2).登录到这台虚拟机运行的宿主机,修改该虚拟机的配置文件:

[root@KVMServer ~]# cd /etc/libvirt/qemu

[root@KVMServer qemu]# ls

networks  vm-00.xml

[root@KVMServer qemu]# vi vm-00.xml

找到:<graphics type='spice' autoport='yes'/>

修改为:<graphics type='spice' autoport='yes' listen='0.0.0.0'>

(3).应用配置文件,启动虚拟机:


[root@KVMServer qemu]# virsh define vm-00.xml

[root@KVMServer qemu]# virsh list --all

 Id    名称                         状态

----------------------------------------------------

 -     vm-00                          关闭

[root@KVMServer qemu]# virsh start vm-00

域 vm-00 已开始

三、客户端访问

1.Linux客户端访问

(1).选择任意一台有桌面环境的Linux主机,安装spice-client:

[root@node ~]# yum -y install spice-client

(2).使用spice的方式连接kvm虚拟机:

[root@node ~]# spice -h 192.168.100.109 -p 5900 

(3).连接显示:

2.Windows客户端访问

(1).下载和安装spice-client:

下载地址:http://www.spice-space.org/download.html

virt-viewer Windows installer - 32 bit - virt-viewer-x86-0.5.7.msi

virt-viewer Windows installer - 64 bit - virt-viewer-x64-0.5.7.msi

(2).双击virt-viewer,填写spice://192.168.100.109:5900

(3).点击Connect,登录虚拟机


其他:

修改虚拟机配置文件的其他参数举例:

<graphics type='spice' port='5930' autoport='no' listen='192.168.100.109 ' passwd='password'/>  

Linux环境下spice连接VM的密码参数:

usr/libexec/spice -h 192.168.100.109 -p 5900 -w password

原文地址:https://www.cnblogs.com/myiaas/p/4161339.html