- Check system version
[root@openstack ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
- First, verify that the CPU supports virtualization, vmx or svm have input on the support, the support virtualization to support KVM
[root@openstack ~]# cat /proc/cpuinfo | egrep 'vmx|svm'
===========================================
3. Check whether the load KVM
[root@openstack ~]# lsmod | grep kvm
kvm_intel 170086 0
kvm 566340 1 kvm_intel
irqbypass 13503 1 kvm
This shows that has been loaded, if not loaded then execute the following command to load KVM
[root@openstack ~]# modprobe kvm
=============================================
- Close selinux
[root@openstack ~]# setenforce 0
[root@openstack ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
- KVM installation related packages
[root@openstack ~]# yum install qemu-kvm qemu-img virt-manager \
libvirt libvirt-python virt-manager \
libvirt-client virt-install virt-viewer -y
Explain the package name:
QEMU-KVM: KVM module
libvirt: a virtual management module
virt-manager: a graphical interface for managing virtual machines
virt-install: Virtual Machine command-line installation tool
- Libvirt start and set the boot from the start
[root@openstack ~]# systemctl start libvirtd
[root@openstack ~]# systemctl enable libvirtd
7. Enter graphical (enter on behalf of half the battle!)
[root@openstack ~]# virt-manager
8. The back-end disk files, virtual machine template configuration files, network configuration files are copied into the need to create a virtual machine on a physical machine! !
scp /..../... ip:/..../.....
9. Configure virtual network
Step one: create a virtual network called the vbr
[root@room9pc01 ~]# vim /etc/libvirt/qemu/networks/vbr.xml
<network>
<name>vbr</name> //vbr为虚拟网络的名字
<bridge name="vbr"/>
<forward mode="nat"/>
<ip address="192.168.1.254" netmask="255.255.255.0"> //本机网关ip为192.168.1.254
<dhcp>
<range start="192.168.1.100" end="192.168.1.200"/> //虚拟机DHCP获取ip范围是100-200
</dhcp>
</ip>
</network>
Step Two: Start vbr virtual network and verify with ifconfig
[root@room9pc01 ~]# virsh net-define /etc/libvirt/qemu/networks/vbr.xml //定义vbr虚拟网络,加载进virsh中
[root@room9pc01 ~]# virsh net-start vbr //启动vbr虚拟网络
[root@room9pc01 ~]# ifconfig //ifconfig验证
vbr: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.254 netmask 255.255.255.0 broadcast 192.168.1.255
ether 52:54:00:b7:1c:10 txqueuelen 1000 (Ethernet)
RX packets 2460 bytes 176958 (172.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1948 bytes 532542 (520.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
================================================== ==============
start virtual network problems may arise:
When open network vbr tips are as follows:
The name org.fedoraproject.FirewallD1 was not provided by any .service files
Approach: libvirtd service to restart
systemctl restart libvirtd
================================================================
Step three: Set vbr virtual network boot from the start
[root@room9pc01 ~]# virsh net-autostart vbr
10. Configure virtual machine storage file
Creating a new front end with back-end disk disk image file template
[root@room9pc01 ~]# cd /var/lib/libvirt/images/
[root@room9pc01 images]# qemu-img create –b node.qcow2 –f qcow2 test.img
11. Configure the virtual machine configuration file, use the template file copy, and modify (step 8 copies)
<domain type='kvm'>
<name>test</name> //修改名字
<memory unit='KiB'>2048000</memory> //修改内存
<currentMemory unit='KiB'>2048000</currentMemory>
...
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/test.img'/> //步骤十创建的img文件位置
…
<channel type='unix'> <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-DA-rhel7/org.qemu.guest_agent.0'/> <target type='virtio' name='org.qemu.guest_agent.0'/> <address type='virtio-serial' controller='0' bus='0' port='1'/> </channel>
#以上5行如果有请删除,会导致启动虚拟机出错!!
#注意:除这些外还要把mac地址删掉,带address字样的全部删除(只是网卡需要去掉mac地址和accress地址,pci总线不用去掉)
12. Start the virtual machine verification
[root@room9pc01 images]# virsh define /etc/libvirt/qemu/test.xml
[root@room9pc01 images]# virsh start test
[root@room9pc01 images]# virsh console test