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

Kvm Command Basics 1

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

(1) View the list of virtual machines virsh list

[root@kvm ~] # virsh list// running virtual machines, if you want to view all plus-all

[root@kvm ~] # virsh list-all

(2) View virtual machine details

[root@kvm ~] # virsh dominfo test1 (dominfo domain)

(3) switch on and off of virtual machine

[root@kvm ~] # virsh start test1 / / (boot)

Verify it.

[root@kvm ~] # virsh list

[root@kvm] # virsh shutdown test01 / / (shutdown gently)

Verify it.

[root@kvm ~] # virsh list-all

Open it again to see if the id has changed

[root@kvm ~] # virsh start test1 [root@kvm ~] # virsh list-all

[root@kvm] # virsh destroy test1 / / (forced shutdown) is similar to unplugging the power supply

(4) Export configuration

[root@kvm ~] # virsh dumpxml test1 > test1.xml / / the current location is / root/

A complete KVM domain will be generated with two files.

1) disk file, which has been specified at the place of deployment

2) Xml configuration file, default is / etc/libvrit/qemu

Delete the configuration file of the virtual machine

[root@kvm kvm-vm] # rm-rf / etc/libvirt/qemu/test1.xml [root@kvm ~] # virsh list-all

[root@kvm ~] # ls / kvm-vm/

Deleting the configuration file will not affect the disk file

(5) Delete a virtual machine

[root@kvm ~] # virsh start test1 / / enable the virtual machine [root@kvm ~] # virsh destroy test1 / / forcibly shut down the virtual machine

[root@kvm ~] # virsh undefine test1// deletes all files associated with the virtual machine

[root@kvm ~] # virsh list-all

[root@kvm ~] # ls / etc/libvirt/qemu/

(6) restore the virtual machine according to the backed-up configuration file

[root@kvm ~] # virsh define test1.xml / / define the configuration file of backup virtual machine [root@kvm ~] # virsh list-all

[root@kvm ~] # ls / etc/libvirt/qemu/ (check whether the configuration file exists)

(7) rename the domain test01 to bdqn01 and change the name of its disk to bdqn01.raw to ensure that the virtual machine can run normally.

1) modify and define the disk name

85 virsh undefine test1// deletes all files associated with the virtual machine 86 ls / etc/libvirt/qemu

87 cd / kvm-vm/ 88 mv test01.raw bdqn01.raw / / change the disk name to bdqn01.raw 91 virsh define test1.xml / / define the backup virtual machine configuration file 94 virsh list-- allvirsh start test1

2) modify the configuration file (with syntax checking function)

[root@kvm qemu] # virsh edit test1 (modify configuration file) the file modified with edit is not the same as the original one

If you modify it incorrectly, the following interface appears when you exit

Y: correct n: do not correct I: ignore f: force

[root@kvm qemu] # virsh start test1// starts the virtual machine

[root@kvm qemu] # virsh list-- all

3) rename (not supported before 7.2)

[root@kvm ~] # virsh destroy test1// shut down the virtual machine [root@kvm qemu] # virsh domrename test1 bdqn01

[root@kvm qemu] # virsh list-- all

(8), the KVM domain is composed of xml configuration files and disk files, so whether a new virtual machine can be generated by copying these two files, and if so, define a new virtual machine named: bdqn02

[root@kvm ~] # cd / kvm-vm/ enter the directory where the disk files are placed [root@kvm kvm-vm] # cp bdqn01.raw bdqn02.raw// copy a disk [root@kvm kvm-vm] # cd / etc/libvirt/qemu/// enter the directory of the configuration file [root@kvm qemu] # cp bdqn01.xml bdqn02.xml// copy a configuration file [root@kvm qemu] # vim bdqn02.xml// modify the configuration file

[root@kvm qemu] # virsh define bdqn02.xml// defines the configuration file of the virtual machine

[root@kvm qemu] # virsh list-all

(9) whether the ping domain can be connected to the periphery of ping, and if the KVM domain is implemented.

[root@localhost ~] # systemctl stop NetworkManager// stop this service [root@localhost ~] # virsh iface-bridge ens33 br0// when executing this command, don't worry about it if you prompt the following information, because it already exists and failed to generate bridging ens33 using additional device br0 [root@localhost ~] # ls / etc/sysconfig/network-scripts/ | grep br0# confirms that this file is available.

[root@localhost ~] # virsh destroy bdqn02// close the virtual machine [root@localhost ~] # virsh edit bdqn02// edit the configuration file of the virtual machine, navigate to interface # change this to bridge # Delete the Mac address line # change here to this # Save and exit

Now that the configuration is complete, run the virtual machine and change its network card configuration file. Note: the gateway and kvm host configured in the virtual machine are the same. They are now in the same network segment. The network card configuration file of the virtual machine is as follows:

[root@localhost ~] # vi / etc/sysconfig/network-scripts/ifcfg-eth0

/ / set the network

[root@localhost ~] # systemctl restart network

/ / restart the network

You can see that it has been successful.

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

Servers

Wechat

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

12
Report