雲計算虛擬機技術-KVM安裝
作者:尹正傑
版權聲明:原創作品,謝絕轉載!否則將追究法律責任。
身為運維的小伙伴估計大家都清楚KVM,因為在CentOS里面KVM還算很折騰的一個軟件,早期CentOS使用的xen虛擬化,后因收購KVM,於是就把KVM替換掉了xen,因此KVM主鍵走入運維的眼簾。
我之前分析過連篇關於KVM的筆記,分別是:虛擬化技術之KVM和KVM使用入門。里面的操作環境都是基於CentOS6.x系列的。最近在CentOS7.x的操作系統上也搗鼓過一番,由此把倒騰的筆記記錄一下,方便我日后查看。
一.開啟虛擬機支持硬件虛擬化
1>.開啟宿主機主板上的虛擬化支持
首先開啟虛擬化,需要CPU支持虛擬化才行; 1>.開機時按Del鍵或者F2鍵進入BIOS系統; 注:一般開機時系統下會有提示,根據提示按相應的鍵進入BIOS系統。 2>.選擇Configuratio選項卡,光標移到Intel Virtual Technology,按回車鍵,選擇Enabled,按回車鍵;
注:主板不一樣,BIOS中的菜單選項不一樣,主要是找到Virtual或Virtualization將其設置為Enabled。
2>.啟動虛擬機實例前配置
我們知道KVM在使用的時候必須是硬件支持虛擬化的,因此在使用之前,我們要確保我們使用的虛擬機實例是否支持硬件虛擬化技術。不推薦使用開源的virtualbox,因為它不支持在虛擬機再次使用虛擬化技術。而我推薦使用vmware workstation軟件。因為他支持在虛擬機里面繼續支持虛擬化操作。只需要我們在啟動虛擬機實例時開啟該功能即可,如下圖所示。
3>.檢查虛擬機實例是否支持硬件虛擬機技術
我們只需要在命令行中輸入:“ grep --color -Ei "vmx|svm" /proc/cpuinfo ”如果有輸出則說明支持硬件虛擬機技術,如果沒有輸出說明你當前環境是不支持硬件虛擬化的喲。(注意,其中vmx表示INTER系列CPU支持的類型,svm表示ADM系列CPU支持的類型。)

[root@node105 ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@node105 ~]# [root@node105 ~]# grep --color -Ei "vmx|svm" /proc/cpuinfo 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 ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase tsc_adjust smep 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 ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm ida arat epb pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase tsc_adjust smep [root@node105 ~]# [root@node105 ~]#
4>.手動加載kvm內核
事實上只要你安裝了CentOs6.x系列往后的任何操作系統版本,想使用KVM虛擬機不需要安裝任何組件(因為KVM是一個內置模塊),只要編譯時這個模塊被編譯了,那么一定是支持相關虛擬化的,否則只能重新編譯內核。

[root@node105 ~]# grep -i "kvm" /boot/config-3.10.0-327.el7.x86_64 CONFIG_KVM_GUEST=y # CONFIG_KVM_DEBUG_FS is not set CONFIG_HAVE_KVM=y CONFIG_HAVE_KVM_IRQCHIP=y CONFIG_HAVE_KVM_IRQFD=y CONFIG_HAVE_KVM_IRQ_ROUTING=y CONFIG_HAVE_KVM_EVENTFD=y CONFIG_KVM_APIC_ARCHITECTURE=y CONFIG_KVM_MMIO=y CONFIG_KVM_ASYNC_PF=y CONFIG_HAVE_KVM_MSI=y CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT=y CONFIG_KVM_VFIO=y CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT=y CONFIG_KVM=m CONFIG_KVM_INTEL=m CONFIG_KVM_AMD=m CONFIG_KVM_MMU_AUDIT=y # CONFIG_KVM_DEVICE_ASSIGNMENT is not set [root@node105 ~]# [root@node105 ~]# [root@node105 ~]# modprobe kvm [root@node105 ~]# [root@node105 ~]# lsmod | grep kvm kvm_intel 162153 0 kvm 525259 1 kvm_intel [root@node105 ~]# [root@node105 ~]#
二.KVM安裝
1>.安裝KVM相關管理工具
qemu-kvm是KVM在用戶空間的管理工具。libvirt是用來管理KVM虛擬機的。

