spice\qemu–虛擬機器建立(2)

來源:互聯網
上載者:User

一、先建立一個簡單的虛擬機器:
     1.建立一個10G的虛擬磁碟:

   #qemu-img create -f qcow2 xp.qcow2 10

     2.建立虛擬機器:

   #qemu-system-x86_64 -hda xp.qcow2 -m 1024 -boot d -cdrom ubuntu_x86_64.iso -spice port=5999,disable-ticketing

    註:-d指光碟機啟動安裝ubuntu_x86_64.iso,-c從硬碟啟動,-n是從網路啟動。如果是-dcn,則按順序找啟動項。

    3.用spice命令串連:
     使用spice串連此虛擬機器,上面加了-spice port = 5999,disable-ticketing(預設是 VNC)

   #spicec -h 10.20.65.240 -p 5999

二、建立一個常用的虛擬機器:

        同樣建立一個磁碟檔案,在/opt/keqi/monitors目錄下建立一個monitor檔案:

    #touch /opt/keqi/monitors/730d16b6-985c-4393-8910-3ccc12c200132

       同時配置網路,在/opt/keqi/下建立指令碼netconfig.sh

#!/bin/shifconfig eth0 0.0.0.0 promisc upbrctl addbr vSwitch0brctl addif vSwitch0 eth0ifconfig vSwitch0 hw ether 00:26:9e:fe:77:f0ifconfig vSwitch0 10.20.65.52 netmask 255.255.255.0 uproute add default gw 10.20.65.254 dev vSwitch0

   在該目錄下建立子目錄.network,並在其中建立指令碼:

     if-down:

#!/bin/bashif [ -n "$1" ];then /sbin/ifconfig $1 down /usr/sbin/tunctl -d $1   exit 0else   exit 1fi

    if-up:

#!/bin/bashif [ -n "$1" ];then    iface=$1    s=`echo $1 | cut -d"-" -f 2`    type=${s:0:1}    num=${s:1}    if [ "s" = $type ];then                net=vSwitch$num    else                if [ "v" = $type ];then                        net=vLan-$num                else                        net=eth$num                fi    fi# sudo has error in redhat     /usr/sbin/tunctl -u `whoami` -t $iface     /sbin/ip link set $iface up    sleep 0.5s     /usr/sbin/brctl addif $net $iface    exit 0else    echo "Error: no interface specified"

       在一個終端 啟動虛擬機器命令如下:

/usr/local/bin/qemu-system-x86_64 -enable-kvm -M pc -nodefconfig -nodefaults -rtc base=localtime,clock=host -chardev socket,id=monitor,path=/opt/keqi/monitors/730d16b6-985c-4393-8910-3ccc12c200132,server,nowait -mon chardev=monitor,mode=readline -smp 1 -m 1024 -name UbuntuD-1110 -boot order=c -drive if=none,id=drive-fdc0-0-0,readonly=on,format=raw -global isa-fdc.driveA=drive-fdc0-0-0 -drive file=/opt/datastore/default/ubuntu-11.10-desktop-amd64.iso,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -drive media=disk,file=/opt/datastore/default/UD_11_10.qcow2,if=none,id=drive-ide0-0-0,format=qcow2,cache=writethrough -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -net nic,model=rtl8139,macaddr=00:e0:4c:31:c0:bd,vlan=0 -net tap,script=/opt/keqi/.network/if-up,downscript=/opt/keqi/.network/if-down,ifname=tap-s0-66,vlan=0 -vga cirrus -soundhw ac97 -cpu qemu64,+ssse3,+sse4.1,+sse4.2,+x2apic -spice addr=0.0.0.0,port=5906,password=11111111 -usb -usbdevice tablet -device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0 -chardev spicevmc,name=vdagent,id=vdagent -device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,name=com.redhat.spice.0

       具體各個命令含義,到qemu官網查看。(注意:命令中file=/opt/datastore/default/ubuntu-11.10-desktop-amd64.iso 是你安裝系統iso路徑)

     在另一個終端串連:

   #spicec -h 10.20.65.52 -p 5906 -w 11111111

    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.