virsh KVM管理工具
virsh所有的命令
Domain Management (help keyword 'domain'):attach-device attach device from an XML fileattach-disk attach disk deviceattach-interface attach network interfaceautostart autostart a domainblkdeviotune Set or query a block device I/O tuning parameters.blkiotune Get or set blkio parametersblockcommit Start a block commit operation.blockcopy Start a block copy operation.blockjob Manage active block operationsblockpull Populate a disk from its backing image.blockresize Resize block device of domain.change-media Change media of CD or floppy driveconsole connect to the guest consolecpu-baseline compute baseline CPUcpu-compare compare host CPU with a CPU described by an XML filecpu-stats show domain cpu statisticscreate create a domain from an XML filedefine define (but don't start) a domain from an XML filedesc show or set domain's description or title destroy destroy (stop) a domaindetach-device detach device from an XML filedetach-disk detach disk devicedetach-interface detach network interfacedomdisplay domain display connection URIdomfstrim Invoke fstrim on domain's mounted filesystems.domhostname print the domain's hostname domid convert a domain name or UUID to domain iddomif-setlink set link state of a virtual interfacedomiftune get/set parameters of a virtual interfacedomjobabort abort active domain jobdomjobinfo domain job informationdomname convert a domain id or UUID to domain namedompmsuspend suspend a domain gracefully using power management functionsdompmwakeup wakeup a domain from pmsuspended statedomuuid convert a domain name or id to domain UUIDdomxml-from-native Convert native config to domain XMLdomxml-to-native Convert domain XML to native configdump dump the core of a domain to a file for analysisdumpxml domain information in XMLedit edit XML configuration for a domaininject-nmi Inject NMI to the guestsend-key Send keycodes to the guestsend-process-signal Send signals to processeslxc-enter-namespace LXC Guest Enter Namespacemanagedsave managed save of a domain statemanagedsave-remove Remove managed save of a domainmaxvcpus connection vcpu maximummemtune Get or set memory parametersmigrate migrate domain to another hostmigrate-setmaxdowntime set maximum tolerable downtimemigrate-compcache get/set compression cache sizemigrate-setspeed Set the maximum migration bandwidthmigrate-getspeed Get the maximum migration bandwidthmc-disable disable mc migration for domainnumatune Get or set numa parametersqemu-attach QEMU Attachqemu-monitor-command QEMU Monitor Commandqemu-agent-command QEMU Guest Agent Commandqemu-agent-command2 QEMU Guest Agent Commandreboot reboot a domainreset reset a domainrestore restore a domain from a saved state in a fileresume resume a domainsave save a domain state to a filesave-image-define redefine the XML for a domain's saved state filesave-image-dumpxml saved state domain information in XMLsave-image-edit edit XML for a domain's saved state fileschedinfo show/set scheduler parametersscreenshot take a screenshot of a current domain console and store it into a filesetmaxmem change maximum memory limitsetmem change memory allocationsetvcpus change number of virtual CPUsshutdown gracefully shutdown a domainstart start a (previously defined) inactive domainsuspend suspend a domainttyconsole tty consoleundefine undefine a domainupdate-device update device from an XML filevcpucount domain vcpu countsvcpuinfo detailed domain vcpu informationvcpupin control or query domain vcpu affinityemulatorpin control or query domain emulator affinityvncdisplay vnc displayDomain Monitoring (help keyword 'monitor'):domblkerror Show errors on block devicesdomblkinfo domain block device size informationdomblklist list all domain blocksdomblkstat get device block stats for a domaindomcontrol domain control interface statedomif-getlink get link state of a virtual interfacedomiflist list all domain virtual interfacesdomifstat get network interface stats for a domaindominfo domain informationdommemstat get memory statistics for a domaindomstate domain statelist list domainsHost and Hypervisor (help keyword 'host'):capabilities capabilitiesfreecell NUMA free memoryhostname print the hypervisor hostnamenode-memory-tune Get or set node memory parametersnodecpumap node cpu mapnodecpustats Prints cpu stats of the node.nodeinfo node informationnodememstats Prints memory stats of the node.nodesuspend suspend the host node for a given time durationsysinfo print the hypervisor sysinfouri print the hypervisor canonical URIversion show versionInterface (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 itiface-commit commit changes made since iface-begin and free restore pointiface-define define (but don't start) a physical host interface from an XML fileiface-destroy destroy a physical host interface (disable it / "if-down")iface-dumpxml interface information in XMLiface-edit edit XML configuration for a physical host interfaceiface-list list physical host interfacesiface-mac convert an interface name to interface MAC addressiface-name convert an interface MAC address to interface nameiface-rollback rollback to previous saved configuration created via iface-beginiface-start start a physical host interface (enable it / "if-up")iface-unbridge undefine a bridge device after detaching its slave deviceiface-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 filenwfilter-dumpxml network filter information in XMLnwfilter-edit edit XML configuration for a network filternwfilter-list list network filtersnwfilter-undefine undefine a network filterNetworking (help keyword 'network'):net-autostart autostart a networknet-create create a network from an XML filenet-define define (but don't start) a network from an XML filenet-destroy destroy (stop) a networknet-dumpxml network information in XMLnet-edit edit XML configuration for a networknet-info network informationnet-list list networksnet-name convert a network UUID to network namenet-start start a (previously defined) inactive networknet-undefine undefine an inactive networknet-update update parts of an existing network's configurationnet-uuid convert a network name to network UUIDNode Device (help keyword 'nodedev'):nodedev-create create a device defined by an XML file on the nodenodedev-destroy destroy (stop) a device on the nodenodedev-detach detach node device from its device drivernodedev-dumpxml node device details in XMLnodedev-list enumerate devices on this hostnodedev-reattach reattach node device to its device drivernodedev-reset reset node deviceSecret (help keyword 'secret'):secret-define define or modify a secret from an XML filesecret-dumpxml secret attributes in XMLsecret-get-value Output a secret valuesecret-list list secretssecret-set-value set a secret valuesecret-undefine undefine a secretSnapshot (help keyword 'snapshot'):snapshot-create Create a snapshot from XMLsnapshot-create-as Create a snapshot from a set of argssnapshot-current Get or set the current snapshotsnapshot-delete Delete a domain snapshotsnapshot-dumpxml Dump XML for a domain snapshotsnapshot-edit edit XML for a snapshotsnapshot-info snapshot informationsnapshot-list List snapshots for a domainsnapshot-parent Get the name of the parent of a snapshotsnapshot-revert Revert a domain to a snapshotStorage Pool (help keyword 'pool'):find-storage-pool-sources-as find potential storage pool sourcesfind-storage-pool-sources discover potential storage pool sourcespool-autostart autostart a poolpool-build build a poolpool-create-as create a pool from a set of argspool-create create a pool from an XML filepool-define-as define a pool from a set of argspool-define define (but don't start) a pool from an XML filepool-delete delete a poolpool-destroy destroy (stop) a poolpool-dumpxml pool information in XMLpool-edit edit XML configuration for a storage poolpool-info storage pool informationpool-list list poolspool-name convert a pool UUID to pool namepool-refresh refresh a poolpool-start start a (previously defined) inactive poolpool-undefine undefine an inactive poolpool-uuid convert a pool name to pool UUIDStorage Volume (help keyword 'volume'):vol-clone clone a volume.vol-create-as create a volume from a set of argsvol-create create a vol from an XML filevol-create-from create a vol, using another volume as inputvol-delete delete a volvol-download download volume contents to a filevol-dumpxml vol information in XMLvol-info storage vol informationvol-key returns the volume key for a given volume name or pathvol-list list volsvol-name returns the volume name for a given volume key or pathvol-path returns the volume path for a given volume name or keyvol-pool returns the storage pool for a given volume key or pathvol-resize resize a volvol-upload upload file contents to a volumevol-wipe wipe a volVirsh itself (help keyword 'virsh'):cd change the current directoryconnect (re)connect to hypervisorecho echo argumentsexit quit this interactive terminalhelp print helppwd print the current directoryquit quit this interactive terminal View Codevirsh 常用命令
1.virsh# list --all ? ? 所有KVM上承載的虛擬機 包括開機和關機的
2.virsh# dominfo 虛擬機的常規信息(CPU 內存規格 內存使用情況)
virsh命令管理虛擬機
libvirt有兩種控制方式,命令行和圖形界面。
1.圖形界面:通過執行名virt-manager,啟動libvirt的圖形界面,在圖形界面下可以一步一步的創建虛擬機,管理虛擬機,還可以直接控制虛擬機的桌面。
2.命令行就是接下來我所說的。如何通過命令行來控制虛擬機。
創建虛擬機?
在/etc/libvirt/qemu下新建xml文件,如node.xml。需要有內存、cpu、硬盤設置、光驅以及vnc等等。以下是我根據Openstack啟的虛機修改而成,沒辦法,直接用Openstack的文件啟動虛機會失敗的,網橋不兼容什么的原因,具體的我忘了,原諒我那只有7秒鐘的記憶吧~代碼貼到下面了:
1 <domain type='qemu'>2 <name>node3</name> 3 <uuid>84b31010-6124-4529-baf9-bae25e18d933</uuid> 4 <memory unit='KiB'>524288</memory> 5 <currentMemory unit='KiB'>524288</currentMemory> 6 <vcpu placement='static'>1</vcpu> 7 <sysinfo type='smbios'> 8 <system> 9 <entry name='manufacturer'>Red Hat Inc.</entry> 10 <entry name='product'>OpenStack Nova</entry> 11 <entry name='version'>2014.1.1-2.el6</entry> 12 <entry name='serial'>421c7a3a-7f61-cde9-13cb-8b5804fc62cc</entry> 13 <entry name='uuid'>84b31010-6124-4529-baf9-bae25e18d933</entry> 14 </system> 15 </sysinfo> 16 <os> 17 <type arch='x86_64' machine='rhel6.5.0'>hvm</type> 18 <boot dev='hd'/> //硬盤啟動 19 <smbios mode='sysinfo'/> 20 </os> 21 <features> 22 <acpi/> 23 <apic/> 24 </features> 25 <cpu mode='host-model'> 26 <model fallback='allow'/> 27 </cpu> 28 <clock offset='utc'/> 29 <on_poweroff>destroy</on_poweroff> 30 <on_reboot>restart</on_reboot> 31 <on_crash>destroy</on_crash> 32 <devices> 33 <emulator>/usr/libexec/qemu-kvm</emulator> 34 <controller type='usb' index='0'> 35 <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> 36 </controller> 37 <memballoon model='virtio'> 38 <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> 39 </memballoon> 40 </devices> 41 </domain> View Code代碼分析:
1.<domain type='kvm'>?? ???????? ? 域類型,也可以是xen
2.<name>node3</name> ?????? ? 虛擬機的名字
3.<memory unit='KiB'>524288</memory>? ? ? ? ? 虛擬機的最大內存
4.<currentMemory unit='KiB'>524288</currentMemory>? 虛擬機當前的內存
5.<vcpu>2</vcpu> 該虛擬機的cpu數
6.<boot dev='hd'/> hd表示從硬盤啟動,cdrom表示從光盤啟動
7.<type arch='x86_64' machine='rhel6.5.0'>hvm</type> 表示全虛擬化
其實還有好多其他的屬性:
1.<console type='pty'> ? console用來代表交互性的控制臺
2.<interface type='bridge'>?? 網橋
3.<source bridge='virbr0'/> 網橋名
4.<mac address='00:16:36:1e:1d:04'/> MAC地址
5.<graphics type='vnc' autoport='yes' keymap='en-us'/>?????? 圖形類型
編輯之后就可以保存退出了。
啟動虛擬機?
1 virsh define /etc/libvirt/qemu/node3.xml 2 virsh start node3第一行命令就是創建定義也就是創建一個虛擬機。第二行就是啟動剛剛創建的虛擬機,如果啟動成功,可以使用命令
1 virsh list查看剛剛啟動的虛擬機。
遷移虛擬機?
在進行遷移之前,需要先配置一下你的兩臺物理機,具體配置方法請移步?Openstack虛擬機熱遷移?,然后參照此文進行配置。
配置完成后先使用命令行
1 virsh -c qemu+ssh://ip/system進行測試,如果可以進入virsh然后可以進行如下的命令進行遷移:
1 virsh migrate --live qemu+ssh://ip/system --unsafe其它操作
virsh start x ??????????????????????????????? 啟動名字為x的非活動虛擬機
virsh create x.xml??????????????????? ? 創建虛擬機(創建后,虛擬機立即執行,成為活動主機)
virsh suspend x ?????????????????????? ? ?? 暫停虛擬機
virsh resume x ????????????????????? ? ? ? 啟動暫停的虛擬機
virsh shutdown x ?????????????????? 正常關閉虛擬機
virsh destroy x ???????????????????????? ? ? 強制關閉虛擬機
virsh dominfo x ???????????????????????????? 顯示虛擬機的基本信息
virsh domname 2?????????????????????????????????? 顯示id號為2的虛擬機名
virsh domid x ?????????????????????????????? 顯示虛擬機id號
virsh domuuid x ?????????????????????? ? ?? 顯示虛擬機的uuid
virsh domstate x ???????????????????????? 顯示虛擬機的當前狀態
virsh dumpxml x ????????????????????? ? ?? 顯示虛擬機的當前配置文件(可能和定義虛擬機時的配置不同,因為當虛擬機啟動時,需要給虛擬機分配id號、uuid、vnc端口號等等)
virsh setmem x 512000????????????????? 給不活動虛擬機設置內存大小
virsh edit x ????????????????????????????????? 編輯配置文件(一般是在剛定義完虛擬機之后)
PS:本博客歡迎轉發,但請注明博客地址及作者~
博客地址:?http://www.cnblogs.com/voidy/
<。)#)))≦
?
轉載于:https://www.cnblogs.com/Bingo0-python/p/6896798.html
總結
以上是生活随笔為你收集整理的virsh KVM管理工具的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NRF24L01
- 下一篇: 基于koa2开发的用户中心