logo
关于我们

技术分享

技术分享 virsh创建虚拟机

virsh创建虚拟机

2020-10-15

xml文件

注意点: 1.  设置memory的时候,注意unit的写法 2.  emulator的路径,写成一行 3.  能不分行写,一个标签,尽量写在一行4.  使用qemu-img管理工具创建虚拟机文件,例如:qemu-img create -f qcow2 test.qcow2 10G5.  创建的文件没有权限,需要将创建的虚拟机文件更改用户组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 主机名查询出来的

云祺备份软件,云祺容灾备份系统,虚拟机备份,数据库备份,文件备份,实时备份,勒索软件,美国,图书馆
  • 标签:
  • 技术分享

您可能感兴趣的新闻 换一批

现在下载,可享30天免费试用

立即下载