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

3. Daily management and configuration of kvm virtual machine

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

The management of KVM virtual machine is mainly through virsh command to manage the virtual machine.

1. View KVM virtual machine configuration files and running status

(1) default configuration file location of KVM virtual machine: / etc/libvirt/qemu/

The autostart directory is the configuration kvm virtual machine boot self-boot directory.

(2) virsh command help

# virsh-help

Or directly virsh the command and then execute the subcommand. As shown below.

# virsh

Welcome to virsh, a virtualized interactive terminal.

Enter: 'help' to get help for the command

'quit' exits

Virsh # help

……

(3) View the status of kvm virtual machine

# virsh list-all

2. Boot the KVM virtual machine

# virsh start kvm008

3. Power off or power off the KVM virtual machine

(1) shutdown

By default, the virsh tool cannot shut down the linux virtual machine, and the linux operating system needs to turn on and start the acpid service.

This service must be configured before installing the KVM linux virtual machine.

# chkconfig acpid on

# service acpid restart

Virsh shutdown

# virsh shutdown kvm008

(2) forced power off

# virsh destroy kvm08

4. Start the virtual machine through the configuration file

# virsh create / etc/libvirt/qemu/kvm008.xml

5. Configure a boot-up virtual machine

# virsh autostart kvm008

The autostart directory is the kvm virtual machine boot directory, where you can see that there is a link to the KVM configuration file.

6. Export KVM virtual machine configuration fil

The virtual machine needs to be shut down or the operation will fail.

# virsh dumpxml / etc/libvirt/qemu/kvm008 > / etc/libvirt/qemu/kvm.xml

KVM virtual machine configuration files can be backed up in this way.

7. Add and remove KVM virtual machines

(1) Delete kvm virtual machine

# virsh undefine kvm008

Description: this command only deletes the configuration file of kvm008, not the virtual disk file. This is shown in the following figure.

(2) redefine the virtual machine profile

Restore the definition of the original KVM virtual machine and redefine the virtual machine by exporting the backed-up configuration file.

# mv / etc/libvirt/qemu/kvm.xml / etc/libvirt/qemu/kvm008.xml

# virsh define / etc/libvirt/qemu/kvm008.xml

8. Edit the KVM virtual machine profile

# virsh edit kvm08

Virsh edit will invoke the vi command to edit the / etc/libvirt/qemu/kvm08.xml configuration file. You can also edit, modify, and save directly through the vi command.

Yes but it is not recommended to edit directly through vi.

9. Virsh console console manages linux virtual machines

The virtual machine can only be turned on.

# virsh console kvm08

10. Other virsh commands

(1) suspend the server

# virsh suspend kvm08

(2) restore the server

# virsh resume kvm08

Virsh commands are rich. Can perform a variety of maintenance tasks, this paper only enumerates the commonly used commands from the point of view of maintenance and management, and provides an idea for the use of the command.

Virsh command:

Virsh # help

Grouped commands:

Domain Management (help keyword 'domain'):

Attach-device attaches a device from a XML file

Attach-disk additional disk device

Attach-interface gets the web interface

Autostart automatically starts a domain

Blkdeviotune Set or query a block device I/O tuning parameters.

Blkiotune Get or set blkio parameters

Blockcommit Start a blockcommit operation.

Blockcopy Start a blockcopy operation.

Blockjob Manage active block operations

Blockpull Populate a disk from its backing p_w_picpath.

Blockresize Resize block device of domain.

Change-media Change media of CD or floppy drive

Console connects to a customer session

Cpu-baseline compute baseline CPU

Cpu-compare compare host CPU with a CPU described by an XML file

Cpu-stats show domain cpu statistics

Create creates a domain from a XML file

Define defines (but does not start) a domain from an XML file

Desc show or set domain's description or title

Destroy destroy (stop) a domain

Detach-device detaches the device from a XML file

Detach-disk detach disk device

Detach-interface separate network interface

Domdisplay domain display connection URI

