{"id":1095,"date":"2022-04-04T13:50:58","date_gmt":"2022-04-04T05:50:58","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=1095"},"modified":"2022-04-05T16:03:54","modified_gmt":"2022-04-05T08:03:54","slug":"2-kvm%e8%99%9a%e6%8b%9f%e6%9c%ba%e7%9a%84virsh%e6%97%a5%e5%b8%b8%e7%ae%a1%e7%90%86%e5%92%8c%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=1095","title":{"rendered":"2.kvm\u865a\u62df\u673a\u7684virsh\u65e5\u5e38\u7ba1\u7406\u548c\u914d\u7f6e"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.\u5217\u8868list\uff08--all\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# virsh list ##\u67e5\u770b\u8fd0\u884c\u4e2d\u7684\u865a\u62df\u673a\r\n Id    Name                           State\r\n----------------------------------------------------\r\n\r\n&#91;root@test ~]# virsh list --all##\u67e5\u770b\u6240\u6709\u72b6\u6001\u7684\u865a\u62df\u673a\r\n Id    Name                           State\r\n----------------------------------------------------\r\n -     centos7                        shut off\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">2.\u5f00\u5173\u673a\uff0cstart\u548cshutdown<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# virsh start centos7 ##\u5f00\u542fcentos7\u865a\u62df\u673a\r\nDomain centos7 started\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n 2     centos7                        running\r\n\r\n&#91;root@test ~]# virsh shutdown centos7 ##\u5173\u95edcentos7\u865a\u62df\u673a\r\nDomain centos7 is being shutdown\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n -     centos7                        shut off\r\n\r\n&#91;root@test ~]# virsh destroy centos7 ##\u5f3a\u5236\u5173\u673a\uff08\u62d4\u7535\u6e90\u5f0f\u5173\u673a\uff09\r\nDomain centos7 destroyed\r\n##\u5f53\u6b63\u5e38\u5173\u673a\u65e0\u6cd5\u5173\u673a\u65f6\u4f7f\u7528\r\n&#91;root@test ~]# virsh reboot centos7 ##\u91cd\u542f\u865a\u62df\u673a\r\nDomain centos7 is being rebooted\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">3.\u5bfc\u51fa\u865a\u62df\u673a\u7684\u914d\u7f6e\u6587\u4ef6dumpxml<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# virsh dumpxml centos7 > \/opt\/vm_centos7.xml\r\n\u5907\u4efd\u865a\u62df\u673a\u7684\u78c1\u76d8\u6587\u4ef6\r\n&#91;root@test ~]# cp \/opt\/centos2.raw \/opt\/centos2.raw.bk\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">4.\u5220\u9664\u865a\u62df\u673aundefined<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# virsh undefine centos7 ##\u53d6\u6d88\u5b9a\u4e49\uff08\u9700\u5728\u5173\u673a\u540e\u64cd\u4f5c\uff09\r\nDomain centos7 has been undefined\r\n\r\n&#91;root@test ~]# virsh list \u2013all\uff08\u672a\u5173\u673a\u65f6\u53d6\u6d88\u5b9a\u4e49\u4f1a\u53d1\u73b0\u865a\u62df\u673a\u8fd8\u6d3b\u7740\uff09\r\n Id    Name                           State\r\n----------------------------------------------------\r\n 4     centos7                        running\r\n\r\n&#91;root@test ~]# virsh shutdown centos7 \uff08\u5173\u673a\u540e\u53d1\u73b0\u865a\u62df\u673a\u6ca1\u4e86\uff09\r\nDomain centos7 is being shutdown\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">5.\u865a\u62df\u673a\u7684\u6062\u590ddefine<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# virsh define \/opt\/vm_centos7.xml #\u4f7f\u7528xml\u6587\u4ef6\u6062\u590d\r\nDomain centos7 defined from \/opt\/vm_centos7.xml\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n -     centos7                        shut off\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">6.\u4fee\u6539\u914d\u7f6eedit\uff08\u81ea\u5e26\u8bed\u6cd5\u68c0\u67e5\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# mv \/opt\/centos2.raw \/opt\/centos7.raw\r\n&#91;root@test ~]# virsh start centos7 \r\nerror: Failed to start domain centos7\r\nerror: Cannot access storage file '\/opt\/centos2.raw': No such file or directory\r\n&#91;root@test ~]# virsh edit centos7\r\n#\u76f8\u5f53\u4e8evim \/etc\/libvirt\/qeum\/centos7.xml,\u4f46\u662fvim\u4fee\u6539\u7684\u6587\u4ef6\u9700\u8981\u91cd\u542flibvirtd\u8fdb\u7a0b\uff0cedit\u7f16\u8f91\u7684\u53ea\u9700\u8981\u91cd\u542f\u865a\u62df\u673a\u5373\u53ef\u751f\u6548\r\n#\u91cd\u542f\u6307\u7684\u662f\u5173\u673a\u518d\u5f00\u673a\uff0c\u4f7f\u7528reboot\u4e0d\u751f\u6548\u662f\u56e0\u4e3a\u8fdb\u7a0b\u4e00\u76f4\u5b58\u5728\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">7.\u865a\u62df\u673a\u91cd\u547d\u540d#domrename<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# virsh domrename centos7 web01#\u91cd\u547d\u540d\r\nerror: Requested operation is not valid: cannot rename active domain\r\n###\u4e0d\u80fd\u5bf9\u8fd0\u884c\u4e2d\u7684\u865a\u62df\u673a\u91cd\u547d\u540d\r\n&#91;root@test ~]# virsh shutdown centos7 \r\nDomain centos7 is being shutdown\r\n\r\n&#91;root@test ~]# virsh domrename centos7 web01\r\nDomain successfully renamed\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n -     web01                          shut off\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">8.\u6302\u8d77suspend\u548c\u7ee7\u7eed\u8fd0\u884cresume<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>##\u6302\u8d77\r\n&#91;root@test ~]# virsh suspend web01 \r\nDomain web01 suspended\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n 3     web01                          paused\r\n\r\n##\u7ee7\u7eed\u8fd0\u884c\r\n&#91;root@test ~]# virsh resume web01 \r\nDomain web01 resumed\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n 3     web01                          running\r\n\r\n\u6302\u8d77\u540e\u518d\u6b21\u5f00\u673a\u53d1\u73b0\u865a\u62df\u673a\u65f6\u95f4\u5df2\u7ecf\u4e0d\u540c\u6b65\u4e86\uff0c\u5efa\u8bae\u5b89\u88c5\u4e00\u4e2achronyd<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">9.\u67e5\u770b\u865a\u62df\u673a\u7aef\u53e3vncdisplay<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# virsh vncdisplay web01 \r\n:0\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">10.\u5bbf\u4e3b\u673a\u542f\u52a8\u81ea\u52a8\u5f00\u542f\u865a\u62df\u673a\uff08\u91cd\u542flibvirtd\u81ea\u52a8\u5f00\u542f\u865a\u62df\u673a\uff09autostart<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@test ~]# virsh autostart web01 \r\nDomain web01 marked as autostarted\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n 1     web01                          running\r\n\r\n&#91;root@test ~]# virsh shutdown web01 \r\nDomain web01 is being shutdown\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n -     web01                          shut off\r\n\r\n&#91;root@test ~]# systemctl restart libvirtd\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n 1     web01                          running\r\n\r\n#\u5f00\u673a\u81ea\u542f\u539f\u7406\r\n&#91;root@test ~]# ll \/etc\/libvirt\/qemu\/autostart\/\r\ntotal 0\r\nlrwxrwxrwx 1 root root 27 Jul 17 19:19 web01.xml -> \/etc\/libvirt\/qemu\/web01.xml\r\n\u5220\u9664\u8f6f\u8fde\u63a5\u865a\u62df\u673a\u81ea\u542f\u52a8\u81ea\u52a8\u5931\u6548\r\n&#91;root@test ~]# rm -f \/etc\/libvirt\/qemu\/autostart\/*\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n 1     web01                          running\r\n\r\n&#91;root@test ~]# virsh shutdown web01 \r\nDomain web01 is being shutdown\r\n\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n -     web01                          shut off\r\n\r\n&#91;root@test ~]# systemctl restart libvirtd\r\n&#91;root@test ~]# virsh list --all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n -     web01                          shut off\r\n\r\n#\u540c\u6837\u7684\u521b\u5efa\u4e00\u4e2a\u8f6f\u8fde\u63a5\u76f8\u5f53\u4e8e\u6267\u884c\u4e86\r\n&#91;root@test ~]# virsh autostart web01\r\n\u9664\u4e86\u67e5\u770b\u8f6f\u8fde\u63a5\u5224\u65ad\u54ea\u4e9b\u865a\u62df\u673a\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u4e86\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u4e0b\u65b9\u547d\u4ee4\u67e5\u770b\r\n&#91;root@test ~]# virsh list --autostart ##\u53ea\u80fd\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u865a\u62df\u673a\u6240\u4ee5\u8fd9\u91cc\u9700\u8981\u52a0--all\r\n Id    Name                           State\r\n----------------------------------------------------\r\n##\u5f53\u7136\u53d6\u6d88\u5f00\u673a\u81ea\u5df1\u542f\u52a8\u9664\u4e86\u5220\u9664\u8f6f\u8fde\u63a5\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\r\n&#91;root@test ~]# virsh autostart web01 --disable \r\nDomain web01 unmarked as autostarted\r\n\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">11.console\u547d\u4ee4\u884c\u63a7\u5236\u53f0<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u865a\u62df\u673a\u4e0a\u6267\u884c\u547d\u4ee4\u4fee\u6539\u5185\u6838\u53c2\u6570\uff08\u6ce8\u610f\u662f\u865a\u62df\u673a\u4e0d\u662f\u5bbf\u4e3b\u673a\uff09\r\n&#91;root@localhost ~]# grubby --update-kernel=ALL --args=\"console=ttyS0,115200n8\"\r\n&#91;root@localhost ~]# reboot\r\n\u5bbf\u4e3b\u673a\u6267\u884c\r\n&#91;root@test ~]# virsh console web01\r\n\u6267\u884c\u547d\u4ee4\u540e\u9700\u8981\u518d\u6309\u4e00\u6b21\u56de\u8f66\u8fdb\u5165\r\n\u8981\u9000\u51fa\u6309crtl+d\u4e0d\u884c\uff0c\u5f97\u6309crtl+]\u9000\u51fa\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">12.\u4f7f\u7528\u865a\u62df\u673a\u4fee\u6539\u865a\u62df\u673a\u5bc6\u7801set-user-password<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>##\u786e\u4fdd\u865a\u62df\u673a\u7684qemu-guest-agent.service\u8fdb\u7a0b\u5df2\u7ecf\u542f\u52a8\r\n&#91;root@localhost ~]# yum install qemu-guest-agent.x86_64\r\n&#91;root@localhost ~]# systemctl start qemu-guest-agent.service \r\n&#91;root@localhost ~]# systemctl enable qemu-guest-agent.service\r\n##\u5bbf\u4e3b\u673a\u64cd\u4f5c\u4fee\u6539\u5bc6\u7801\r\n&#91;root@test ~]# virsh set-user-password --user root --password 123 web01 \r\nPassword set successfully for root in web01\r<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1095"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1095"}],"version-history":[{"count":6,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1095\/revisions"}],"predecessor-version":[{"id":1105,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1095\/revisions\/1105"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}