[root@node105 ~]# yum -y install qemu-kvm libvirt ..... libvirt-daemon.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-config-network.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-config-nwfilter.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-interface.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-lxc.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-network.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-nodedev.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-nwfilter.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-qemu.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-secret.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage-core.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage-disk.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage-gluster.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage-iscsi.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage-logical.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage-mpath.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage-rbd.x86_64 0:4.5.0-10.el7_6.4 libvirt-daemon-driver-storage-scsi.x86_64 0:4.5.0-10.el7_6.4 libvirt-libs.x86_64 0:4.5.0-10.el7_6.4 libvorbis.x86_64 1:1.3.3-8.el7.1 libxcb.x86_64 0:1.13-1.el7 libxslt.x86_64 0:1.1.28-5.el7 lvm2.x86_64 7:2.02.180-10.el7_6.3 lvm2-libs.x86_64 7:2.02.180-10.el7_6.3 lz4.x86_64 0:1.7.5-2.el7 lzop.x86_64 0:1.03-10.el7 netcf-libs.x86_64 0:0.2.8-4.el7 nfs-utils.x86_64 1:1.3.0-0.61.el7 nmap-ncat.x86_64 2:6.40-16.el7 numad.x86_64 0:0.5-18.20150602git.el7 opus.x86_64 0:1.0.2-6.el7 pciutils.x86_64 0:3.5.1-3.el7 perl.x86_64 4:5.16.3-294.el7_6 perl-Carp.noarch 0:1.26-244.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-Pod-Escapes.noarch 1:1.04-294.el7_6 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-294.el7_6 perl-macros.x86_64 4:5.16.3-294.el7_6 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 pixman.x86_64 0:0.34.0-1.el7 pulseaudio-libs.x86_64 0:10.0-5.el7 qemu-img.x86_64 10:1.5.3-160.el7_6.1 qemu-kvm-common.x86_64 10:1.5.3-160.el7_6.1 quota.x86_64 1:4.01-17.el7 quota-nls.noarch 1:4.01-17.el7 radvd.x86_64 0:2.17-3.el7 rdma-core.x86_64 0:17.2-3.el7 rpcbind.x86_64 0:0.2.0-47.el7 seabios-bin.noarch 0:1.11.0-2.el7 seavgabios-bin.noarch 0:1.11.0-2.el7 sgabios-bin.noarch 1:0.20110622svn-4.el7 spice-server.x86_64 0:0.14.0-6.el7_6.1 tcp_wrappers.x86_64 0:7.6-77.el7 unbound-libs.x86_64 0:1.6.6-1.el7 usbredir.x86_64 0:0.7.1-3.el7 yajl.x86_64 0:2.0.4-4.el7 Updated: selinux-policy.noarch 0:3.13.1-229.el7_6.9 systemd.x86_64 0:219-62.el7_6.3 Dependency Updated: cryptsetup-libs.x86_64 0:2.0.3-3.el7 cyrus-sasl-lib.x86_64 0:2.1.26-23.el7 dbus.x86_64 1:1.10.24-12.el7 dbus-libs.x86_64 1:1.10.24-12.el7 device-mapper.x86_64 7:1.02.149-10.el7_6.3 device-mapper-libs.x86_64 7:1.02.149-10.el7_6.3 gnutls.x86_64 0:3.3.29-8.el7 krb5-libs.x86_64 0:1.15.1-37.el7_6 libgudev1.x86_64 0:219-62.el7_6.3 libnl3.x86_64 0:3.2.28-4.el7 libselinux.x86_64 0:2.5-14.1.el7 libselinux-python.x86_64 0:2.5-14.1.el7 libselinux-utils.x86_64 0:2.5-14.1.el7 libsemanage.x86_64 0:2.5-14.el7 libsepol.x86_64 0:2.5-10.el7 libtasn1.x86_64 0:4.10-1.el7 p11-kit.x86_64 0:0.23.5-3.el7 p11-kit-trust.x86_64 0:0.23.5-3.el7 pciutils-libs.x86_64 0:3.5.1-3.el7 policycoreutils.x86_64 0:2.5-29.el7_6.1 selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.9 systemd-libs.x86_64 0:219-62.el7_6.3 systemd-sysv.x86_64 0:219-62.el7_6.3 Complete! [root@node105 ~]#
virt-install是KVM用來安裝虛擬機用的。

