第一次用virt-manager建立帶有OS的p_w_picpath時,在最後一步總會遇到下面這個錯誤。後來發現應該是libvirt的問題,選擇從新編譯安裝另外一個版本。這裏從新選擇的時libvirt-1.1.4node
Unable to complete install: 'Failed to connect socket to '/var/run/libvirt/virtlogd-sock': No such file or directory'python
libvirtError: Failed to connect socket to '/var/run/libvirt/virtlogd-sock': No such file or directorymysql
在用virt-manager建立帶有OS的p_w_picpath時,許kvm和libvirt安裝且正常運行,有以下輸出即可:sql
root@u-node4:/home/zxl# kvm-okubuntu
INFO: /dev/kvm existsvim
KVM acceleration can be usedapi
root@u-node4:/tool/libvirt-1.3.4# virsh list服務器
Id Name Stateapp
----------------------------------------------------dom
而後安裝qemu 和virt-manager
root@u-node4:/tool/libvirt-1.3.4# apt-get install qemu virt-manager
root@u-node4:~# virt-manager (若是出現DBUS問題,那麼在切換用戶時注意用su - 代替su)
報錯,找不到br100網卡
而且本實驗要建立的p_w_picpath中的虛擬機是要將虛擬網卡創建在網橋上的,即建立基於虛擬局域網的虛擬網卡。此虛擬局域網能夠讓位於同一臺物理服務器上的虛擬機再次組成一個局域網
root@u-node4~# vim /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.139.8
netmask 255.255.255.0
gateway 192.168.139.1
auto br100
iface br100 inet static
bridge_ports eth0
bridge_maxwait 0
bridge_stp off
bridge_fd 0
address 192.169.139.8
netmask 255.255.255.0
gateway 192.168.139.1
broadcast 192.168.139.255
root@u-node4:~#/etc/init.d/networking restart
root@u-node6:~# ifconfig
br100 Link encap:Ethernet HWaddr 00:0c:29:60:fa:7d
inet addr:192.169.139.8 Bcast:192.168.139.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe60:fa7d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2146 errors:0 dropped:0 overruns:0 frame:0
TX packets:67 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:140919 (140.9 KB) TX bytes:10782 (10.7 KB)
eth0 Link encap:Ethernet HWaddr 00:0c:29:60:fa:7d
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:749892 errors:0 dropped:0 overruns:0 frame:0
TX packets:253662 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1077881402 (1.0 GB) TX bytes:21269261 (21.2 MB)
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:175799 errors:0 dropped:0 overruns:0 frame:0
TX packets:175799 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:30344562 (30.3 MB) TX bytes:30344562 (30.3 MB)
virbr0 Link encap:Ethernet HWaddr 72:e7:c7:39:ff:28
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
vnet0 Link encap:Ethernet HWaddr fe:54:00:13:99:27
inet6 addr: fe80::fc54:ff:fe13:9927/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1898 errors:0 dropped:0 overruns:0 frame:0
TX packets:296 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:90591 (90.5 KB) TX bytes:89508 (89.5 KB)
點擊finish安裝虛擬機
當裝完操做系統,且安裝了虛擬機中須要使用的軟件後,就能夠將虛擬機關閉
在宿主機執行virsh destroy ubuntu-12.04即可關閉虛擬機
root@u-node4:~# virsh destroy ubuntu-12.04
Domain ubuntu-12.04 destroyed
root@u-node4:~# virsh list --all
Id Name State
----------------------------------------------------
- ubuntu-12.04 shut off
接下來須要保存虛擬機的定義文件和虛擬機p_w_picpath
root@u-node4:~# virsh dumpxml ubuntu-12.04 > ubuntu-12.04.xml
root@u-node4:~# vim ubuntu-12.04.xml
1 <domain type='kvm'>
2 <name>ubuntu-12.04</name>
3 <uuid>a4a93d3d-b573-9c1f-fa93-beaa9d3f301b</uuid>
4 <memory unit='KiB'>1004544</memory>
5 <currentMemory unit='KiB'>1004544</currentMemory>
6 <vcpu placement='static'>1</vcpu>
7 <os>
8 <type arch='x86_64' machine='pc-1.0-qemu-kvm'>hvm</type>
9 <boot dev='hd'/>
10 </os>
11 <features>
12 <acpi/>
13 <apic/>
14 <pae/>
15 </features>
16 <clock offset='utc'/>
17 <on_poweroff>destroy</on_poweroff>
18 <on_reboot>restart</on_reboot>
19 <on_crash>restart</on_crash>
20 <devices>
21 <emulator>/usr/bin/kvm</emulator>
22 <disk type='file' device='disk'>
23 <driver name='qemu' type='raw'/>
24 <source file='/var/lib/libvirt/p_w_picpaths/ubuntu-12.04.img'/>
25 <target dev='vda' bus='virtio'/>
26 <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0 x0'/>
27 </disk>
28 <disk type='block' device='cdrom'>
29 <driver name='qemu' type='raw'/>
30 <target dev='hdc' bus='ide'/>
31 <readonly/>
32 <address type='drive' controller='0' bus='1' target='0' unit='0'/>
33 </disk>
34 <controller type='usb' index='0'>
35 <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0 x2'/>
36 </controller>
37 <controller type='pci' index='0' model='pci-root'/>
38 <controller type='ide' index='0'>
39 <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0 x1'/>
40 </controller>
41 <interface type='bridge'>
42 <mac address='52:54:00:13:99:27'/>
43 <source bridge='br100'/>
44 <model type='virtio'/>
45 <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0 x0'/>
46 </interface>
47 <serial type='pty'>
48 <target port='0'/>
49 </serial>
50 <console type='pty'>
51 <target type='serial' port='0'/>
52 </console>
53 <input type='mouse' bus='ps2'/>
54 <graphics type='vnc' port='-1' autoport='yes'/>
55 <sound model='ich6'>
56 <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0 x0'/>
57 </sound>
58 <video>
59 <model type='cirrus' vram='9216' heads='1'/>
60 <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0 x0'/>
61 </video>
62 <memballoon model='virtio'>
63 <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0 x0'/>
64 </memballoon>
65 </devices>
66 </domain>
保存好虛擬機的定義文件後,找到第文件中關於虛擬機的硬盤p_w_picpath定義部分
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/lib/libvirt/p_w_picpaths/ubuntu-12.04.img'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0 x0'/>
</disk>
source file指明瞭虛擬磁盤p_w_picpath的全路徑,將此p_w_picpath剪切至保存目錄,如p_w_picpath目錄,則保存虛擬機p_w_picpath完畢
root@u-node6:~# mv /var/lib/libvirt/p_w_picpaths/ubuntu-12.04.img /p_w_picpath/
root@u-node6:~# mv ubuntu-12.04.xml /p_w_picpath/
因爲此虛擬機不在使用,則能夠udefine此虛擬機(udefine不是刪除,只是取消了此虛擬機的定義)
root@u-node4:~# virsh undefine ubuntu-12.04
Domain ubuntu-12.04 has been undefined
root@u-node4:~# virsh list --all
Id Name State
----------------------------------------------------
總結:
裝kvm,libvirt,virt-manager失敗許屢次的解決方法:
1:配置搜狐源
2:apt-get install qemu-kvm ubuntu-vm-builder bridge-utils
3: apt-get install qemu virt-manager(此時其實會裝libvirt-bin,有依賴,但可能運行virt-manager報錯,需最後purge掉)
4: apt-get install build-essential python-dev libxml2-dev libxslt-dev tgt lvm2 python-lxml unzip python-mysqldb mysql-client memcached openssl expect iputils-arping python-xattr python-lxml kvm gawk iptables ebtables sqlite3 sudo kvm vlan curl socat python-libxml2 iscsitarget iscsitarget-dkms open-iscsi build-essential libxml2 libxml2-dev make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms libxslt1.1 libxslt1-dev vlan gnutls-bin libgnutls-dev cdbs debhelper libncurses5-dev libreadline-dev libavahi-client-dev libparted0-dev libdevmapper-dev libudev-dev libpciaccess-dev libcap-ng-dev libnl-3-dev libapparmor-dev python-all-dev libxen-dev policykit-1 libyajl-dev libpcap0.8-dev libnuma-dev radvd libxml2-utils libnl-route-3-200 libnl-route-3-dev libnuma1 numactl libnuma-dbg libnuma-dev dh-buildinfo expect ebtables iptables iputils-ping iputils-arping sudo dnsmasq-base dnsmasq-utils
5: tar -xf libvirt-1.1.4.tar.gz
6:/configure --prefix=/usr --sysconfdir=/etc
7:make && make install
8:virt-manage 安裝虛擬機
此時若是報APP的錯誤,則執行apt-get purge libvirt-bin,而後進入到執行./configure的目錄執行make clean,在從新執行6和7步,即可.