一、安装环境

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

二、安装kvm

2.1 查看CPU是否支持kvm

显示vmx则支持

[root@localhost ~]# cat /proc/cpuinfo | grep -E -o 'vmx|svm'
vmx
vmx

2.2 关闭selinux

临时关闭

setenforce 0 

永久关闭

vi /etc/sysconfig/selinux
将 SELinux=enforcing 修改为 SELinux=disabled

2.3 安装kvm

yum install -y qemu-kvm \
qemu-kvm-tools \
qemu-img \
libvirt \
libvirt-python \
libvirt-client \
virt-manager \
virt-install \
virt-viewer \
bridge-utils \
libguestfs-tools \
python-virtinst

2.4 配置虚拟网卡

需要将KVM服务器的网卡配置成桥接模式,此处我的网卡是ens33,所以用br0来桥接ens33网卡
ens33网卡

[root@localhost iso]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
BRIDGE="br0"
NM_CONTROLLED="no"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="5c545cbb-8f0f-4707-976f-ab58f85a03c2"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.1.174"
PREFIX="24"
GATEWAY="192.168.1.1"
DNS1="192.168.1.1"
IPV6_PRIVACY="no"

br0 网卡

[root@localhost iso]# cat /etc/sysconfig/network-scripts/ifcfg-br0 
TYPE="Bridge"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="br0"
UUID="5c545cbb-8f0f-4707-976f-ab58f85a03c2"
DEVICE="br0"
ONBOOT="yes"
IPADDR="192.168.1.175"
PREFIX="24"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
DNS1="192.168.1.1"
IPV6_PRIVACY="no"

重启网络

systemctl restart network

2.5 查看安装结果

重启机器

shutdown -r now

查看kvm模块

[root@localhost iso]# lsmod | grep kvm
kvm_intel             183621  0 
kvm                   586948  1 kvm_intel
irqbypass              13503  1 kvm

启动kvm服务

systemctl start libvirtd && systemctl enable libvirtd && systemctl status libvirtd

三、安装Centos7.6系统

3.1 安装

创建磁盘、镜像目录

mkdir /home/{vms,iso}

上传系统镜像至镜像目录

我的镜像:CentOS-7-x86_64.iso

查看自己的虚拟网卡名称

ip addr

一般都是virbr0

安装虚拟机

virt-install \
--virt-type=kvm \
--name=CentOS7-kvm1 \
--vcpus=2 \
--memory=2048 \
--location=/home/iso/CentOS-7-x86_64.iso \
--disk path=/home/vms/centos78.qcow2,size=20,format=qcow2 \
--network bridge=virbr0 \
--graphics none \
--extra-args='console=ttyS0' \
--force

安装前配置

根据提示依次配置就行,x 代表不用设置 !代表需要确认 空白代表可选

Starting installer, one moment...
anaconda 21.48.22.147-1 for CentOS 7 started.
 * installation log files are stored in /tmp during the installation
 * shell is available on TTY2
 * when reporting a bug add logs from /tmp as separate text/plain attachments
08:54:06 Not asking for VNC because we don't have a network
================================================================================
================================================================================
Installation

 1) [x] Language settings                 2) [!] Time settings
        (English (United States))                (Timezone is not set.)
 3) [!] Installation source               4) [!] Software selection
        (Processing...)                          (Processing...)
 5) [!] Installation Destination          6) [x] Kdump
        (No disks selected)                      (Kdump is enabled)
 7) [ ] Network configuration             8) [!] Root password
        (Not connected)                          (Password is not set.)
 9) [!] User creation
        (No user will be created)
  Please make your choice from above ['q' to quit | 'b' to begin installation |
  'r' to refresh]: 

[anaconda] 1:main* 2:shell  3:log  4:storage-lo> Switch tab: Alt+Tab | Help: F1 

3.2 查看虚拟机

[root@localhost ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 2     CentOS7-kvm1                   running
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