KVM故障調試經驗

來源:互聯網
上載者:User

本次在UBuntu12.04.2系統安裝KVM,隨後建立虛擬機器,又出現了新的問題。

現象:

ping不通虛擬機器,ssh登入不上,console方式登入不上, 虛擬機器無法shutdown,貌似電源管理也沒有安裝成功。

先來解決網路問題:

還好可以通過virt-cat來檢查虛擬機器內部的檔案。

先關閉虛擬機器

virsh destroy vm1

然後檢查網卡設定檔案:

root@dbkvm:~# virt-cat -d vm1 /etc/network/interfaces# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).# The loopback network interfaceauto loiface lo inet loopback# The primary network interfaceauto eth0iface eth0 inet static        address 192.168.1.51        netmask 255.255.255.0         network 192.168.1.0        broadcast 192.168.1.255        gateway 192.168.1.1         # dns-* options are implemented by the resolvconf package, if installed        dns-nameservers 8.8.8.8        dns-search localdomain

這個dns-search localdomain看上去很奇怪。一般是defaultdomain. 

localdomain是因為host機器的/etc/hosts中配置成了

127.0.0.1       localhost.localdomain dbkvm

將其換成這種配置:

127.0.0.1localhost127.0.1.1dbkvm

再建立虛擬機器,網路正常了。可以ping通,可以ssh登入。 console問題還有。

虛擬機器裡面的網路設定dns-search 被設定成了defaultdomain.

因此推測是hosts檔案的配置錯誤,導致虛擬機器中網卡設定的dns-search錯誤,導致無法串連網路,因此不能在建立過程中從網路下載安裝openssh-server.

來看一下電源管理

如果不安裝電源管理,就不能在host主機通過shutdown關閉虛擬機器。

在建立vm的選項中需要補上:

--addpkg=acpid

事後彌補就要登入到虛擬機器中,然後運行命令:

apt-get install acpid

再來處理console不能登入的問題。

先停止虛擬機器。

virsh stop vm1

準備一個檔案ttyS0.conf, 內容如下:

# ttyS0.conf - getty# This service maintains a getty on ttyS0 from the point the system is# started until it is shut down again.start on stopped rc RUNLEVEL=[2345]stop on runlevel [!2345]respawn

安裝guestfish程式, 這會安裝一些常用的virt工具,比如virt-edit等,安裝時回答no.

apt-get install guestfish

還要安裝

apt-get install libguestfs-tools

現在用virt-copy-in將檔案複製到vm的/etc/init目錄中:

virt-copy-in -d vm1 ttyS0.conf /etc/init

然後調用virsh edit vm1 來編輯vm1的設定檔,添加下面的內容:

<devices>  ...  <serial type='pty'>    <source path='/dev/pts/2'/>    <target port='0'/>  </serial>  <console type='pty' tty='/dev/pts/2'>    <source path='/dev/pts/2'/>    <target port='0'/>  </console></devices>

最後試用一下:

virsh start vm1Domain vm1 startedroot@dbkvm:~/kvm_scripts# virsh console vm1Connected to domain vm1Escape character is ^]Ubuntu 12.04.2 LTS vm1 ttyS0vm1 login: rootPassword: Last login: Thu May  2 09:21:03 UTC 2013 from 192.168.1.4 on pts/1Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-41-virtual x86_64)

可以了。

所有問題的根源都出在那個不正確的host機器上的/etc/hosts配置。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.