KVM是Kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,KVM的虚拟化需要硬件支持(如Intel VT技术或者AMD V技术)。是基于硬件的完全虚拟化。
实验环境:单台服务器部署,IP地址为:192.168.10.30 [root@server ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) 1. 硬件检测: [root@server ~]# egrep '^flags.*(vmx|svm)' /proc/cpuinfo 如果输出的结果包含VMX,它是Intel处理器虚拟机技术标志:如果包含SVM,它是AMD处理器虚拟机技术的标志,如果你什么都没有得到,那你的系统并没有支持虚拟化的处理,不能使用KVM,另linux发行版本必须在64bit环境中才能使用KVM。
2.BIOS中开启VT: 确认在主板BIOS中开启CPU的Virtual Technolege(VT,虚化技术),不同主板所在菜单不同. 3.安装步骤: [root@server ~]# yum clean all && yum makecache //重新初始化yum缓存 [root@server ~]# yum install -y qemu-kvm qemu-key-tools virt-manager libvirt virt-install python-virtinst bridge-utils [root@server ~]# yum install -y install qemu* [root@server ~]# lsmod |grep kvm
kvm_intel 148081 0 kvm 461126 1 kvm_inte
[root@server ~]# modprobe kvm && modprobe kvm_intel [root@server ~]# systemctl enable libvirtd && systemctl start libvirtd [root@server ~]# virsh -c qemu:///system list //出现如下说明KVM安装成功
Id Name State
----------------------------------------------------
[root@server ~]# yum groupinstall "X Window System" //安装X-Window [root@server ~]# yum install -y gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts [root@server ~]# yum install -y tigervnc tigervnc-server tigervnc-server-module //安装VNC [root@server ~]# cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service [root@server ~]# cat /lib/systemd/system/vncserver@:1.service | grep -v ^# | grep -v ^$
[Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking User=root ExecStartPre=-/usr/bin/vncserver -kill %i ExecStart=/sbin/runuser -l root -c "/usr/bin/vncserver %i" PIDFile=/root/.vnc/%H%i.pid ExecStop=-/usr/bin/vncserver -kill %i [Install] WantedBy=multi-user.target
[root@server ~]# systemctl daemon-reload [root@server ~]# vncpasswd
Password:hello123 Verify:hello123 Would you like to enter a view-only password (y/n)? n
[root@server ~]# systemctl enable vncserver@:1.service && systemctl start vncserver@:1.service [root@server ~]# systemctl status vncserver@:1.service
● vncserver@:1.service - Remote desktop service (VNC) Loaded: loaded (/usr/lib/systemd/system/vncserver@:1.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2017-11-29 10:46:37 CST; 18s ago Process: 6353 ExecStart=/sbin/runuser -l root -c /usr/bin/vncserver %i (code=exited, status=0/SUCCESS) Process: 6349 ExecStartPre=/usr/bin/vncserver -kill %i (code=exited, status=2) Main PID: 6375 (Xvnc) CGroup: /system.slice/system-vncserver.slice/vncserver@:1.service ‣ 6375 /usr/bin/Xvnc :1 -auth /root/.Xauthority -desktop server:1 (root) -fp catalogue:...
Nov 29 10:46:33 server systemd[1]: Starting Remote desktop service (VNC)... Nov 29 10:46:33 server vncserver[6349]: Can't find file /root/.vnc/server:1.pid Nov 29 10:46:33 server vncserver[6349]: You'll have to kill the Xvnc process manually Nov 29 10:46:37 server systemd[1]: Started Remote desktop service (VNC).
VNC服务使用的端口号与桌面号相关,VNC使用TCP端口从5900开始,对应关系如下:桌面号为“1” -- 端口号为5901 基于Java的VNC客户程序Web服务TCP端口从5800开始,也是与桌面号相关,对应关系如下:桌面号为“1” -- 端口号为5801
其实我们在虚拟机搭建的时候,我们最终关心的网卡是: eth0, br0, vnet0,vnet1…其中eth0是我们服务器原来的物理网卡,而br0是我们虚拟出来的网桥设备,而vnetX就是桥接映射到虚拟机里面用到的网卡。当配置完毕之后,我们使用ifconfig命令查看起来的话,会发现eth0是没有IP地址,而br0仿佛是虚拟出来的一个原来eth0的访问接口,它具有IP地址,可以代替原来的eth0被访问。而vnetX的地址可以在建立虚拟机之后在虚拟机里面配置,桥接后可以被外部访问。注意:将已有的物理网卡添加到网桥,此时物理网卡eth0工作于混杂模式,所以不需要IP地址,因为网桥是工作在链路层的。br0就提供了IP地址,用来模拟原来的物理网卡的访问接口。
[root@server ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet BOOTPROTO=none MASTER=bond0 SLAVE=yes NAME=eth0 DEVICE=eth0 ONBOOT=yes NM_CONTROLLED=no
[root@server ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0 BOOTPROTO=static ONBOOT=yes TYPE=Ethernet BRIDGE=br0
[root@server ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge BOOTPROTO=static IPADDR=192.168.10.30 NETMASK=255.255.255.0 GATEWAY=192.168.10.2 NM_CONTROLLED=no NAME=br0 DEVICE=br0 ONBOOT=yes
[root@server ~]# service network restart 4.VNC客户端连接: