virsh创建虚拟机

本文详细介绍了如何配置和管理虚拟机,包括设置内存、选择操作系统类型、创建虚拟机文件、分配vCPU、配置设备(如磁盘和网卡)、启动虚拟机、使用VNC进行远程访问等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 主机名查询出来的

转载于:https://my.oschina.net/hgfdoing/blog/514637

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值