KVM是Kernel Virtual Machine的简写,目前Linux发行版必须在64位的系统环境才能运行KVM,同时硬件须要支持VT技术。node
KVM自Linux2.6.20版本后就直接整合到Linux内核,它依托CPU虚拟化指令集(如Intel-VT、AMD-V)实现高性能的虚拟化支持。因为与Linux内核高度整合,所以在性能、安全性、兼容性、稳定性上都有很好的表现。python
下图是一个简单的KVM虚拟化架构,在KVM环境中运行的每一个虚拟化操做系统都将表现位单个独立的系统进程。所以它能够 很方便地与Linux系统中的安全模块进行整合(SELinux),能够灵活地实现资源的管理及分配。vim
- Centos操做系统3台;
- Windiws 7操做系统1台;
所需镜像和工具请访问:https://pan.baidu.com/s/1fPhMgWJAjnmgJI5w267QCA
提取码:7x2pcentos
[root@centos01 ~]# cat /proc/cpuinfo | grep vmx flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch epb tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
[root@centos01 ~]# ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target <!--将命令行改成图形化运行,重启虚拟机便可生效--> [root@centos01 ~]# rm -rf /etc/yum.repos.d/CentOS-* <!--删除系统自动yum源--> [root@centos01 ~]# mount /dev/cdrom /mnt/ <!--挂载操做系统光盘--> mount: /dev/sr0 写保护,将以只读方式挂载 [root@centos01 ~]# rpm -qa | grep qemu-kvm <!--检查kvm模块是否安装--> qemu-kvm-1.5.3-141.el7.x86_64 qemu-kvm-common-1.5.3-141.el7.x86_64 [root@centos01 ~]# rpm -qa | grep qemu-kvm-tools<!--检查kvm调试工具是否安装--> [root@centos01 ~]# yum -y install qemu-kvm-tools <!--安装调试工具--> [root@centos01 ~]# rpm -qa | grep qemu-kvm-tools<!--检查kvm调试工具是否安装成功--> qemu-kvm-tools-1.5.3-141.el7.x86_64 [root@centos01 ~]# rpm -qa | grep virt-install <!--检查建立虚拟机工具是否安装--> [root@centos01 ~]# yum -y install virt-install <!--安装建立虚拟机工具--> [root@centos01 ~]# rpm -qa | grep virt-install<!--检查建立虚拟机工具是否安装成功--> virt-install-1.4.1-7.el7.noarch [root@centos01 ~]# rpm -qa | grep qemu-img<!--检查磁盘管理工具是否安装--> qemu-img-1.5.3-141.el7.x86_64 [root@centos01 ~]# rpm -qa | grep bridge-utils<!--检查网络工具是否安装--> bridge-utils-1.5-9.el7.x86_64 [root@centos01 ~]# rpm -qa | grep libvirt<!--检查虚拟机管理工具是否安装--> libvirt-daemon-driver-qemu-3.2.0-14.el7.x86_64 libvirt-client-3.2.0-14.el7.x86_64 libvirt-daemon-driver-interface-3.2.0-14.el7.x86_64 libvirt-daemon-driver-storage-disk-3.2.0-14.el7.x86_64 libvirt-daemon-driver-storage-3.2.0-14.el7.x86_64 libvirt-daemon-driver-storage-core-3.2.0-14.el7.x86_64 libvirt-daemon-driver-storage-mpath-3.2.0-14.el7.x86_64 libvirt-daemon-driver-storage-iscsi-3.2.0-14.el7.x86_64 libvirt-daemon-kvm-3.2.0-14.el7.x86_64 libvirt-daemon-driver-nodedev-3.2.0-14.el7.x86_64 libvirt-gconfig-1.0.0-1.el7.x86_64 libvirt-daemon-driver-storage-rbd-3.2.0-14.el7.x86_64 libvirt-daemon-driver-storage-scsi-3.2.0-14.el7.x86_64 libvirt-libs-3.2.0-14.el7.x86_64 libvirt-daemon-driver-network-3.2.0-14.el7.x86_64 libvirt-daemon-driver-nwfilter-3.2.0-14.el7.x86_64 libvirt-glib-1.0.0-1.el7.x86_64 libvirt-daemon-driver-storage-gluster-3.2.0-14.el7.x86_64 libvirt-daemon-3.2.0-14.el7.x86_64 libvirt-daemon-config-network-3.2.0-14.el7.x86_64 libvirt-gobject-1.0.0-1.el7.x86_64 libvirt-daemon-driver-storage-logical-3.2.0-14.el7.x86_64 libvirt-python-3.2.0-3.el7.x86_64 libvirt-daemon-driver-secret-3.2.0-14.el7.x86_64 [root@centos01 ~]# rpm -qa | grep virt-manager<!--检查图形管理虚拟机工具是否安装--> virt-manager-common-1.4.1-7.el7.noarch [root@centos01 ~]# yum -y install virt-manager<!--安装图形管理虚拟机工具--> [root@centos01 ~]# rpm -qa | grep virt-manager <!--检查图形管理虚拟机工具是否安装成功--> virt-manager-1.4.1-7.el7.noarch virt-manager-common-1.4.1-7.el7.noarch [root@centos01 ~]# lsmod | grep kvm <!--检查虚拟化模块是否开启--> kvm_intel 170086 0 kvm 566340 1 kvm_intel irqbypass 13503 1 kvm [root@centos01 ~]# systemctl start libvirtd <!--启动虚拟化服务--> [root@centos01 ~]# systemctl enable libvirtd <!-设置开机自动启动-->
[root@centos01 ~]# pwd <!--查看当前位置--> /root [root@centos01 ~]# ls <!--验证是否上传成功--> anaconda-ks.cfg CentOS-7.4-x86_64-1708.iso initial-setup-ks.cfg
[root@centos01 ~]# virt-manager
api
[root@centos01 ~]# virsh list --all Id 名称 状态 ---------------------------------------------------- 2 centos running
[root@centos01 ~]# virsh shutdown centos 域 centos 被关闭
[root@centos01 ~]# virsh start centos 域 centos 已开始
[root@centos01 ~]# virsh autostart centos 域 centos标记为自动开始
[root@centos01 ~]# virsh destroy centos 域 centos 被删除
[root@centos01 ~]# virsh suspend centos 域 centos 被挂起
[root@centos01 ~]# virsh resume centos 域 centos 被从新恢复
[root@centos01 ~]# virsh dumpxml centos > /etc/libvirt/qemu/centos01.xml
[root@centos01 ~]# virsh undefine centos 域 centos 已经被取消定义
[root@centos01 ~]# cd /etc/libvirt/qemu/ [root@centos01 qemu]# ls autostart centos01.xml networks
[root@centos01 qemu]# virsh define centos01.xml 定义域 centos(从 centos01.xml)
[root@centos01 ~]# virsh list --all Id 名称 状态 ---------------------------------------------------- 4 centos running
[root@centos01 ~]# vim /etc/libvirt/qemu/centos.xml [root@centos01 ~]# virsh edit centos
[root@centos01 ~]# virsh shutdown centos 域 centos 被关闭 [root@centos01 ~]# virt-clone -o centos -n centos02 -f /var/lib/libvirt/images/centos02.qcow2 正在分配 'centos02.qcow2' | 30 GB 00:11 成功克隆 'centos02'。
[root@centos01 ~]# virsh snapshot-create centos 已生成域快照 1574274181
[root@centos01 ~]# virsh snapshot-revert centos 1574274181
[root@centos01 ~]# virsh snapshot-list centos 名称 生成时间 状态 ------------------------------------------------------------ 1574274181 2019-11-21 02:23:01 +0800 shutoff
[root@centos01 ~]# virsh snapshot-delete centos 1574274181 已删除域快照 1574274181 [root@centos01 ~]# virsh snapshot-list centos 名称 生成时间 状态 ------------------------------------------------------------
—————— 本文至此结束,感谢阅读 ——————安全