KVM虚拟机安装与使用

安装

系统支持

# lscpu | grep vmx             
标记:              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb invpcid_single ibrs ibpb stibp kaiser tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp

安装

Centos

# sudo yum install virt-manager libvirt

Debian

# sudo apt-get install virt-manager
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
  augeas-lenses bridge-utils dmeventd ebtables freepats gir1.2-gtk-vnc-2.0 gir1.2-libosinfo-1.0
  gir1.2-libvirt-glib-1.0 gir1.2-spice-client-glib-2.0 gir1.2-spice-client-gtk-3.0
  gir1.2-vte-2.91 gstreamer1.0-libav gstreamer1.0-plugins-bad ipxe-qemu libaio1 libaugeas0
  libcacard0 libdca0 libde265-0 libdevmapper-event1.02.1 libfaad2 libfdt1 libgovirt-common
  libgovirt2 libgtk-vnc-2.0-0 libgvnc-1.0-0 libkate1 liblilv-0-0 liblvm2app2.2 liblvm2cmd2.02
  libmjpegutils-2.1-0 libmms0 libmodplug1 libmpcdec6 libmpeg2encpp-2.1-0 libmplex2-2.1-0
  libnetcf1 libofa0 libopencv-calib3d2.4v5 libopencv-features2d2.4v5 libopencv-flann2.4v5
  libopencv-highgui2.4-deb0 libopencv-objdetect2.4v5 libopencv-video2.4v5 libosinfo-1.0-0
  libphodav-2.0-0 libphodav-2.0-common librados2 librbd1 libreadline5 libserd-0-0 libsord-0-0
  libsoundtouch1 libspice-client-glib-2.0-8 libspice-client-gtk-3.0-5 libspice-server1
  libsratom-0-0 libsrtp0 libusbredirhost1 libusbredirparser1 libvdeplug2 libvirt-clients
  libvirt-daemon libvirt-daemon-system libvirt-glib-1.0-0 libvirt0 libvo-aacenc0 libvo-amrwbenc0
  libwildmidi-config libwildmidi2 libxen-4.8 libxenstore3.0 libxml2-utils libzbar0 lvm2
  netcat-openbsd osinfo-db python-gi-cairo python-ipaddr python-libvirt python-libxml2
  python-requests python-urllib3 qemu-kvm qemu-system-common qemu-system-x86 qemu-utils seabios
  spice-client-glib-usb-acl-helper virt-viewer virtinst
建议安装:
  augeas-doc frei0r-plugins augeas-tools libosinfo-l10n serdi sordi srtp-utils numad radvd
  auditd systemtap apparmor nfs-common zfsutils pm-utils thin-provisioning-tools python-socks
  python-ntlm samba vde2 qemu-block-extra sgabios ovmf debootstrap ssh-askpass gir1.2-secret-1
  python-guestfs
下列【新】软件包将被安装:
  augeas-lenses bridge-utils dmeventd ebtables freepats gir1.2-gtk-vnc-2.0 gir1.2-libosinfo-1.0
  gir1.2-libvirt-glib-1.0 gir1.2-spice-client-glib-2.0 gir1.2-spice-client-gtk-3.0
  gir1.2-vte-2.91 gstreamer1.0-libav gstreamer1.0-plugins-bad ipxe-qemu libaio1 libaugeas0
  libcacard0 libdca0 libde265-0 libdevmapper-event1.02.1 libfaad2 libfdt1 libgovirt-common
  libgovirt2 libgtk-vnc-2.0-0 libgvnc-1.0-0 libkate1 liblilv-0-0 liblvm2app2.2 liblvm2cmd2.02
  libmjpegutils-2.1-0 libmms0 libmodplug1 libmpcdec6 libmpeg2encpp-2.1-0 libmplex2-2.1-0
  libnetcf1 libofa0 libopencv-calib3d2.4v5 libopencv-features2d2.4v5 libopencv-flann2.4v5
  libopencv-highgui2.4-deb0 libopencv-objdetect2.4v5 libopencv-video2.4v5 libosinfo-1.0-0
  libphodav-2.0-0 libphodav-2.0-common librados2 librbd1 libreadline5 libserd-0-0 libsord-0-0
  libsoundtouch1 libspice-client-glib-2.0-8 libspice-client-gtk-3.0-5 libspice-server1
  libsratom-0-0 libsrtp0 libusbredirhost1 libusbredirparser1 libvdeplug2 libvirt-clients
  libvirt-daemon libvirt-daemon-system libvirt-glib-1.0-0 libvirt0 libvo-aacenc0 libvo-amrwbenc0
  libwildmidi-config libwildmidi2 libxen-4.8 libxenstore3.0 libxml2-utils libzbar0 lvm2
  netcat-openbsd osinfo-db python-gi-cairo python-ipaddr python-libvirt python-libxml2
  python-requests python-urllib3 qemu-kvm qemu-system-common qemu-system-x86 qemu-utils seabios
  spice-client-glib-usb-acl-helper virt-manager virt-viewer virtinst
升级了 0 个软件包,新安装了 92 个软件包,要卸载 0 个软件包,有 3 个软件包未被升级。
需要下载 63.9 MB/64.4 MB 的归档。
解压缩后会消耗 149 MB 的额外空间。
您希望继续执行吗? [Y/n] 

启动

# sudo systemctl enable libvirtd
# sudo systemctl start libvirtd

查看启动情况

# lsmod | grep kvm
kvm_intel             200704  0
kvm                   598016  1 kvm_intel
irqbypass              16384  1 kvm

安装虚拟机

开启图形界面工具

# virt-manager

命令行界面安装系统

配置网络环境

安装网桥配置工具

Debian

# sudo apt-get install bridge-utils