一、安装前准备
1.环境准备
2.安装kvm前准备工作
(1). 确定处理器有 VT
命令行: grep vmx /proc/cpuinfo (INTEL 芯片 )
grep svm /proc/cpuinfo (AMD 芯片 )
cat /proc/cpuinfo | grep -e vmx -e nx -e svm
不知道芯片的生产厂商则输入:egrep ‘(vmx|svm)’ /proc/cpuinfo
如果 flags: 里有 vmx 或者 svm 就说明支持 VT ;如果没有任何的输出,说明你的 cpu 不支持,将无法成功安装 KVM 虚拟机。
(2). 当你硬件本身支持虚拟化,但查询相应参数无果时,请检查 BIOS 设定,确认你的 BIOS 中开启了硬件支持虚拟化的功能!
将如下选项设为Enabled
Intel® Virtualization Tech [Enabled]
[root@localhost ~]# egrep '(vmx|svm)' /proc/cpuinfo | wc -l
3.制作本地yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost bak]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv C* bak/
[root@localhost yum.repos.d]# vim 1.repo
[1repo]
name=myrepo
enabled=1
gpgcheck=0
baseurl=file:///mnt
[root@localhost yum.repos.d]# mount /dev/cdrom /mnt
[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: 1repo
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
1repo | 3.6 kB 00:00:00
(1/2): 1repo/group_gz | 166 kB 00:00:00
(2/2): 1repo/primary_db | 3.1 MB 00:00:00
源标识 源名称 状态
1repo myrepo 4,021
repolist: 4,021
[root@localhost yum.repos.d]# yum makecache
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
1repo | 3.6 kB 00:00:00
(1/2): 1repo/other_db | 1.3 MB 00:00:00
(2/2): 1repo/filelists_db | 3.2 MB 00:00:00
元数据缓存已建立
yum install kvm virt-manager libvirt libvirt-python python-virtinst libvirt-client qemu-kvm qemu-img
[root@localhost ~]# modprobe kvm
[root@localhost ~]# lsmod | grep kvm
kvm_intel 183621 0
kvm 586948 1 kvm_intel
irqbypass 13503 1 kvm
[root@localhost ~]# systemctl start libvirtd
[root@localhost ~]# systemctl enable libvirtd
[root@localhost ~]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: active (running) since 一 2019-05-27 16:51:03 CST; 32s ago
如出现
[root@localhost ~]# virsh list --all
Id 名称 状态
----------------------------------------------------
4.配置br0网桥
Vim ifcfg-ens33
TYPE=Ethernet
NAME=ens33
DEVICE=ens33
ONBOOT=yes
BRIDGE=br0
Vim ifcfg-br0
TYPE=Bridge
NAME=br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.254.20
PREFIX=24(NETMASK=255.255.255.0)
GATEWAY=192.168.254.1
DNS=192.168.254.251
[root@localhost network-scripts]# systemctl restart network
[root@localhost network-scripts]# ethtool br0
Settings for br0:
Link detected: yes
[root@localhost network-scripts]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29729056 no ens33
virbr0 8000.525400731acf yes virbr0-nic
[root@localhost network-scripts]# ifconfig br0
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.30.170 netmask 255.255.255.0 broadcast 192.168.30.255
inet6 fe80::c091:e1ff:fe6a:f448 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:72:90:56 txqueuelen 1000 (Ethernet)
RX packets 1630 bytes 149520 (146.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 146 bytes 20014 (19.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
不要用ssh工具直接在linux命令行中执行startx进入图形化界面
如果是英文界面可用下面方法汉化:
locale -a #查看是否装了中文包 没有执行下一行
yum install kde-l10n-Chinese -y
localectl set-locale LANG=zh_CN.UTF8
二、kvm虚拟机安装
应用程序——>系统工具——虚拟系统管理器
用ftp工具上传linux的系统镜像文件到主机
[root@localhost ~]# ls | grep CentOS
CentOS-7-x86_64-DVD-1810.iso
[root@localhost ~]# mv CentOS-7-x86_64-DVD-1810.iso /var/lib/libvirt/images/