当前位置:网站首页 > 更多 > 站长帮 > 正文

[服务搭建] centos 7以上安装KVM

作者:CC下载站 日期:2019-10-23 08:13:23 浏览:2122 分类:站长帮

KVM是一个开源的硬件虚拟化软件,使我们可以通过他来创建多个linux、window的子系统。

下面将介绍如何在centos,Rhel上安装kvm.

  1. 首先检测cpu是否支持硬件虚拟化

在控制台输入一下命令

1grep -E '(vmx|svm)' /proc/cpuinfo

系统将返回vmx或svm  否则如果什么也没输出那么代表cpu不支持虚拟化。

2. 安装KVM以及相关组件

1yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils

3,开启并且运行libvirtd 服务

1systemctl start libvirtd1systemctl enable libvirtd

4,输入一下命令检测kvm是否加载成功

123[root@linuxtechi ~]# lsmod | grep kvmkvm_intel1621530kvm5254091 kvm_intel

5, 安装的mini版系统virt-manager不会自动启动。还需要安装

1yum install "@X Window System" xorg-x11-xauth xorg-x11-fonts-* xorg-x11-utils -y

6,重启系统

7,运行 virt-manager

[服务搭建] centos 7以上安装KVM

8,配置网络接口

配置网络接口则可链接网络

12cd /etc/sysconfig/network-scripts/cp ifcfg-eno49 ifcfg-br0

按照如下修改interface文件

1vi ifcfg-eno4912345TYPE=EthernetBOOTPROTO=staticDEVICE=eno49ONBOOT=yesBRIDGE=br0

修改ifcfg-br0文件

12345678910输入vi ifcfg-br0按照你实际的情况把IP地址 网关 dns修改TYPE=BridgeBOOTPROTO=staticDEVICE=br0ONBOOT=yesIPADDR=192.168.10.21NETMASK=255.255.255.0GATEWAY=192.168.10.1DNS1=192.168.10.11

重启网络

1systemctl restart network

检查一下网络

1ip addr show br0

8,创建虚拟机.

通过命令行virt-install 或者界面版的virt-manager来创建

先用virt-manager来创建一个Windows Server 2012 R2系统

输入virt-manager启动

通过File->new virtual machine创建

[服务搭建] centos 7以上安装KVM

选择ISO文件

[服务搭建] centos 7以上安装KVM

点击下一步,选择CPU和内存

[服务搭建] centos 7以上安装KVM

在点击下一步选择存储

[服务搭建] centos 7以上安装KVM

在点击下一步网络选择桥接

[服务搭建] centos 7以上安装KVM

点击完成后开始安装系统

[服务搭建] centos 7以上安装KVM

9或者通过命令行创建一个ubuntu系统

1234567virt-install --name=Ubuntu-16-04 --file=/var/lib/libvirt/images/ubuntu16-04.dsk --file-size=20 --nonsparse --graphics spice --vcpus=2 --ram=2048 --cdrom=ubuntu-16.04-server-amd64.iso --network bridge=br0 --os-type=linux --os-variant=generic看到如下界面Starting install...Allocating 'ubuntu16-04.dsk'| 20 GB 00:00:00Creating domain...

[服务搭建] centos 7以上安装KVM

下面是virt-install操作的相关命令

  • –name = <Name of the Virtual Machine>

  • –file = <Location where our virtual machine disk file will be stored >

  • –file-size = < Size of the Virtual Machine, in my case it is 20GB >

  • –nonsparse = < Allocate the whole storage while creating>

  • –graphics = < Specify the graphical tool for interactive installation, in above example I am using spice >

  • –vcpu = < Number of virtual CPU for the Machine >

  • –ram = < RAM size for the virtual Machine >

  • –cdrom = < Virtual CD ROM which specify the installation media like ISO file >

  • –network = < it is used to specify which network we will use for the virtual machine, in this example I am bridge interface>

  • –os-type = < Operating system type like linux and window>

  • –os-variant= <KVM maintains the OS variants like ‘fedora18′, ‘rhel6’ and ‘winxp’ , this option is optional and if you not sure about OS variant you can mentioned it as generic>

安装完成后可以通过virt-manager来管理

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