KVM的环境配置及安装

来自CloudWiki
跳转至: 导航搜索

KVM环境配置

安装Centos

Vietual1-13.png

修改内核模式为兼容内核启动

[root@ localhost ~]# uname -a

Linux victory 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


[root@ localhost ~]#vim /boot/grub/grub.conf

将default=0修改为default=1

关闭SElinux,重启后生效

[root@ localhost ~]#vim /etc/sysconfig/selinux

# 修改SELINUX=disabled
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

关闭防火墙

[root@ localhost ~]#chkconfig ip6tables off

[root@ localhost ~]#chkconfig iptables off

重启

reboot

查看SELINUX更改效果:

[root@victory ~]# getenforce

Disabled


查看是否支持虚拟化

[root@localhost ~]# egrep -c '(vmx|svm)' /proc/cpuinfo

16

如果执行这条命令的返回结果为0则表示CPU不支持虚拟化,如果返回结果为1或者大于1到数字则表示CPU支持虚拟。其中vmx为Intel的CPU指令集,svm为AMD的CPU指令集。

安装KVM

安装KVM软件包

[root@localhost ~]# yum -y install kvm python-virtinst libvirt tunctl bridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v libguestfs-tools

  perl-Pod-Simple.x86_64 1:3.13-144.el6
  perl-Test-Harness.x86_64 0:3.17-144.el6
  perl-Test-Simple.x86_64 0:0.92-144.el6
  perl-devel.x86_64 4:5.10.1-144.el6
  perl-libs.x86_64 4:5.10.1-144.el6
  perl-version.x86_64 3:0.77-144.el6

Complete!

启动libvirt

https://baike.baidu.com/item/libvirt/2515334?fr=aladdin

[root@localhost ~]# /etc/init.d/libvirtd restart

Stopping libvirtd daemon:                                  [FAILED]
Starting libvirtd daemon: 2019-02-06 11:10:47.433+0000: 31229: info : libvirt vrsion: 0.10.2, package: 64.el6 (CentOS BuildSystem <http://bugs.centos.org>, 208-06-19-16:23:48, x86-01.bsys.centos.org)
2019-02-06 11:10:47.433+0000: 31229: warning : virGetHostname:2279 : getaddrinf failed for 'victory': Name or service not known
                                                           [  OK  ]
You have mail in /var/spool/mail/root

出现了一个warning,是由于域名缺乏解析的原因,我们来配一下。

vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.48       victory

vi /etc/resolv.conf

nameserver 114.114.114.114

[root@victory network-scripts]# service libvirtd restart

Stopping libvirtd daemon:                                  [  OK  ]
Starting libvirtd daemon:                                  [  OK  ]

可以看到这时警告消失。


libvirt常用命令

libvirt连接KVM

[root@localhost ~]# virsh -c qemu:///system list //用libvirt连接到超级管理程序

Id    Name                           State
----------------------------------------------------

[root@localhost ~]# lsmod |grep kvm // lsmod 命令:是一个小程序,用来显示文件、proc/modules的信息,也就是显示当前内核模块装载的模块

kvm_intel              54285  0 
kvm                   333172  1 kvm_intel

[root@localhost ~]# virsh --version

0.10.2

[root@localhost ~]# virt-install --version

0.600.0

[root@localhost ~]# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm //创建软链接