一:搭建KVM虚拟化平台

1、创建centos的虚拟机的时候进行编辑,处理器开启虚拟化功能

kkfileView linux arm架构安装 linux搭建kvm_操作系统


2、安装kvm插件

kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_02


kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_03


这是在安装系统的时候直接安装kvm组件,当然也可以通过yum命令或者其他的方式进行安装

--YUM命令安装:

安装插件:

yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install

安装图形化界面:

yum install -y virt-manager

systemctl enable libvirtd && systemctl start libvirtd #设置开机自启并且启动lbvired服务

3、禁用防火墙:

[root@localhost ~]#systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

关闭selinux:

[root@localhost ~]# vi /etc/selinux/config

将selinux设置为diabled,保存退出

kkfileView linux arm架构安装 linux搭建kvm_虚拟化_04


4、查看电脑是否支持虚拟化

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

VMX是英特尔处理器Svm是AMD处理器

kkfileView linux arm架构安装 linux搭建kvm_虚拟化_05


有输出即代表CPU支持虚拟化5、添加一块专门存放虚拟机镜像的的硬盘(需求看自己)

kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_06


添加之后还不能用,需要格式化

[root@localhost ~]# mkfs.ext4 /dev/sdb #使用ext4文件格式进行格式化

[root@localhost ~]# mkdir /ios #在根目录下创建一个挂载点目录

[root@localhost ~]# mount /dev/sdb /ios/ #将sdb挂载到该目录下,就可以使用了

[root@localhost ~]# df -h #查看一下是否挂载成功

kkfileView linux arm架构安装 linux搭建kvm_配置文件_07


[root@localhost ~]# vi /etc/fstab #开机自动挂载

kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_08

6、检查一下kvm模块是否被加载

[root@localhost ~]# lsmod | grep kvm

kkfileView linux arm架构安装 linux搭建kvm_虚拟化_09


如果没有输出结果,可以使用下面这条命令加载一下kvm模块

[root@localhost ~]# modprobe kvm7、到目前为止,kvm平台已经基本安装完成,接下来需要创建桥接网卡

编辑主机原网卡配置文件vi /etc/sysconfig/network-scripts/ifcfg-ens33,在文件末尾添加一行:BRIDGE="br0"

kkfileView linux arm架构安装 linux搭建kvm_配置文件_10


复制ifcfg-ens33配置文件并重命名为ifcfg-br0

[root@localhost network-scripts]# cp -rvf ifcfg-ens33 ifcfg-br0

修改ifcfg-br0配置文件

kkfileView linux arm架构安装 linux搭建kvm_运维_11


[root@localhost ~]# systemctl restart network #重启网络

kkfileView linux arm架构安装 linux搭建kvm_配置文件_12


可以看到ens33已经获取到了IP地址

8、基本操作

[root@localhost ~]# virt-manager #打开虚拟机管理器

双击QEMU/KVM

kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_13


9、创建一个镜像存储池,用来存放iso镜像文件

kkfileView linux arm架构安装 linux搭建kvm_虚拟化_14


10、给该存储池命名

kkfileView linux arm架构安装 linux搭建kvm_虚拟化_15


11、存储池所在的目录

kkfileView linux arm架构安装 linux搭建kvm_操作系统_16


kkfileView linux arm架构安装 linux搭建kvm_虚拟化_17


12、创建一个虚拟机

kkfileView linux arm架构安装 linux搭建kvm_操作系统_18


13、将iso文件上传到存储池所在的目录,然后单击“浏览”按钮选择镜像文件,再选择操作系统类型及版本

kkfileView linux arm架构安装 linux搭建kvm_虚拟化_19


14、创建磁盘镜像的大小

kkfileView linux arm架构安装 linux搭建kvm_运维_20


如果磁盘不够可以稍微给小一点

kkfileView linux arm架构安装 linux搭建kvm_运维_21


kkfileView linux arm架构安装 linux搭建kvm_配置文件_22


至此,一台虚拟机就创建完成一:kvm虚拟机的基本操作

(1)查看虚拟机的硬件

点击像小灯泡一样的按钮,可查看到虚拟机硬件信息

kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_23


kkfileView linux arm架构安装 linux搭建kvm_运维_24


(2)添加硬件

单击“Add Hardware” 后根据实际情况添加硬件

kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_25


(3)克隆虚拟机

克隆之前一定要关闭虚拟机,否则不会成功,右键你要克隆的虚拟机,单击clone

kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_26


kkfileView linux arm架构安装 linux搭建kvm_数据结构与算法_27


二:使用KVM命令管理虚拟机

Virsh命令

virsh list --all

查看在运行的所有的虚拟机

virsh dumpxml vm-name

查看kvm虚拟机配置文件

virsh start vm-name

启动kvm虚拟机

virsh shutdown vm-name

正常关机

virsh destroy vm-name
强制关机
virsh undefine vm-name
删除vm的配置文件

virsh define file-name.xml
根据配置文件定义虚拟机
virsh suspend vm-name
挂起虚拟机
virsh resumed vm-name
恢复被挂起的虚拟机
virsh snapshot-create
创建快照
virt-df  -h  vm-name
查看虚拟机的磁盘信息
virt-clone  -o rhel7.0  -n  rhel7.0-01  -f  /var/rhel7.0-01.qcow2
克隆虚拟机

virsh snapshot-create rhel7.0
创建快照(格式必须是qcow2)
virsh  snapshot-list rhel7.0
Name Creation Time State

1537275180 2018-09-18 20:53:00 +0800 running

查看快照信息(如果要恢复的话或者删除必须要看名称是什么)
virsh  snapshot-revert rhel7.0 1537275180
恢复快照
virsh  snapshot-delete rhel7.0 1537275180
删除快照


https://blog.51cto.com/brighttime/2176928