Domhostname print the domain's hostname

Domid converts a domain name or UUID to a domain id

Domif-setlink setlink state of a virtual interface

Domiftune get/set parameters of a virtual interface

Domjobabort abort active domain job

Domjobinfo domain job information

Domname converts a domain id or UUID to a domain name

Dompmsuspend suspend a domain gracefully using power management functions

Dompmwakeup wakeup a domain from pmsuspended state

Domuuid converts a domain name or id to a domain UUID

Domxml-from-native Convert native config to domain XML

Domxml-to-native Convert domain XML to native config

Dump dump the kernel of a domain into a file for easy analysis.

Domain information in dumpxml XML

Edit edits the XML configuration of a domain

Inject-nmi Inject NMI to the guest

Send-key Send keycodes to the guest

Managedsave managedsave of a domain state

Managedsave-remove Remove managedsave of a domain

Maxvcpus connection vcpu maximum

Memtune Get or set memory parameters

Migrate migrates the domain to another host

Migrate-setmaxdowntime set maximum tolerable downtime

Migrate-setspeed Set the maximum migration bandwidth

Migrate-getspeed Get the maximum migration bandwidth

Numatune Get or set numa parameters

Reboot restarts a domain

Reset reset a domain

Restore restores a domain from a state that exists in a file

Resume restores a domain

Save saves the state of a domain to a file

Save-p_w_picpath-define redefine the XML for a domain's saved state file

Save-p_w_picpath-dumpxml saved state domain information in XML

Save-p_w_picpath-edit edit XML for a domain's saved state file

Schedinfo display / set scheduling variables

Screenshot take a screenshot of a current domain console and store it into a file

Setmaxmem changes the maximum memory limit

Setmem changes the allocation of memory

Setvcpus changes the number of the virtual CPU

Shutdown closes a domain

Start starts an inactive domain (previously defined)

Suspend suspends a domain

Ttyconsole tty console

Undefine undefine a domain

Update-device update device from an XML file

Vcpucount domain vcpu counts

Vcpuinfo detailed domain vcpu information

Vcpupin control or query domain vcpu affinity

Emulatorpin control or query domain emulator affinity

Vncdisplay vnc display

Domain Monitoring (help keyword 'monitor'):

Domblkerror Show errors on block devices

Domblkinfo domain block device size information

Domblklist list all domain blocks

Domblkstat gets the status of the domain setting block

Domcontrol domain control interface state

Domif-getlink getlink state of a virtual interface

Domiflist list all domain virtual interfaces

Domifstat obtains the status of domain network interface

Dominfo domain information

Dommemstat get memory statistics for a domain

Domstate domain status

List list domain

Host and Hypervisor (help keyword 'host'):

Capabilities performance

Freecell NUMA available memory

Hostname print Manager hostname

Node-memory-tune Get or set node memory parameters

Nodecpustats Prints cpustats of the node.

Nodeinfo Node Information

Nodememstats Prints memory stats of the node.

Nodesuspend suspend the host node for a given time duration

Qemu-attach QEMU Attach

Qemu-monitor-command QEMU Monitor Command

Qemu-agent-command QEMU Guest Agent Command

Sysinfo print the hypervisor sysinfo

Typical URI of uri print manager

Version display version

Interface (help keyword 'interface'):

Iface-begin create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)

Iface-bridge create a bridge device and attach an existing network device to it

Iface-commit commit changes made since iface-begin and free restore point

