温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

virsh创建虚拟机的方法介绍

发布时间:2021-08-05 09:39:06 来源:亿速云 阅读:183 作者:chen 栏目:云计算

本篇内容介绍了“virsh创建虚拟机的方法介绍”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

xml文件

注意点: 1. 设置memory的时候,注意unit的写法 2. emulator的路径,写成一行 3. 能不分行写,一个标签,尽量写在一行 4. 使用qemu-img管理工具创建虚拟机文件,例如:qemu-img create -f qcow2 test.qcow2 10G 5. 创建的文件没有权限,需要将创建的虚拟机文件更改用户组sudo chown hgf:root /var/lib/libvirt/images/test.qcow2. 即执行start的用户的名下

<domain type="kvm">
    <name>centos</name>

    <memory unit="MiB">1024</memory>
    <currentMemory unit="MiB">1024</currentMemory>

    <vcpu>2</vcpu>

    <os>
        <type arch="x86_64" machine="pc">hvm</type>
        <boot dev="hd" />
        <boot dev="cdrom" />
    </os>

    <features>
        <acpi />
        <apic />
        <pae />
    </features>

    <clock offset="localtime" />

    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>destroy</on_crash>

    <devices>
        <emulator>/usr/libexec/qemu-kvm</emulator>

        <disk type="file" device="disk">
            <driver name="qemu" type="qcow2"/>
            <source file="/var/lib/libvirt/images/test.qcow2" />
            <target dev="hda" bus="ide"/>
        </disk>

        <disk type="file" device="cdrom">
            <source file="/home/hgf/Dowmload/CentOS-7.0-1406-x86_64-DVD.iso" />
            <target dev="hdb" bus="ide"/>
        </disk>

        <interface type="bridge">
            <source bridge="virbr0"/>
        </interface>

        <input type="mouse" bus="ps2" />
        <graphics type="vnc" port="-1" autoport="yes" listen="0.0.0.0" keymap="en-us" />

    </devices>


</domain>

定义虚拟机

virsh define test_virsh.xml

使用virsh undefine [虚拟主机名]来取消虚拟机的定义

启动虚拟机

virsh start cetos

start后面的参数,是之前用xml定义的虚拟机的name标签指定的,也可以在define虚拟机后,使用命令virsh list --alll

vnc查看虚拟机

查询虚拟机所使用的vnc端口 virsh vncdisplay centos

vncviewer安装

yum install vnc(安扎ungde是tiger vncviewer) 打开vnc viewer后,在地址栏输入IP地址:序号,如127.0.0.1:0

注意:此处的序号是使用virsh vncdisplay 主机名查询出来的

“virsh创建虚拟机的方法介绍”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI