kvm常見故障及解決方案

一、啟動虛擬機Connection reset by peer

# virsh start vmhost1error: Failed to start domain vmhost1error: Unable to read from monitor: Connection reset by peer

在虛擬機運行過程中關閉宿主伺服器就有可能導致這種情況出現,由於宿主伺服器中的kvm虛擬機控制器與安裝在kvm中的虛擬機會話被異常重置,所以我們可以如下解決:

# virsh managedsave-remove vmhost1# virsh start vmhost1

如果啟動查看/var/log/libvirt/qemu/vmhost1.log下log還報如下錯誤:

Cannot set up guest memory 'pc.ram': Cannot allocate memory

這個問題可能是分配給vmhost1分配的記憶體過大(甚至超過的物理主機的記憶體大小),或者可能是宿主機沒有足夠的記憶體分配給此虛擬機,導致無法啟動!

二、重Define虛擬機時無/usr/bin/kvm

error: Failed to define domain from hostname.xmlerror: Cannot find QEMU binary /usr/bin/kvm: No such file or directory

解決方法:

# ln -s /usr/libexec/qemu-kvm /usr/bin/kvm

三、error: internal error process exited while connecting to monitor

# virsh start vmhost1  
error: Failed to start domain vmhost1error: internal error process exited while connecting to monitor: kvm: -drive file=/dev/sp1368155439693/v1368544020461,if=none,id=drive-virtio-disk0,format=qcow2: could not open disk p_w_picpath /dev/sp1368155439693/v1368544020461: Invalid argument

分析:鏡像格式錯誤,用qemu-img info 檢查鏡像和xml配置文件中指定的type是否一致!

四、Unable to load library 'virt': libvirt.so

Unable to load library 'virt': libvirt.so: cannot open shared object file: No such file or directoryLinux下解決:      ln -s /usr/lib/libvirt.so.0   /usr/lib/libvirt.so    windows下解決:        將libvirt-0.dll改名為virt.dll

五、error: Refusing to undefine while domain managed save p_w_picpath exists

# virsh undefine vmhost1error: Refusing to undefine while domain managed save p_w_picpath existshttp://www.redhat.com/archives/libvir-list/2011-July/msg01219.html

解決方法:virsh undefine $domain  –managed-save

六、啟動libvirtd進程出錯

# /usr/local/sbin/libvirtd -d -l --config /usr/local/etc/libvirt/libvirtd.conf (編譯安裝的啟動方式)
error:/usr/local/sbin/libvirtd: initialization failed  try to install libpcap-devel RPM and rebuild libvirt  http://comments.gmane.org/gmane.comp.emulators.libvirt/58218apt-get install libpcap-dev  上面的方法好像都沒有效果,但是嘗試了http://wiki.libvirt.org/page/The_daemon_cannot_be_started說的,把配置文件里的  listen_tls = 0注釋取消(更奇怪的問題,在我的客戶端鏈接不對)

七、啟動虛擬機報錯

# virsh start vmhost1error: Failed to start domain vmhost1error: internal error process exited while connecting to monitor: Could not access KVM kernel module: No such file or directoryfailed to initialize KVM: No such file or directoryNo accelerator found!

上面的提示資訊就是因為QEMU在初始化階段因為無法找到kvm內核模組。

# modprobe kvm   #載入指定的模組

重啟電腦,進入bios介面,設置advance選項裡面的virtualization標籤為Enabled

通過命令 lsmod | grep kvm    #顯示已載入的模組

八、虛擬機遷移

# virsh migrate --live 1 qemu+tcp://192.168.0.121 --p2p --tunnelled --unsafe error: operation failed: Failed to connect to remote libvirt URI qemu+tcp://192.168.0.121(在URI後面加上/system,『system』相當於root用戶的訪問許可權)    #virsh migrate --live 2 qemu+tcp://192.168.0.121/system --p2p --tunnelled   error: Unsafe migration: Migration may lead to data corruption if disks use cache != none(加上--unsafe參數)#virsh migrate --live 2 qemu+tcp://192.168.0.121/system --p2p --tunnelled --unsafe error: Timed out during operation: cannot acquire state change lock (啟動虛擬機有時也會遇此錯誤),需要重啟libvirtd進程

九、virsh

error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused(libvirtd 進程沒有啟動,libvirtd是一個監聽客戶端請求的進程)# virsh -c qemu:///system listerror: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied  error: failed to connect to the hypervisor  (當前用戶沒有許可權,修改/etc/libvirt/libvirtd.conf,unix_sock_rw_perms = 0777,使所有用戶都有許可權讀寫)

轉:http://openskill.cn/article/146