欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

安装KVM虚拟机--命令行模式

程序员文章站 2022-05-29 22:26:16
...

一、安装环境

[[email protected] ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

二、安装kvm

2.1 查看CPU是否支持kvm

显示vmx则支持

[[email protected] ~]# 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 \
python-virtinst \
libvirt \
libvirt-python \
virt-manager \
libguestfs-tools \
bridge-utils \
virt-install

2.4 查看安装结果

重启机器

shutdown -r now

查看kvm模块

[[email protected] ~]# lsmod | grep kvm
kvm_intel             183621  4 
kvm                   586948  1 kvm_intel
irqbypass              13503  3 kvm

启动kvm服务

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

三、安装Centos7.6系统

3.1 安装

创建磁盘、镜像目录

mkdir /home/{vms,iso}

上传系统镜像至镜像目录

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

查看自己的虚拟网卡名称

ip addr

一般都是virbr0

安装虚拟机

virt-install \
--virt-type=kvm \
--name=CentOS7-kvm1 \
--vcpus=2 \
--memory=2048 \
--location=/home/iso/CentOS-7-x86_64-DVD-1810.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 查看虚拟机

[[email protected] ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 2     CentOS7-kvm1                   running
相关标签: Kvm