Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy kvm Virtualization Technology under Linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to deploy kvm virtualization technology under Linux". In the daily operation, I believe that many people have doubts about how to deploy kvm virtualization technology under Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to deploy kvm virtualization technology under Linux". Next, please follow the editor to study!

KVM is a virtualized infrastructure used in the Linux kernel that converts the Linux kernel into a hypervisor. KVM was imported into the Linux 2.6.20 core in February 2007 and ported to FreeBSD and illumos as loadable core modules.

KVM architecture

KVM is an open source Linux native full virtualization solution based on X86 hardware of virtualization extensions (Intel VT or AMD-V). In KVM, the virtual machine is implemented as a regular Linux process, which is scheduled by the standard Linux scheduler, and each virtual CPU of the virtual machine is implemented as a conventional Linux process. This allows KMV to use the existing features of the Linux kernel.

However, KVM itself does not perform any hardware simulation, and requires the client space program to set up the address space of a client virtual server through the / dev/kvm interface, provide it with a simulated Imando O, and map its video display back to the host display screen. The current application is QEMU.

User space, kernel space, and virtual machines on Linux:

Deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology Guest on Centos6.5: client systems, including CPU (vCPU), memory, drivers (Console, network card, Igamo device driver, etc.), are run in a restricted CPU mode by KVM. KVM: runs in kernel space, providing virtual levels of CPU and memory, as well as the client's Imax O interception. After being intercepted by KVM, the Guest's Icano is handed over to QEMU for processing. QEMU: modified QEMU code for use in KVM virtual machines, running in user space, providing hardware I dev/kvm O virtualization, and interaction with KVM through IOCTL / dev/kvm devices. KVM function

The features supported by KVM include:

Support for CPU and memory hyper-score (Overcommit) support for paravirtualized Imax O (virtio) support for hot swappable (cpu, block devices, network devices, etc.) support for symmetric multiprocessing (Symmetric Multi-Processing) SMP) support for real-time migration (Live Migration) support for direct allocation of PCI devices and single root Imax O virtualization (SR-IOV) support for kernel same page merging (KSM) support for NUMA (Non-Uniform Memory Access, inconsistent storage access structure) KVM common tools libvirt: virtualized API for operating and managing KVM virtual machines, written in C language Can be called by Python,Ruby, Perl, PHP, Java and other languages. Can operate including KVM,vmware,XEN,Hyper-v, LXC and other Hypervisor. Virsh: libvirt-based command line tool (CLI) Virt-Manager: libvirt-based GUI tool virt-v2v: virtual machine format migration tool virt-* tool: including Virt-install (command line tool for creating KVM virtual machine), Virt-viewer (tool for connecting to virtual machine screen), Virt-clone (virtual machine cloning tool), virt-top and other sVirt: security tools KVM installation

Check to see if CPU supports virtualization before installation

Lntel CPU: [root@localhost ~] # cat / proc/cpuinfo | grep vmx deploys kvm virtualization technology on Centos6.5, deploys kvm virtualization technology on Centos6.5

If the above operations have output, it means that CPU supports virtualization.

Experimental environment KVM:Centos6.5 64-bit operating system memory 4GB hard disk 20g

Enable CPU virtualization support:

Deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology installation dependency [root@localhost] # yum-y install qemu-kvm qemu-kvm-tools python-virtinst.noarch qemu-img bridge-utils libvirt virt-manager on Centos6.5

Deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology on Centos6.5 to check whether the KVM module [root@localhost ~] # lsmod | grep kvmkvm_intel 54285 0kvm 333172 1 kvm_intel runs the KVM network in libvirt there are two ways: NAT and bridge, the default is NAT. Bridge (bridging mode) will be taken as an example. [root@localhost ~] # ip A1: lo: mtu 16436 qdisc noqueue state UNKNOWN link/loopback 0012 scope host valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:88:85:64 brd ff:ff:ff:ff:ff:ff Inet 192.168.2.113 scope global eth0 inet6 fe80::20c:29ff:fe88:8564/64 scope link valid_lft forever preferred_lft forever3 24 brd 192.168.2.255 scope global eth0 inet6 fe80::20c:29ff:fe88:8564/64 scope link valid_lft forever preferred_lft forever3: pan0: mtu 1500 qdisc noop state DOWNlink/ether c2:34:e0:1c:77:37 brd ff:ff:ff:ff:ff:ff [root@localhost ~] # cd / etc/sysconfig/network-scripts/ [root@localhost network-scripts] # cp ifcfg-eth0 ifcfg-br0 [root@localhost Network-scripts] # vim ifcfg-br0DEVICE=br0HWADDR=00:0c:29:88:85:64TYPE=BridgeONBOOT=yesNM_CONTROLLED=noBOOTPROTO=staticIPADDR=192.168.2.113NETMASK= 255.255.255.0 [root @ localhost network-scripts] # vim ifcfg-eth0DEVICE=eth0HWADDR=00:0c:29:88:85:64TYPE=EthernetONBOOT=yesNM_CONTROLLED=noBOOTPROTO=staticBRIDGE= "br0" # Bridge Virtual Network Card name [root@localhost ~] # / etc/init.d/network restart deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology on the Top of Centos6.5 [root@localhost ~] # ip a deploy kvm virtualization technology on Centos6.5 deploy kvm virtualization technology on Centos6.5 install KVM [root @ localhost ~] # mkdir-pv / data_kvm/ {store Iso} mkdir: created directory "/ data_kvm" mkdir: created directory "/ data_kvm/store" mkdir: created directory "/ data_kvm/iso" enter the graphical interface [root@localhost ~] # virt-manager

There is an error in the connection, just restart

Deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology on Centos6.5 restart libvirtd [root@localhost] # / etc/init.d/libvirtd start [root@localhost ~] # virt-manager deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology add Pool on Centos6.5

Double-click localhost {QEMU}-- Storage-- "+" to add pool

Deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology on Centos6.5

Select browse-- find the directory you just created-- finish

Deploy kvm virtualization technology on Centos6.5 deploy kvm virtualization technology on Centos6.5 to create storage volume

KVM01 pool just created on a stand-alone machine-- create a new volume

Deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology deploy kvm Virtualization Technology on Centos6.5

The specific installation process is the same as installing the Linux system (linux system installation tutorial)

Deploy kvm virtualization technology on Centos6.5 deploy kvm virtualization technology on Centos6.5 view KVM configuration file storage directory [root@localhost ~] # ls / etc/libvirt/qemucentos6.5.xml networks view virtual machine status [root@localhost ~] # virsh list-- allId name status- -- 2 shutdown of centos6.5 running (on) virtual machine, Bootstrap and other operations need to ensure that acpid services are installed and running [root@localhost] # yum-y install acpid deploy kvm virtualization technology on Centos6.5 deploy kvm virtualization technology on Centos6.5 [root@localhost] # / etc/init.d/acpid start [root@localhost] # / etc/init.d/haldaemon stop is shutting down the HAL daemon: Set] [root@localhost ~] # / etc/init.d/acpid start [root@localhost ~] # / etc/init.d/haldaemon start to start the HAL daemon: [confirm] [root@localhost ~] # / etc/init.d/acpid statusacpid (pid 1417) is running. Shutdown KVM virtual machine [root@localhost ~] # virsh shutdown centos6.5 domain centos6.5 is disabled [root@localhost ~] # virsh destroy centos6.5 domain centos6.5 is deleted deploy kvm virtualization technology on Centos6.5 deploy kvm virtualization technology on Centos6.5 [root@localhost ~] # virsh list-- allId name status- -- centos6.5 shuts down boot KVM virtual machine [root@localhost ~] # virsh start centos6.5 domain centos6.5 has started [root@localhost ~] # virsh list-- allId name status- -- 4 centos6.5 running virtual machine companion host automatically starts [root@localhost ~] # virsh autostart centos6.5 domain centos6.5 marked as automatic start [root@localhost ~] # ls / etc/libvirt/qemuautostart centos6.5.xml networks export virtual machine configuration [ Root@localhost ~] # virsh dumpxml centos6.5 > / etc/libvirt/qemu/centos6.5_bak.xml Delete virtual machine [root@localhost ~] # virsh undefine centos6.5 modify virtual machine configuration information [root@localhost ~] # virsh edit centos6.5KVM file management Convert raw format to qcow2 format