Iface-define define (but don't start) a physical host interface from an XML file

Iface-destroy destroy a physical host interface (disable it / "if-down")

Iface-dumpxml interface information in XML

Iface-edit edit XML configuration for a physical host interface

Iface-list list physical host interfaces

Iface-mac convert an interface name to interface MAC address

Iface-name convert an interface MAC address to interface name

Iface-rollback rollback to previous saved configuration created via iface-begin

Iface-start start a physical host interface (enable it / "if-up")

Iface-unbridge undefine a bridge device after detaching its slave device

Iface-undefine undefine a physical host interface (remove it from configuration)

Network Filter (help keyword 'filter'):

Nwfilter-define define or update a network filter from an XML file

Nwfilter-dumpxml network filter information in XML

Nwfilter-edit edit XML configuration for a network filter

Nwfilter-list list network filters

Nwfilter-undefine undefine a network filter

Networking (help keyword 'network'):

Net-autostart automatically starts the network

Net-create creates a network from a XML file

Net-define defines (but does not start) a network from an XML file

Net-destroy destroy (stop) a network

Network Information in net-dumpxml XML

Net-edit edits the XML configuration for the network

Net-info network information

Net-list lists the networks

Net-name converts a network UUID to a network name

Net-start starts an inactive network (previously defined)

Net-undefine undefines an inactive network

Net-update update parts of an existing network's configuration

Net-uuid converts a network name to a network UUID

Node Device (help keyword 'nodedev'):

Nodedev-create create a device defined by an XML file on the node

Nodedev-destroy destroy (stop) a device on the node

Nodedev-detach detach node device from its device driver

Node device details in nodedev-dumpxml XML

The enumerated devices in the host nodedev-list

Nodedev-reattach reattach node device to its device driver

Nodedev-reset resets node devices

Secret (help keyword 'secret'):

Secret-define define or modify a secret from an XML file

Secret-dumpxml secret attributes in XML

Secret-get-value Output a secret value

Secret-list list secrets

Secret-set-value set a secret value

Secret-undefine undefine a secret

Snapshot (help keyword 'snapshot'):

Snapshot-create Create a snapshot from XML

Snapshot-create-as Create a snapshot from a set of args

Snapshot-current Get or set the current snapshot

Snapshot-delete Delete a domain snapshot

Snapshot-dumpxml Dump XML for a domain snapshot

Snapshot-edit edit XML for a snapshot

Snapshot-info snapshot information

Snapshot-list List snapshots for a domain

Snapshot-parent Get the name of the parent of a snapshot

Snapshot-revert Revert a domain to a snapshot

Storage Pool (help keyword 'pool'):

Find-storage-pool-sources-as found potential storage pool source

Find-storage-pool-sources discovers potential storage pool sources

Pool-autostart automatically starts a pool

Pool-build establish Pool

Pool-create-as creates a pool from a set of variables

Pool-create creates a pool from a XML file

Pool-define-as defines a pool in a set of variables

Pool-define defines (but does not start) a pool in a XML file

Pool-delete Delete Pool

Pool-destroy destroy (stop) a pool

Pool information in pool-dumpxml XML

Pool-edit edits XML configuration for storage pool

Pool-info Storage Pool Information

Pool-list lists pools

Pool-name converts pool UUID to pool name

Pool-refresh refresh pool

Pool-start starts a (previously defined) inactive pool

Pool-undefine undefines an inactive pool

Pool-uuid converts a pool name to a pool UUID

Storage Volume (help keyword 'volume'):

Vol-clone clone a volume.

Vol-create-as creates volumes from a set of variables

Vol-create creates a volume from a XML file

Vol-create-from create a vol, using another volume as input

Vol-delete Delete Volume

Vol-download download volume contents to a file

Volume information in vol-dumpxml XML

Vol-info Storage Volume Information

Vol-key returns the volume key for a given volume name or path

Vol-list lists volumes

Vol-name returns the volume name for a given volume key or path

Vol-path returns the volume path for a given volume name or key

Vol-pool returns the storage pool for a given volume key or path

Vol-resize resize a vol

Vol-upload upload file contents to a volume

Vol-wipe wipe a vol

Virsh itself (help keyword 'virsh'):

Cd change the current directory

Connect connect (reconnect) to hypervisor

Echo echo arguments

Exit exits this non-interactive terminal

Help Printing help

Pwd print the current directory

Quit exits this non-interactive terminal

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

Network Security

Wechat

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

12
Report