[root@node105 ~]# yum -y install virt-install Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn * extras: ftp.sjtu.edu.cn * updates: mirror.lzu.edu.cn Resolving Dependencies --> Running transaction check ---> Package virt-install.noarch 0:1.5.0-1.el7 will be installed --> Processing Dependency: virt-manager-common = 1.5.0-1.el7 for package: virt-install-1.5.0-1.el7.noarch --> Running transaction check ---> Package virt-manager-common.noarch 0:1.5.0-1.el7 will be installed --> Processing Dependency: libvirt-python >= 0.7.0 for package: virt-manager-common-1.5.0-1.el7.noarch --> Processing Dependency: libosinfo >= 0.2.11 for package: virt-manager-common-1.5.0-1.el7.noarch --> Processing Dependency: python-requests for package: virt-manager-common-1.5.0-1.el7.noarch --> Processing Dependency: python-ipaddr for package: virt-manager-common-1.5.0-1.el7.noarch --> Processing Dependency: libxml2-python for package: virt-manager-common-1.5.0-1.el7.noarch --> Processing Dependency: genisoimage for package: virt-manager-common-1.5.0-1.el7.noarch --> Running transaction check ---> Package genisoimage.x86_64 0:1.1.11-25.el7 will be installed --> Processing Dependency: libusal = 1.1.11-25.el7 for package: genisoimage-1.1.11-25.el7.x86_64 --> Processing Dependency: libusal.so.0()(64bit) for package: genisoimage-1.1.11-25.el7.x86_64 --> Processing Dependency: librols.so.0()(64bit) for package: genisoimage-1.1.11-25.el7.x86_64 ---> Package libosinfo.x86_64 0:1.1.0-2.el7 will be installed --> Processing Dependency: osinfo-db-tools for package: libosinfo-1.1.0-2.el7.x86_64 --> Processing Dependency: osinfo-db for package: libosinfo-1.1.0-2.el7.x86_64 ---> Package libvirt-python.x86_64 0:4.5.0-1.el7 will be installed ---> Package libxml2-python.x86_64 0:2.9.1-6.el7_2.3 will be installed --> Processing Dependency: libxml2 = 2.9.1-6.el7_2.3 for package: libxml2-python-2.9.1-6.el7_2.3.x86_64 ---> Package python-ipaddr.noarch 0:2.1.11-1.el7 will be installed ---> Package python-requests.noarch 0:2.6.0-1.el7_1 will be installed --> Processing Dependency: python-urllib3 >= 1.10.2-1 for package: python-requests-2.6.0-1.el7_1.noarch --> Processing Dependency: python-chardet >= 2.2.1-1 for package: python-requests-2.6.0-1.el7_1.noarch --> Running transaction check ---> Package libusal.x86_64 0:1.1.11-25.el7 will be installed ---> Package libxml2.x86_64 0:2.9.1-5.el7_1.2 will be updated ---> Package libxml2.x86_64 0:2.9.1-6.el7_2.3 will be an update ---> Package osinfo-db.noarch 0:20181214-1.el7_6 will be installed ---> Package osinfo-db-tools.x86_64 0:1.1.0-1.el7 will be installed --> Processing Dependency: libarchive.so.13()(64bit) for package: osinfo-db-tools-1.1.0-1.el7.x86_64 ---> Package python-chardet.noarch 0:2.2.1-1.el7_1 will be installed ---> Package python-urllib3.noarch 0:1.10.2-5.el7 will be installed --> Processing Dependency: python-six for package: python-urllib3-1.10.2-5.el7.noarch --> Processing Dependency: python-ipaddress for package: python-urllib3-1.10.2-5.el7.noarch --> Processing Dependency: python-backports-ssl_match_hostname for package: python-urllib3-1.10.2-5.el7.noarch --> Running transaction check ---> Package libarchive.x86_64 0:3.1.2-10.el7_2 will be installed ---> Package python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7 will be installed --> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch ---> Package python-ipaddress.noarch 0:1.0.16-2.el7 will be installed ---> Package python-six.noarch 0:1.9.0-2.el7 will be installed --> Running transaction check ---> Package python-backports.x86_64 0:1.0-8.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================================================= Installing: virt-install noarch 1.5.0-1.el7 base 94 k Installing for dependencies: genisoimage x86_64 1.1.11-25.el7 base 299 k libarchive x86_64 3.1.2-10.el7_2 base 318 k libosinfo x86_64 1.1.0-2.el7 base 228 k libusal x86_64 1.1.11-25.el7 base 136 k libvirt-python x86_64 4.5.0-1.el7 base 343 k libxml2-python x86_64 2.9.1-6.el7_2.3 base 247 k osinfo-db noarch 20181214-1.el7_6 updates 177 k osinfo-db-tools x86_64 1.1.0-1.el7 base 79 k python-backports x86_64 1.0-8.el7 base 5.8 k python-backports-ssl_match_hostname noarch 3.5.0.1-1.el7 base 13 k python-chardet noarch 2.2.1-1.el7_1 base 227 k python-ipaddr noarch 2.1.11-1.el7 base 35 k python-ipaddress noarch 1.0.16-2.el7 base 34 k python-requests noarch 2.6.0-1.el7_1 base 94 k python-six noarch 1.9.0-2.el7 base 29 k python-urllib3 noarch 1.10.2-5.el7 base 102 k virt-manager-common noarch 1.5.0-1.el7 base 1.2 M Updating for dependencies: libxml2 x86_64 2.9.1-6.el7_2.3 base 668 k Transaction Summary ============================================================================================================================================================================================= Install 1 Package (+17 Dependent packages) Upgrade ( 1 Dependent package) Total download size: 4.2 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/19): genisoimage-1.1.11-25.el7.x86_64.rpm | 299 kB 00:00:00 (2/19): libosinfo-1.1.0-2.el7.x86_64.rpm | 228 kB 00:00:00 (3/19): libarchive-3.1.2-10.el7_2.x86_64.rpm | 318 kB 00:00:00 (4/19): libvirt-python-4.5.0-1.el7.x86_64.rpm | 343 kB 00:00:00 (5/19): libxml2-2.9.1-6.el7_2.3.x86_64.rpm | 668 kB 00:00:00 (6/19): libusal-1.1.11-25.el7.x86_64.rpm | 136 kB 00:00:00 (7/19): osinfo-db-tools-1.1.0-1.el7.x86_64.rpm | 79 kB 00:00:00 (8/19): libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm | 247 kB 00:00:00 (9/19): python-backports-1.0-8.el7.x86_64.rpm | 5.8 kB 00:00:00 (10/19): python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm | 13 kB 00:00:00 (11/19): python-ipaddr-2.1.11-1.el7.noarch.rpm | 35 kB 00:00:00 (12/19): python-ipaddress-1.0.16-2.el7.noarch.rpm | 34 kB 00:00:00 (13/19): python-chardet-2.2.1-1.el7_1.noarch.rpm | 227 kB 00:00:00 (14/19): python-requests-2.6.0-1.el7_1.noarch.rpm | 94 kB 00:00:00 (15/19): python-six-1.9.0-2.el7.noarch.rpm | 29 kB 00:00:00 (16/19): osinfo-db-20181214-1.el7_6.noarch.rpm | 177 kB 00:00:00 (17/19): python-urllib3-1.10.2-5.el7.noarch.rpm | 102 kB 00:00:00 (18/19): virt-install-1.5.0-1.el7.noarch.rpm | 94 kB 00:00:00 (19/19): virt-manager-common-1.5.0-1.el7.noarch.rpm | 1.2 MB 00:00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 5.3 MB/s | 4.2 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : libxml2-2.9.1-6.el7_2.3.x86_64 1/20 Installing : python-ipaddress-1.0.16-2.el7.noarch 2/20 Installing : libxml2-python-2.9.1-6.el7_2.3.x86_64 3/20 Installing : libarchive-3.1.2-10.el7_2.x86_64 4/20 Installing : osinfo-db-tools-1.1.0-1.el7.x86_64 5/20 Installing : osinfo-db-20181214-1.el7_6.noarch 6/20 Installing : libosinfo-1.1.0-2.el7.x86_64 7/20 Installing : libvirt-python-4.5.0-1.el7.x86_64 8/20 Installing : python-six-1.9.0-2.el7.noarch 9/20 Installing : python-backports-1.0-8.el7.x86_64 10/20 Installing : python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch 11/20 Installing : python-urllib3-1.10.2-5.el7.noarch 12/20 Installing : python-chardet-2.2.1-1.el7_1.noarch 13/20 Installing : python-requests-2.6.0-1.el7_1.noarch 14/20 Installing : libusal-1.1.11-25.el7.x86_64 15/20 Installing : genisoimage-1.1.11-25.el7.x86_64 16/20 Installing : python-ipaddr-2.1.11-1.el7.noarch 17/20 Installing : virt-manager-common-1.5.0-1.el7.noarch 18/20 Installing : virt-install-1.5.0-1.el7.noarch 19/20 Cleanup : libxml2-2.9.1-5.el7_1.2.x86_64 20/20 Verifying : osinfo-db-tools-1.1.0-1.el7.x86_64 1/20 Verifying : libosinfo-1.1.0-2.el7.x86_64 2/20 Verifying : python-ipaddr-2.1.11-1.el7.noarch 3/20 Verifying : python-urllib3-1.10.2-5.el7.noarch 4/20 Verifying : libxml2-2.9.1-6.el7_2.3.x86_64 5/20 Verifying : libusal-1.1.11-25.el7.x86_64 6/20 Verifying : python-chardet-2.2.1-1.el7_1.noarch 7/20 Verifying : python-requests-2.6.0-1.el7_1.noarch 8/20 Verifying : libxml2-python-2.9.1-6.el7_2.3.x86_64 9/20 Verifying : libarchive-3.1.2-10.el7_2.x86_64 10/20 Verifying : python-backports-1.0-8.el7.x86_64 11/20 Verifying : python-six-1.9.0-2.el7.noarch 12/20 Verifying : libvirt-python-4.5.0-1.el7.x86_64 13/20 Verifying : virt-install-1.5.0-1.el7.noarch 14/20 Verifying : python-ipaddress-1.0.16-2.el7.noarch 15/20 Verifying : virt-manager-common-1.5.0-1.el7.noarch 16/20 Verifying : genisoimage-1.1.11-25.el7.x86_64 17/20 Verifying : osinfo-db-20181214-1.el7_6.noarch 18/20 Verifying : python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch 19/20 Verifying : libxml2-2.9.1-5.el7_1.2.x86_64 20/20 Installed: virt-install.noarch 0:1.5.0-1.el7 Dependency Installed: genisoimage.x86_64 0:1.1.11-25.el7 libarchive.x86_64 0:3.1.2-10.el7_2 libosinfo.x86_64 0:1.1.0-2.el7 libusal.x86_64 0:1.1.11-25.el7 libvirt-python.x86_64 0:4.5.0-1.el7 libxml2-python.x86_64 0:2.9.1-6.el7_2.3 osinfo-db.noarch 0:20181214-1.el7_6 osinfo-db-tools.x86_64 0:1.1.0-1.el7 python-backports.x86_64 0:1.0-8.el7 python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7 python-chardet.noarch 0:2.2.1-1.el7_1 python-ipaddr.noarch 0:2.1.11-1.el7 python-ipaddress.noarch 0:1.0.16-2.el7 python-requests.noarch 0:2.6.0-1.el7_1 python-six.noarch 0:1.9.0-2.el7 python-urllib3.noarch 0:1.10.2-5.el7 virt-manager-common.noarch 0:1.5.0-1.el7 Dependency Updated: libxml2.x86_64 0:2.9.1-6.el7_2.3 Complete! [root@node105 ~]#
2>.啟動libvirt服務

