云计算虚拟机技术-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=4163mtu 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 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 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 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 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>.