服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Ubuntu - UBuntu系统安装KVM创建虚拟机遭遇故障的解决方法

UBuntu系统安装KVM创建虚拟机遭遇故障的解决方法

2019-11-21 18:51Ubuntu教程网 Ubuntu

ping不通虚拟机,ssh登录不上,console方式登录不上, 虚拟机无法shutdown,貌似电源管理也没有安装成功

本次在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 interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface 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.1 localhost
127.0.1.1 dbkvm

 

再创建虚拟机,网络正常了。可以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程序:

 

复制代码

代码如下:


apt-get install guestfish


现在用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 vm1
Domain vm1 started
root@dbkvm:~/kvm_scripts# virsh console vm1
Connected to domain vm1
Escape character is ^]
Ubuntu 12.04.2 LTS vm1 ttyS0
vm1 login: root
Password:
Last login: Thu May 2 09:21:03 UTC 2013 from 192.168.1.4 on pts/1
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-41-virtual x86_64)

 

可以了。所有问题的根源都出在那个不正确的host机器上的/etc/hosts配置。

延伸 · 阅读

精彩推荐
  • UbuntuUbuntu下安装Chrome的方法分享

    Ubuntu下安装Chrome的方法分享

    本文给大家分享的是Ubuntu下安装Chrome的方法,安装的过程中发现还是挺麻烦的,就记录下来推荐给大家,有需要的小伙伴可以参考下。...

    Ubuntu教程网3862021-10-25
  • Ubuntu如何在ubuntu系统中安装pycharm工具并运行

    如何在ubuntu系统中安装pycharm工具并运行

    在Windows系统中安装pycharm,只需要下载安装包,然后根据指令一步一步操作;而在Linux系统中的Ubuntu中安装pycharm,需要下载安装包,还有安装相关的其他软件...

    百度经验12082019-10-21
  • UbuntuWSL、WSL2与Ubuntu性能大PK

    WSL、WSL2与Ubuntu性能大PK

    科技媒体 Phoronix 对 Windows 10 May 2020 中 WSL 和 WSL 2 的性能进行了测试,参与测试的发行版为 Ubuntu 20.04 on WSL/WSL2 ,以及 Ubuntu 20.04 LTS,均被安装在除 Windows 之...

    开源中国29412020-06-23
  • UbuntuUbuntu20.04开启root账户的方法步骤

    Ubuntu20.04开启root账户的方法步骤

    这篇文章主要介绍了Ubuntu20.04开启root账户的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们...

    缀梦13002020-08-01
  • UbuntuUbuntu Gnome下如何修改应用图标icon?

    Ubuntu Gnome下如何修改应用图标icon?

    最近有些朋友问小编Ubuntu Gnome下如何修改应用图标icon?今天小编要为大家分享的是Ubuntu Gnome下修改应用图标icon的方法;有需要的朋友一起去看看吧...

    服务器之家6412019-06-01
  • UbuntuUbuntu17.10怎么添加日历事项? Ubuntu添加行程提醒的教程

    Ubuntu17.10怎么添加日历事项? Ubuntu添加行程提醒的教程

    Ubuntu17.10怎么添加日历事项?Ubuntu17.10系统中有一个日程管理功能,可以在日历中添加行程提醒,下面我们就来看看Ubuntu添加行程提醒的教程,需要的朋友可...

    服务器之家2812019-06-19
  • UbuntuUbuntu 15.04升级到Ubuntu 15.10的详细教程

    Ubuntu 15.04升级到Ubuntu 15.10的详细教程

    ubuntu15.04怎么升级到ubuntu15.10?又该升级系统了,但是很多人对ubuntu系统很不熟悉,下面我们一起来看看ubuntu15.04升级ubuntu15.10的详细教程,需要的朋友可以...

    服务器之家4562019-07-02
  • UbuntuUbuntu安装和卸载CUDA和CUDNN的实现

    Ubuntu安装和卸载CUDA和CUDNN的实现

    这篇文章主要介绍了Ubuntu安装和卸载CUDA和CUDNN的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们...

    夜雨飘零14632020-08-04