[root@node105 ~]# systemctl enable libvirtd [root@node105 ~]# [root@node105 ~]# systemctl start libvirtd [root@node105 ~]# [root@node105 ~]# systemctl status libvirtd ● libvirtd.service - Virtualization daemon Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2019-02-17 22:47:01 CST; 7s ago Docs: man:libvirtd(8) https://libvirt.org Main PID: 13624 (libvirtd) CGroup: /system.slice/libvirtd.service ├─13624 /usr/sbin/libvirtd ├─13795 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper └─13796 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper Feb 17 22:47:02 node105.yinzhengjie.org.cn libvirtd[13624]: 2019-02-17 14:47:02.207+0000: 13642: warning : virQEMUCapsLogProbeFailure:4536 : Failed to probe capabilities for /usr/libexec... Feb 17 22:47:02 node105.yinzhengjie.org.cn libvirtd[13624]: 2019-02-17 14:47:02.257+0000: 13642: warning : virLXCDriverCapsInit:82 : Failed to get host CPU cache info Feb 17 22:47:02 node105.yinzhengjie.org.cn dnsmasq[13795]: started, version 2.66 cachesize 150 Feb 17 22:47:02 node105.yinzhengjie.org.cn dnsmasq[13795]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth Feb 17 22:47:02 node105.yinzhengjie.org.cn dnsmasq-dhcp[13795]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h Feb 17 22:47:02 node105.yinzhengjie.org.cn dnsmasq[13795]: reading /etc/resolv.conf Feb 17 22:47:02 node105.yinzhengjie.org.cn dnsmasq[13795]: using nameserver 172.30.1.254#53 Feb 17 22:47:02 node105.yinzhengjie.org.cn dnsmasq[13795]: read /etc/hosts - 5 addresses Feb 17 22:47:02 node105.yinzhengjie.org.cn dnsmasq[13795]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses Feb 17 22:47:02 node105.yinzhengjie.org.cn dnsmasq-dhcp[13795]: read /var/lib/libvirt/dnsmasq/default.hostsfile Hint: Some lines were ellipsized, use -l to show in full. [root@node105 ~]# [root@node105 ~]#