Virtual machine disk files are divided into raw and qcow2 formats, and the default format of KVM is raw bare devices.

Raw benefits: good performance, the fastest. Cons: some new features are not supported. Such as: mirror, zlib disk compression, AES encryption, etc.

Libguestfs-tools tool to realize format conversion

[root@localhost ~] # yum-y install libguestfs-tools deploy kvm Virtualization Technology on Centos6.5 deploy kvm Virtualization Technology on Centos6.5 [root@localhost ~] # qemu-img info / data_kvm/store/KVM011.imgimage: / data_kvm/store/KVM011.imgfile format: rawvirtual size: 3.9g (4194304000 bytes) disk size: 3.9g [root@localhost ~] # virsh shutdown centos6.5 Domain centos6.5 is turned off format conversion It takes some time [root@localhost ~] # qemu-img convert-f raw-O qcow2 / data_kvm/store/KVM011.img / data_kvm/store/ KVM011.qcow2 [root @ localhost ~] # ls / data_kvm/store/KVM011.img KVM011.qcow2 [root@localhost ~] # ls / etc/libvirt/qemuautostart centos6.5_bak.xml centos6.5.xml networks [root@localhost ~] # virsh edit centos6.5 edits the domain centos6.5 XML configuration. Modify centos6.5 's xml configuration file 23 24 Virt-cat command, which is similar to cat. You can view the file in the virtual machine and view the network file in the virtual machine. It takes some time to [root@localhost ~] # virt-cat-a / data_kvm/store/centos6.5.qcow2 / etc/sysconfig/networkVirt-edit command to edit the file. Usage is basically the same as vim [root@localhost ~] # virt-edit-a / data_kvm/store/centos6.5.qcow2 / etc/sysconfig/networVirt-df command to view virtual machine disk information [root@localhost ~] # virt-df-h centos6.5Filesystem Size Used Available Use%centos6.5:/dev/sda1 484M 33M 427M 7 % centos6.5:/dev/sdb1 4.2G 4.2G 0 100%centos6.5:/dev/VolGroup/lv_root 3.0G 1.0G 1.8G 34% virtual machine clone [root@localhost ~] # virsh destroy centos6.5 domain centos6.5 deleted [root@localhost ~] # virsh list-- allId name Status-centos6.5 off cloning from centos6.5 to centos6.5-clome [root@localhost ~] # virt-clone-o centos6.5- n centos6.5-clome-f / data_kvm/store / KVM011-clone.qcow2Clone 'centos6.5-clome' created successfully. [root@localhost ~] # virsh list-- allId name status-centos6.5 off- Centos6.5-clome closes snapshots of virtual machines to create snapshots [root@localhost ~] # virsh snapshot-create centos6.5Domain snapshot 1535644190 created1535644190: version number of snapshots (how many seconds have elapsed since January 1, 1970) View snapshot information [root@localhost ~] # virsh snapshot-list centos6.5 name Creation Time status- -1535644190 2018-08-30 23:49:50 + 0800 shutoff restore snapshot [root@localhost ~] # virsh snapshot-list centos6.5 name Creation Time status- -- 1535644190 2018-08-30 23:49:50 + 0800 shutoff1535644574 2018-08-30 23:56:14 + 0800 shutoff [root@localhost ~] # virsh snapshot-revert centos6.5 1535644190 [root@localhost ~] # virsh snapshot-current centos6.5 1535644190 shutoff delete snapshot [root@localhost ~] # virsh snapshot- Delete centos6.5 1535644190Domain snapshot 1535644190 deleted [root@localhost ~] # virsh snapshot-list centos6.5 name Creation Time status-1535644574-08-30 23:56:14 + 0800 shutoff so far The study on "how to deploy kvm virtualization technology under Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report