程序员人生 网站导航

使用libvirt启动虚拟机

栏目:服务器时间:2016-07-07 13:45:23

准备xml文件:

<domain type='kvm'> <name>demo</name> <memory>524288</memory> <vcpu>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='hd'/> </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='/root/cirros.img'/> <target dev='hda' bus='ide'/> </disk> <disk type='file' device='cdrom'> <source file='/root/cirros.img'/> <target dev='hdb' bus='ide'/> </disk> <graphics type="vnc" autoport="yes" keymap="en-us" listen="0.0.0.0"/> </devices> </domain>


查看当前虚拟机列表:

[root@controller1 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     instance-00000073              shut off

使用demo.xml创建新的虚拟机
[root@controller1 ~]# virsh define demo.xm
Domain demo defined from demo.xml


[root@controller1 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 7     demo                           running
 -     instance-00000073              shut off




[root@controller1 ~]# virsh start demo
Domain demo started


[root@controller1 ~]# ps -auxf |grep qemu
root     10448  0.0  0.0 112640   976 pts/1    S+   10:55   0:00          \_ grep --color=auto qemu
root     10110 27.0  1.1 923984 94096 ?        Sl   10:55   0:05 /usr/libexec/qemu-kvm -name demo -S -machine pc-i440fx-rhel7.0.0,accel=kvm,usb=off -m 512 -realtime mlock=off -smp 1,sockets=1,cores=1,threads=1 -uuid b957acd3⑶777⑷b9d-b3b5-f4a59849e455 -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-demo/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/root/cirros.img,if=none,id=drive-ide0-0-0,format=qcow2 -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -drive file=/root/cirros.img,if=none,id=drive-ide0-0⑴,readonly=on,format=raw -device ide-cd,bus=ide.0,unit=1,drive=drive-ide0-0⑴,id=ide0-0⑴ -vnc 0.0.0.0:0 -k en-us -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 -msg timestamp=on
[root@controller1 ~]# ls


遇到的问题:主机内存不足:
主机还有多少内存
这里是1台控制节点,甚么虚拟机都不起,4G的内存也基本用完了
所以,控制节点内存需要大于4G,否则1台虚拟机都开启不了


[root@controller1 ~]# free -h
             total       used       free     shared    buffers     cached
Mem:          3.6G       3.4G       201M       229M        45M       154M
-/+ buffers/cache:       3.2G       401M
Swap:           0B         0B         0B
[root@controller1 ~]# 
如果给虚拟机512M内存,这里会报错:
Cannot set up guest memory 'pc.ram': Cannot allocate memory






------分隔线----------------------------
------分隔线----------------------------

最新技术推荐