libvirt 问题解决记录集(更新中)

本篇记录在使用libvirt的时候遇到的一些情况,即解决方法.

出现Permission denied

1
2
3
[root@localhost vm]# virsh start centos
error: Failed to start domain centos
error: internal error process exited while connecting to monitor: qemu-system-x86_64: -drive file=/home/d/shixun/vm/vdisk.img,if=none,id=drive-ide0-0-0,format=qcow2: could not open disk image /home/d/shixun/vm/vdisk.img: Permission denied

解决:/etc/libvirt/qemu.conf

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
# Some examples of valid values are:
#
# user = "qemu" # A user named "qemu"
# user = "+0" # Super user (uid=0)
# user = "100" # A user named "100" or a user with uid=100
#
user = "root"
 
# The group for QEMU processes run by the system instance. It can be
# specified in a similar way to user.
group = "root"
 
# Whether libvirt should dynamically change file ownership
# to match the configured user/group above. Defaults to 1.
# Set to 0 to disable file ownership changes.
dynamic_ownership = 0

我的这个没能解决问题

/etc/init.d/libvirtd restart 不管用

libvirt遇到死锁

在使用virsh对虚拟机进行动态迁移时,虚拟机没有开启.于是就去开启虚拟机,但是却发现无法运行.

1
2
3
Error starting domain: Timed out during operation: cannot acquire state change lock
 
libvirtError: Timed out during operation: cannot acquire state change lock

我进行了以下的步骤

1
2
3
4
5
6
7
8
9
virsh undefine centos
 
####Login as a root user and kill the libvirtd.
 
killall -9 libvirtd
 
rm /var/run/libvirtd.pid   ##### Remove the libvirtd pid file.
 
/etc/init.d/libvirtd  restart   #### Restart libvirtd.

在尝试上面的操作后,不起作用.

修改一下的domain的xml文件中的name标签,给虚拟机改个名字,期间我还删除了domain的xml文件里的qemu:commandline里面信息,重新define后就可以运行了.

迁移需要FQDN

在进行迁移的时候使用命令 virsh migrate –live ubuntu qemu+ssh://dest_ip/system

1
error: internal hostname on destination resolved to localhost, but migration requires an FQDN

解决:ssh进入到dest host机器,运行hostname domain 就好了.其中domian是一个域名.将接下来就可以进行迁移了.

启动nfs出现问题

启动NFS服务,出现问题

1
Failed to issue method call: Unit nfsserver.service failed to load: No such file or directory. See system logs and 'systemctl status nfsserver.service' for details.

解决:按照教程来就好了

1
2
3
4
5
6
# vim /etc/exports
/var/lib/libvirt/images *.example.com(rw,no_root_squash,sync)
 
# service nfs start
 
# mount -t nfs storage_host:/var/lib/libvirt/images /var/lib/libvirt/images

挂载nfs出现问题

当去mount远程的nfs服务器,出现问题了.

mount.nfs: access denied by server while mounting 211.87.***.53:/mnt/nfs

解决:原来发现,在/etc/exports中,没有将/mnt/nfs添加进去,只能将里面有的文件夹才能mount到本机来.

可以先umoutn /mnt/nfs ,然后在mount看看能否成功

virsh关闭虚拟机

virsh shutdown 关闭虚拟机没起作用

解决:需要在虚拟机里安装一些东西

1
2
3
yum install acpid
chkconfig acpid on
service acpid start

virsh无法使用ssh协议访问远程机器

当我去远程查询信息的时候,virsh -c qemu+ssh://211.87.***.88/system list 的时候出现了下面的问题.

1
2
3
error: failed to connect to the hypervisor
error: no valid connection
error: End of file while reading data: : Input/output error

查看日志 cat /var/log/secure | grep sshd 发现是我这里主动发出断开的.难道是检测到libvirtd有些问题导致的?

当时使用virt-manage可以查询到远程的信息.估计是sshd出现的问题把.

解决:我没有重新安装sshd,我是通过tcp协议进行迁移的,因为是做测试,所以没有考虑安全的问题.具体使用tcp进行迁移,查看virsh使用qemu+tcp访问远程libvirtd .

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Java项目使用libvirt,可以参考以下步骤: 1. 下载并安装libvirt的开发包和C语言开发环境。可以从libvirt官方网站下载对应版本的libvirt开发包,然后安装到本地系统。 2. 安装并配置Java Native Access库(JNA)。JNA是一个用于在Java直接访问本地库和非托管代码的工具。可以从JNA的官方网站下载JNA的jar包,并将其添加到Java项目的classpath。 3. 导入libvirt的Java封装库。可以从libvirt的官方网站下载Java封装库,然后将其添加到Java项目的classpath。 4. 在Java项目使用libvirt的API。可以使用Java封装库提供的API来访问libvirt的功能,例如连接到本地或远程的libvirt服务、创建虚拟机、启动虚拟机等。 以下是一个简单示例代码: ```java import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.LibvirtException; public class LibvirtExample { public static void main(String[] args) throws LibvirtException { // 连接到本地的libvirt服务 Connect conn = new Connect("qemu:///system"); // 获取指定名称的虚拟机 Domain domain = conn.domainLookupByName("testvm"); // 启动虚拟机 domain.create(); // 关闭虚拟机 domain.shutdown(); // 断开与libvirt服务的连接 conn.close(); } } ``` 以上代码使用Java封装库提供的API连接到本地的libvirt服务,获取名为“testvm”的虚拟机,并启动和关闭该虚拟机。需要注意的是,以上代码仅作为示例,实际使用时需要根据实际情况进行调整和修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值