Virt-manager的问题

我安装了virt-manager,但无法使其工作。
我尝试了之前发布的一些答案,但都没有成功。我已经确认了以下几点:
- 已安装libvirt-bin软件包 - 已启动libvirtd守护进程 - 我是libvirtd组的成员 - libvirt URI为:qemu:///system
当我尝试运行virt-manager时,出现了以下错误:
Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/connection.py", line 1027, in _open_thread
    self.vmm = self._try_open()
  File "/usr/share/virt-manager/virtManager/connection.py", line 1009, in _try_open
    flags)
  File "/usr/lib/python2.7/dist-packages/libvirt.py", line 102, in openAuth
    if ret is None:raise libvirtError('virConnectOpenAuth() failed')
libvirtError: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission     denied

请编辑您的问题,包括ls -la /var/run/libvirt/的输出。 - Eric Carvalho
5个回答

你可能需要退出并重新登录。
假设 `/etc/libvirt/libvirtd.conf` 中有:
# Set the UNIX domain socket group ownership. This can be used to
# allow a 'trusted' set of users access to management capabilities
# without becoming root.
#
# This is restricted to 'root' by default.
unix_sock_group = "libvirtd"

# Set the UNIX socket permissions for the R/O socket. This is used
# for monitoring VM status only
#
# Default allows any user. If setting group ownership, you may want to
# restrict this too.
unix_sock_ro_perms = "0777"

# Set the UNIX socket permissions for the R/W socket. This is used
# for full management of VMs
#
# Default allows only root. If PolicyKit is enabled on the socket,
# the default will change to allow everyone (eg, 0777)
#
# If not using PolicyKit and setting group ownership for access
# control, then you may want to relax this too.
unix_sock_rw_perms = "0770"

如果您的用户是libvirtd组的成员,它应该可以工作。
检查一下您的用户是否应该加入该组,例如用户vagrant
$ cat /etc/group|grep $USER
vagrant:x:1000:
libvirtd:x:116:ubuntu,vagrant

如果您的用户不在该组中,您需要将其添加:
$ sudo usermod -a -G libvirtd $USER

如果您的用户已经在/etc/group中的组中,那么请检查groups的输出结果。
$ groups
vagrant libvirtd

如果你看不到 libvirtd,你需要退出并重新登录。

2这个方法很有效!(在注销/登录后)。在我的情况下,我使用了libvirt而不是libvirtd(我遵循了这篇文章)。 - dance2die
5对我来说,我必须重新启动才能使其正常工作。 - Alex Punnen
1在我的情况下,也是libvirt而不是libvirtd。 - Melroy van den Berg
2您也可以尝试使用su $USER而不是重新登录:) 这在我这边起作用了 - Hybris95

我遇到了同样的问题。试试这个指南,对我有用。别忘了在将用户添加到'libvirtd'组后重新登录。

欢迎来到Ask Ubuntu!虽然这理论上可以回答问题,但最好在这里包含答案的关键部分,并提供链接作为参考。 - Eric Carvalho

我遇到了这个问题,因为我有两个libvirtd组。

当我安装qemu-kvm时,libvirtd组不存在,所以它被创建为任意的组ID 121:

ls -n /var/run/libvirt/libvirt-sock
srwxrwx--- 1 0 121 0 Oct  1 18:49 /var/run/libvirt/libvirt-sock

后来,我的主机加入了NIS。我是libvirtd的成员,但组ID是1046。
id
uid=177(jmcgeheeiv) ...,1046(libvirtd),...

我不是201组的成员,所以无法写入到套接字/var/run/libvirt/libvirt-sock
/var/run/libvirt/libvirt-sock的组所有权更新为正确的组编号解决了我的问题。
sudo chgrp 1019 /var/run/libvirt/libvirt-sock
ls -n /var/run/libvirt/libvirt-sock
srwxrwx--- 1 0 1019 0 Oct  1 18:49 /var/run/libvirt/libvirt-sock

在这种情况下,没有必要注销和登录。
虽然上述方法解决了即时的问题,但它违反了基础设施即代码的原则。真正的解决方案是重新构建主机,首先创建与NIS一致的组ID为1046的组libvirtd,然后安装qemu-kvm。

试着将这行添加到/etc/libvirt/libvirtd.conf中。
listen_tls = 0

然后通过以下方式重新启动lirvirt
/etc/init.d/libvirt-bin restart

在我的情况下,解决方案是在KVM主机上安装sudo apt install qemu-system而不是sudo apt install --no-install-recommends qemu-system。我不需要修改默认的/etc/libvirt/libvirtd.conf文件。另请参阅Debian KVM Wiki