[root@node105 ~]# yum -y install net-tools Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.sjtu.edu.cn * extras: ftp.sjtu.edu.cn * updates: mirror.lzu.edu.cn Resolving Dependencies --> Running transaction check ---> Package net-tools.x86_64 0:2.0-0.24.20131004git.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================================================================= Installing: net-tools x86_64 2.0-0.24.20131004git.el7 base 306 k Transaction Summary ============================================================================================================================================================================================= Install 1 Package Total download size: 306 k Installed size: 918 k Downloading packages: net-tools-2.0-0.24.20131004git.el7.x86_64.rpm | 306 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1 Verifying : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1 Installed: net-tools.x86_64 0:2.0-0.24.20131004git.el7 Complete! [root@node105 ~]#
[root@node105 ~]# ifconfig eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.30.1.105 netmask 255.255.255.0 broadcast 172.30.1.255 inet6 fe80::20c:29ff:fe38:e29c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:38:e2:9c txqueuelen 1000 (Ethernet) RX packets 55421 bytes 77010056 (73.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 25561 bytes 2723550 (2.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 4 bytes 340 (340.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4 bytes 340 (340.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 #大家把眼力勁看向這里,這塊網卡是由於咱們安裝了libvirtd軟件時創建了這塊虛擬網卡!我們可以看到這塊虛擬機的ip地址。 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 00:00:00:00:00:00 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@node105 ~]# [root@node105 ~]#
3>.將你需要安裝虛擬機的iso通過scp或者rz等工具上傳到服務器上
[root@node105 ~]# ll -h /root/iso/ total 603M -rw-r--r--. 1 root root 603M May 13 2018 CentOS-7-x86_64-Minimal-1511.iso [root@node105 ~]# [root@node105 ~]#
4>.創建一個raw格式10G大小的虛擬機磁盤
[root@node105 ~]# ll -h /root/iso/ total 603M -rw-r--r--. 1 root root 603M May 13 2018 CentOS-7-x86_64-Minimal-1511.iso [root@node105 ~]# [root@node105 ~]# qemu-img create -f raw /home/yinzhengjie/CentOS-7-x86_64.raw 10G Formatting '/home/yinzhengjie/CentOS-7-x86_64.raw', fmt=raw size=10737418240 [root@node105 ~]#
5>.創建虛擬機
[root@node105 ~]# virt-install --virt-type kvm \ #指定虛擬機的類型 > --name Yinzhengjie-CentOS-7-x86_64 \ #指定虛擬機的名稱 > --ram 1024 \ #指定內存大小為1GB,默認單位是MB > --cdrom=/root/iso/CentOS-7-x86_64-Minimal-1511.iso \ #指定光盤的路徑 > --disk path=/home/yinzhengjie/CentOS-7-x86_64.raw \ #指定你創建磁盤的路徑 > --network network=default \ #指定網絡 > --graphics vnc,listen=0.0.0.0 \ #指定連接方式為VNC,監聽模式指定所有的網卡 > --noautoconsole
6>.使用VNC連接工具鏈接到你的虛擬機上
7>.
8>.