In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you how to create a virtual machine and set up a network in libvirt. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something from the detailed introduction of this article.
I: Introduction
Libvirt is a further operation encapsulation based on virtualization technologies such as xen and kvm. It can quickly call kvm and xen commands to quickly create and manage virtual machines. For example, libvirt records the parameters required by kvm to create a virtual machine through xml configuration files, and then only needs to read the xml configuration information every time the virtual machine is started, without having to enter so many commands and parameters every time. Their relationship is as follows:
2: Creating a Virtual Machine
1. Also determine whether the machine supports virtualization, and then load the kernel module.
2. Install qemu-kvm and libvirt (bridge-utils will be installed automatically)
yum install -y qemu-kvm libvirt
3. Start the libvritd daemon
service libvirtd start
There are two ways to use virsh.
Virsh list --all
virsh [Enter] Enter the interactive interface
virsh# list --all
5. Writing configuration files
Note:
1. Do not put disk images and CD images under root, but under/directory.
2. There is no order problem with cdrom and hd in this line
3, vnc port If automatic acquisition is enabled, set to yes and-1, if you want to specify the port, set to no and specific 590X
In fact, libvirt uses the function of qemu-kvm to carry out operation encapsulation on her basis. At the same time, it records the parameters of the virtual machine in a configuration file and multiplexes this configuration file.
kvm1 1024 1024 2 hvm destroy restart destroy /usr/libexec/qemu-kvm
virsh operating virtual machine commands
1. Define the virtual machine (specify the configuration file, which will be copied to a specified folder in libvirt)
virsh define /cloud/centos-base.xml
2. Virsh manages virtual machines
virsh list --all #Show all virtual machines--all Show all
3. Start the virtual machine
virsh start centos
4. Shut down the virtual machine
virsh shutdown centos
5. Forced shutdown
virsh destroy centos
6. Remove the virtual machine
virsh undefine centos
7. Display vnc port
virsh vncdisplay centos
8, Dynamic query kvm use resources
top -d 1 | grep kvm
9. Query the kvm process
ps -aux | grep kvm
10. Boot the virtual machine automatically
virsh autostart centos
The requested URL/cloud/centos.bak.xml was not found on this server.
virsh dumpxml centos > /cloud/centos.bak.xml
Edit the virtual machine configuration (configure the configuration file in libvirt, not the one we wrote)
virsh edit centos
13. Clone KVM virtual machines
virt-clone -o Winxp -n winxpclone-f /home/kvm/winxpclone.img (-o name of original object-n name of new client-f new file as new client disk image)
III: Configure the network
1, no longer need brctl and tunctl to manually create bridges, tap type network card and then associate and so on, now only need to use virsh provided iface-bridge, iface-unbridge, etc. to automatically create bridges, network cards, and bound to the bridge. The main thing is that it will directly ifcfg-eth0 and create an ifcfg-br0 file, so that after the machine restarts, it is still valid.
2. It is also divided into three network modes: bridge, nat and hosts-only.
bridge and nat models
The nat: virsh startup creates a bridge virbr0 of type nat, the configuration information of which is defined in cat /var/lib/libvirt/network/default.xml. If you define a network of nat type, you can directly associate this bridge.
Bridge: You need to create a bridge using iface-bridge eth0 br0 and bind eth0.
3. Creating a bridge and associating eth0 to the bridge (automatically creating bridgebr0 and binding eth0) modifies ifcfg-eth0 and creates a configuration file for ifcfg-br0
virsh iface-bridge eth0 br0
4. Edit the virtual machine configuration file and bind it to the bridge (a network card vnet0 of tap type will be automatically created and bound to the bridge)
5. Define and start the virtual machine as above.
After starting the virtual machine, ifconfig will show a tap type NIC of vnet0, which is automatically generated because the above bridge is connected to br0, and its NIC mac is also automatically generated. br0 is bound to two network cards eth0 and vnet0
If you start another virtual machine bound to virtbr0, then another tap-type NIC (vnet1) is automatically created and bound to virtbr0.
IV: Summary
Virsh will automatically create a bridge and bind eth0 to it, while modifying ifcfg-eth0 and creating ifcfg-br0 so that it will take effect the next time it is booted. Different from manual brctl operation
2. When starting the virtual machine, link to that bridge, which bridge will automatically create a network card of tap type, and the name will increment from vnet0. After closing the virtual machine, this vnet0 will be automatically deleted.
3, xml configuration file when defining the network card can not specify mac network card, will be automatically assigned, if manually specified, then you must ensure that the same bridge, mac can not be repeated
4. If multiple network cards are configured in xml, you need to remember the order. The first is eth0, the second is eth2...... Because binding to that bridge, you need to configure the IP address of the corresponding network segment, otherwise you can't access the Internet.
Five: virsh network operations iface-begin iface-commit iface-destroy iface-edit iface-mac iface-rollback iface-unbridge iface-bridge iface-define iface-dumpxml iface-list iface-name iface-start Iface-undefined The above is how to create a virtual machine and set up a network in libvirt. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
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.