Kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,自Linux 2.6.20之后集成在Linux的各个主要发行版本中。在本vmware workstation中部署centos7系统中进行搭建。
一、开启CPU虚拟化功能; ps:需要cpu支持虚拟化。
二、 KVM安装步骤
1.安装qemu-kvm和libvirt
[root@node1 ~]# yum install -y qemu-kvm libvirt #qemu-kvm用来创建虚拟机硬盘,libvirt用来管理虚拟机
2. 安装virt-install
[root@kvm-node1 ~]# yum install -y virt-install ###用来创建虚拟机
3.启动libvirtd
[root@node1 ~]#[root@node1 ~]# systemctl start libvirtd.service #启动服务
[root@node1 ~]# systemctl enable libvirtd.service #设置开机启动
[root@node1 ~]# ifconfig #使用ifconfig 会多出一块virbr0网卡;IP默认网段192.168.122.1./24,此时说明llibvirt
三、下面可以使用KVM创建虚拟机(Centos6.5)
1.使用qemu命令创建一个20G的硬盘(默认最小10G)硬盘名称为centos6.5.raw
[root@node1 opt]# qemu-img create -f raw /opt/centos6.5.raw 20G
Formatting '/opt/centos6.5.raw', fmt=raw size=21474836480
[root@node1 opt]# ll -h /opt/
total 0
-rw-r--r--. 1 root root 20G Oct 7 23:49 centos6.5.raw
2.使用virt-install创建Centos6.5_01的虚拟机,在创建虚拟机之前需要将centos6.5的iso镜像上传至/根目录下;注意:如果使用vnc管理我,部署多台虚拟机时要为其分配端口号;
[root@node1 opt]# virt-install --virt-type kvm --name CentOS-6.5-x86_64 --ram 1024 --cdrom=/CentOS-6.5-i386-bin-DVD1.iso --disk path=/opt/centos6.5.raw --network network=default --graphics vnc,port='5910',listen=0.0.0.0 --noautoconsole
Starting install...
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
3.查看虚拟机的状态; 此时虚拟机的状态是runing
[root@node1 opt]# virsh list --all
Id Name State
----------------------------------------------------
1 CentOS-6.5-x86_64 running
4.下载TightVNC Viewer
下载地址:https://www.tightvnc.com/download-old.php
5.VNC连接192.168.2.21
------------------------安装系统大家都会吧-------------------------------------------------------------------------------------------------------
-------完成安装---------
四、KVM的管理
[root@node1 opt]# virsh list --all #查看虚拟机列表
[root@node1 opt]# virsh start CentOS-6.5-x86_64 #启动虚拟机
[root@node1 opt]# vish shutdown kvm1 #关闭虚拟机 此时需要等待60秒
[root@node1]# virsh destroy KVM1 #强制关闭虚拟机 类是于断电;
[root@node1]# virsh undefine KVM1 #删除虚拟机;
[root@node1]# updatedb
[root@node1]# locate kvm1 #查看虚拟机文件rm -rf 删除查出的文件
五、webvirtmgr部署
更新yum源:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
运行yum makecache生成缓存
1.[root@node1]# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx #安装依赖包
有些依赖安装不上,这里需要注意重新安装;
2.下载https://github.com/retspen/webvirtmgr 代码