A description of virtualization
1 Common virtualization software
VMware series
VMware Workstation, VMware vsphere (VMware ESXi), VMware Fusion (MAC)
Xen Open Source Semi-virtualized
XenServer Commercial, Vendor Ctirx, Xen-based
KVM Open source based Linux kernel module
Hyper-V Business, vendor Microsoft
Openvz Open source sharing a kernel based on Linux virtual machines and host hosts
VirtualBox Open Source Sun Inc. develops Oracle acquisition Sun
Http://developer.huawei.com/ict/forum/thread-23385-1-1.html
2 Virtualization Architecture
Reference http://developer.huawei.com/ict/forum/thread-23385-1-1.html
Two KVM
1 Why KVM is selected
Vmware,xen,hyper-v all charges, the rest of the OpenVZ, but the virtual machine with the host shared core, such as to install a WinDOS VM, can not achieve. KVM is free and exists as a functional module of the Linux kernel. Therefore, Yum can be used after installation, it is very convenient.
2 KVM Technology
KVM was developed by Qumranet, an Israeli start-up company, and in September 2008 Redhat acquired Qumranet
KVM is a module of the Linux kernel that turns the Linux kernel into a hypervisor
KVM is fully open source, and the Redhat KVM-based virtualization solution is called Rhev
KVM appears as a process in the Linux operating system and is scheduled by the standard Linux Scheduler, which allows KVM to use the functionality of the Linux kernel
Only one KVM kernel module can not achieve all the functions of virtualization, just as the operating system only the kernel can not become a full operating system like
QEMU is an open source virtualization software, pure software, can be virtualized so the hardware, performance is not strong
Based on QEMU, KVM has developed a tool that can run in user space QEMU-KVM
disks, network devices, etc. are simulated by the QEMU-KVM tool.
KVM and QEMU-KVM communication is implemented through/DEV/KVM
Libvirt is an API for managing KVM virtual machines, with commands for Virsh
3 Installing KVM on CENTOS7
The premise is that the CPU supports virtualization
Virtual machine Set Memory 2G, add a 50G virtual disk, processor 2 core, virtualization engine two virtualization related options tick
关闭iptables或者firewalldsystemctl stop iptablessystemctl stop firewalld关闭selinuxsetenforce 0vim /etc/selinux/config设置SELINUX=disabled
格式化新磁盘,挂载到/kvmmkfs.ext4 /dev/sdcblkid /dev/sdcmkdir /kvmmount /dev/sdc /kmv添加开机自动挂载vim /etc/fstab对照之前的挂载规则,增加一条/dev/sdc /kvm ext4 defaults 0 0
Download a centos7 image file
Check if CPU parameters support virtualization
grep -Ei ‘vmx|svm‘ /proc/cpuinfo
Installing KVM
yum install -y virt-* libvirt bridge-utils qemu-img
4 Configuring the NIC and installing CENTOS7
Configure the network card to increase the bridge adapter
Set up an br0 nic with the type BRIDGE,IP address set to ENS33 IP
ENS33 the IP address in the config file, add bridge=br0
Check if the KVM module is loaded
lsmod|grep kvm
Start the LIBVIRTD service
systemctl start libvirtd
brctl show
You can see two NICs br0 and Virbr0
Command-line installation Centos7
virt-install --name=lvlinux01 --memory=512,maxmemory=1024 --vcpus=1,maxvcpus=2 --os-type=linux --os-variant=rhel7 --location=/tmp/CentOS-7-x86_64-DVD-1708.iso --disk path=/kvm/lvlinux01.img,size=10 --bridge=br0 --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
5 Virtual Machine Management
The virtual machine needs to be restarted to exit the virtual machine using the shortcut key Ctrl]
ps aux |grep kvm
View the KVM Process
virsh list
View the list of virtual machines and see only the virtual machines that are running
virsh list --all
View a list of virtual machines, including virtual machines that are not running
virsh console lvlinux01
Enter the specified virtual machine
virsh shutdown lvlinux01
Shutting down a virtual machine
virsh start lvlinux01
Turn on the virtual machine
virsh destroy lvlinux01
Like stop, this is a forced stop
virsh undefine lvlinux01
Completely destroy the virtual machine, delete the virtual machine configuration file, Virsh list--all will not see
ls /etc/libvirt/qemu/
You can view the virtual machine configuration file
virsh autostart lvlinux01
Host power on the virtual machine also boot
virsh autostart --disable lvlinux01
Unlock Boot
virsh suspend lvlinux01
Hang Up
virsh resume lvlinux01
Recovery
6 Virtual machine Cloning
virsh shutdown lvlinux01
virt-clone --original lvlinux01 --name lvlinux02 --file /kvm/lvlinux02.img
--original specifying a clone source virtual machine
--NAME Specifies the virtual machine name after cloning
--FILE Specifies the virtual disk file for the target virtual machine
If the lvlinux01 virtual machine is powered on, you are prompted to shut down or pause the virtual machine first
7 Snapshot Management
Create a Snapshotvirsh snapshot-create lvlinux01
virtual disks in RAW format do not support snapshots, QCOW2 support
qemu-img info /kvm/lvlinux01.img
View lvlinux01.img information While viewing the list of snapshots
virsh snapshot-list lvlinux01
List all snapshots
virsh snapshot-current lvlinux01
View current Snapshot version
ls /var/lib/libvirt/qemu/snapshot/lvlinux01
View all snapshot profiles
virsh snapshot-revert lvlinux01 1513440854
Recovering a specified snapshot
virsh snapshot-delete lvlinux01 1513440854
Deleting a snapshot
8 Disk Format
Virtual disk Common format raw, Qcow2
qemu-img info /kvm/lvlinux01.img
View Virtual Disk formats
qemu-img create -f raw /kvm_data/lvlinux01_2.img 2G
Create a 2G RAW format disk
Convert RAW format disk to QCOW2 format
qemu-img convert -O qcow2 /kvm/lvlinux01_2.img /kvm/lvlinux01_2.qcow2
After conversion with LS-LH to see the size of the disk file, you can see the Qcow2 file is relatively small, raw file size and we specify the size of the space is 2G
Disk performance in RAW format is better than QCOW2, but raw format disks do not take snapshots
To convert lvlinux02 to RAW format disk
virsh shutdown lvlinux02
qemu-img convert -O raw /kvm/lvlinux02.img /kvm/lvlinux02_3.raw
virsh edit lvlinux02
Change format and file path
virsh start lvlinux02
9 Disk Expansion –raw format
qemu-img resize /kvm/lvlinux02_3.raw +2Gqemu-img info /kvm/lvlinux02_3.raw virsh destroy lvlinux02virsh start lvlinux02virsh console lvlinux02
Fdisk-l View the disk condition and divide the new partition
In addition to expansion of existing disks, additional disks can be added
qemu-img create -f raw /kvm/lvlinux02_2.raw 5Gvirsh edit lvlinux02 //增加<disk>…</disk>,注意更改source、target、slotvirsh destroy lvlinux02virsh start lvlinux02
Disk Expansion –qcow2 Format
qemu-img resize /kvm/lvlinux01.img +2G
If prompted Qemu-img:can ' t resize an image which have snapshots, need to delete the snapshot
qemu-img info /kvm/lvlinux01.img
virsh destroy lvlinux01
virsh start lvlinux01
virsh console lvlinux01
Fdisk-l View the disk condition and divide the new partition
In addition to expansion of existing disks, additional disks can be added
qemu-img create -f qcow2 /kvm/lvlinux01_2.img 5G
virsh edit lvlinux01
Add <disk>...</disk> Note change the source, target, slot
virsh destroy lvlinux01
virsh start lvlinux01
10 tuning CPU, memory, NIC
virsh dominfo lvlinux01
View Configuration
virsh edit lvlinux01
Change the following sections
<memory unit=‘KiB‘>1048576</memory> <currentMemory unit=‘KiB‘>524288</currentMemory> <vcpu placement=‘static‘ current=‘1‘>2</vcpu>
virsh shutdown lvlinux01
virsh start lvlinux01
virsh setmem lvlinux01 800m
Dynamically Adjust memory
virsh dumpxml lvlinux01 > /etc/libvirt/qemu/lvlinux01.xml
You need to write the configuration to the configuration file.
virsh setvcpus lvlinux01 2
Dynamically adjust the number of CPUs
virsh domiflist lvlinux01
View NIC
virsh attach-interface lvlinux01 --type bridge --source virbr0
Add a new NIC and set it to NAT network mode (virbr0 similar to VMware vmnet8), where if--source br0 is written, the network mode is bridged
virsh dumpxml lvlinux01 > /etc/libvirt/qemu/lvlinux01.xml
You need to write the configuration to the configuration file.
11 Migrating virtual Machines
The way to make sure that the virtual machine is shutdown state
virsh shutdown lvlinux01
virsh dumpxml lvlinux01 > /etc/libvirt/qemu/lvlinux03.xml
If it is a remote machine, you need to copy the configuration file to the remote machine.
virsh domblklist lvlinux01
View the directory where the virtual machine disk resides
rsync -av /kvm/lvlinux01.img /kvm/lvlinux03.img
If you are migrating to remote, you need to copy the disk file to the remote machine
vi /etc/libvirt/qemu/lvlinux03.xml
Because it is migrated to this machine, the configuration file with the configuration of the LVLINUX01 sub-machine, do not change the conflict, so need to modify the file, if the remote machine does not have to modify
Modified Domname: <name>lvlinux03</name>
Modify the UUID (change the number, do not change the number of digits)
modifying disk paths
virsh define /etc/libvirt/qemu/lvlinux03.xml
Define a new virtual machine
virsh list --all
The newly migrated lvlinux03 virtual machine will be discovered
Linux Learning Summary (72) Virtualization KVM