In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Blog outline:
I. disk and snapshot management
II. Virtual machine cloning technology
III. Network configuration of virtual machines
I. disk and snapshot management
This paragraph mainly introduces the management of disks and snapshots!
There are two disk formats in the KVM virtual machine, which are:
RAW: naked format. Large footprint, good performance, but does not support snapshot function; qcow2: small footprint, performance is slightly worse than RAW, but it supports snapshot function; (1) Virtual disk management
Examples are as follows:
[root@localhost ~] # qemu-img create 1234.raw 5G// creates a virtual disk with a name of 1234.raw and a size of 5G. The default format for creating a disk is raw [root@localhost ~] # qemu-img create-f qcow2 123.qcow2 5G//. The name is 123.qcow2 and the size is 5G. Specify the disk format as qcow2 [root@localhost ~] # qemu-img info 1234.raw / / View the details of the 1234.raw disk [root@localhost ~] # qemu-img info 123.qcow2 / / View the details of the 123.qcow2 disk / / the above operations are recommended in a created test directory
The following actions convert the local disk format to qcow2
[root@localhost ~] # cd / kvm/disk/ KVM Virtual disk Storage path [root@localhost disk] # qemu-img info web01.raw / / View disk details image: web01.rawfile format: raw / / the format shown here is rawvirtual size: 10G (10737418240 bytes) disk size: 1.4G [root@localhost disk] # virsh list-- all / / View virtual machine list Confirm that the virtual machine is a shutdown state Id name status-web01 shuts down [root@localhost disk] # qemu-img convert-f raw-O qcow2 Web01.raw web01.qcow2// converts the original disk format raw to qcow2 However, before the conversion, you need to make sure that the KVM virtual machine is turned off [root@localhost disk] # ls web01.qcow2 web01.raw// Note that the disk of the virtual machine before conversion still exists [root@localhost disk] # virsh edit web01 / / modify the disk file format of the virtual machine, navigate to driver name, and modify it to the following: / / change the original disk type raw to qcow2 Both lines need to be modified [root@localhost disk] # virsh start web01// to confirm that the virtual machine can be turned on Prove that there are no errors in disk file changes (2) Virtual machine snapshot management [root@localhost disk] # virsh snapshot-create web01// create snapshot for web01 virtual machine [root@localhost disk] # virsh snapshot-list web01// view snapshot information name of virtual machine generation time status-- -- 1575285097 2019-12-02 19:11:37 + 0800 running// name this column is expressed as a timestamp The time from 1970 to now Default is seconds [root@localhost disk] # virsh snapshot-revert web01 1575285097 bytes / restore specified snapshot information for virtual machine [root@localhost disk] # qemu-img info web01.qcow2 / / View disk information after virtual machine conversion image: web01.qcow2file format: qcow2virtual size: 10G (10737418240 bytes) disk size: 2.0Gcluster_size: 65536Snapshot list:ID TAG VM SIZE DATE VM CLOCK1 1575285097 254m 2019-12-02 19:11:37 00displacement 01bureau 54.499max / it can be seen here that the snapshot is actually stored on the disk of the virtual machine Occupied disk space Format specific information: compat: 1.1 lazy refcounts: false [root@localhost disk] # virsh snapshot-delete web01 1575285097 / delete the specified snapshot for the virtual machine
This is a brief introduction to the disk information for the KVM virtual machine, and will continue to be updated if you have the opportunity!
II. Virtual machine cloning technology
In the KVM virtualization platform, there are three main types of clones:
Manual cloning; linked cloning; full automatic cloning; (1) manual cloning
The KVM virtual machine has two configuration files, and the virtual machine is cloned by cloning the configuration file. Another prerequisite is that the virtual machine must be in a shutdown state.
Do the following:
[root@localhost ~] # cd / etc/libvirt/qemu/ [root@localhost qemu] # cp web01.xml web02.xml / / copy with the most basic command [root@localhost qemu] # virsh dumpxml web01 > web03.xml// generate [root@localhost qemu] # lsnetworks web01.xml web02.xml web03.xml// using the dumpxml tool to confirm that the xml file does exist Both of the above methods can be [root@localhost qemu] # rm-rf web03.xml / / Experimental environment, so delete this file [root@localhost qemu] # cd / kvm/disk/ [root@localhost disk] # cp web01.raw web02.raw / / enter the specified directory to copy the virtual machine disk file [root@localhost disk] # vim / etc/libvirt/qemu/web02.xml / / modify the xml file definition of the virtual machine to the first The changes in the name field are as follows: web02 is defined to the first uuid field to delete the entire uuid line! Define to the first mac address field to delete the entire row! [root@localhost disk] # cd / etc/libvirt/qemu [root@localhost qemu] # virsh define web02.xml / / define a virtual machine through the configuration file (this virtual machine is not active yet) Note: if you need to delete use "virsh define web02.xml" but only delete the xml file, not the disk file! [root@localhost qemu] # virsh list-- all Id name status-web01 off-web02 Shut down [root@localhost qemu] # virsh start web02 / / enable the virtual machine Test by yourself (2) Link cloning
Link cloning is just a link to its original disk file! Do the following:
[root@localhost disk] # qemu-img create-f qcow2-b web01.raw web02.qcow2// generates a new disk file web02.qcow2 for the original web01.raw, adding the meaning of "- b" option It means [root@localhost disk] # qemu-img info web02.qcow2 / / View the details of the newly created disk image: web03.qcow2file format: qcow2virtual size: 10G (10737418240 bytes) disk size: 196K / / Note the size cluster _ size: 65536backing file: web01.raw / / indicates the final used disk Format specific information: compat: 1.1 lazy refcounts: false [root@localhost disk] # virsh edit web02 defined to the driver name field Change it to qcow2 and change it to web02.qcow2 [root@localhost disk] # virsh start web02 / / for boot test and self-test (3) full automatic cloning
In view of the above two cloning methods, this kind of cloning method is too simple! A hard requirement is to shut down the KVM virtual machine.
[root@localhost ~] # virt-clone-- auto-clone-o web01- n web03 / / web03 virtual machines are automatically generated for virtual machine web01, and web01-clone will be generated if the name is not specified by-n. [root@localhost ~] # virsh list-- all Id name status-web01 off-web02 Turn off-web03 turn off [root@localhost ~] # virsh start web03 / / start up and test by yourself
That's all about the cloning of virtual machines!
III. Network configuration of virtual machines
The reason why we create multiple virtual machines in the KVM virtual machine is to provide corresponding services to Internet users.
So first, let's introduce two modes of the KVM virtual machine:
(1) NAT mode
Scope of application: Internet access is not allowed
Principle: NAT is the default mode after KVM installation. It supports the access between KVM host and virtual machine, as well as virtual machine access to the Internet, but does not support Internet users to access it!
Implementation method:
[root@localhost ~] # virt-clone-- auto-clone-o web01-n web02// generates a web02 virtual machine by full automatic cloning [root@localhost ~] # systemctl start firewalld// ensures that the firewall is turned on [root@localhost ~] # echo net.ipv4.ip_forward = 1 > > / etc/sysctl.conf [root@localhost ~] # sysctl-pnet.ipv4.ip_forward = 1 / enable route forwarding function [root@localhost ~ ] # firewall-cmd-- add-port=5900/tcp-- permanent [root@localhost ~] # firewall-cmd-- reload// if you need VNC to operate it You also need to open port 5900 [root@localhost ~] # virsh start web02 / / enable the web02 virtual machine
To verify:
There is no problem with accessing the Internet!
(2) bridge mode (bridged network)
Scope of application: server host virtualization
Principle: that is, the network connection mode of the virtual bridge, so that Internet users can access the virtual machine of KVM
Implementation method:
[root@localhost ~] # systemctl stop NetworkManager / / close the network management tool [root@localhost ~] # virsh iface-bridge ens33 br0 / / generate br0 through ens33 use additional device br0 to generate bridging ens33 failed / / prompt failed it doesn't matter that the bridge interface br0 [root@localhost ~] # cd / etc/sysconfig/network-scripts/ [root@localhost network-scripts] # cat ifcfg-ens33DEVICE=ens33ONBOOT=yesBRIDGE= "br0" / / there is almost no content in the network card that can view ens33. Just bridging to br0 [root@localhost network-scripts] # cat ifcfg-br0 DEVICE= "br0" ONBOOT= "yes" TYPE= "Bridge" BOOTPROTO= "none" IPADDR= "192.168.1.7" NETMASK= "255.255.255.0" GATEWAY= "192.168.1.254" IPV6INIT= "yes" IPV6_AUTOCONF= "yes" DHCPV6C= "no" STP= on "DELAY=" 0 / / found that the IP address that originally belonged to ens33 ran to the br0 card [root@localhost ~] # brctl show / / using the br special command to view the bridge name bridge id STP enabled interfacesbr0 8000.000c29855ef5 yes ens33virbr0 8000.52540028f9c1 yes virbr0-nic//, you can see that ens33 is bridged to the br0 network card [root@localhost ~] # virsh edit web01 / / use edit tools to edit the configuration file of the web01 virtual machine and locate it to interface. Modify the content: change it to bridge and change it to bridge='br0' [root@localhost ~] # virsh start web01 / / start the web01 virtual machine
To verify:
That's all about the KVM virtual machine network!
-this is the end of this article. Thank you for reading-
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.