【问题标题】:libvirt-php receives the error: unable to connect to server Permission deniedlibvirt-php 收到错误:无法连接到服务器权限被拒绝
【发布时间】:2014-11-24 14:45:16
【问题描述】:

我已经安装了 php-libvirt 以及所有必需的软件包(我尝试了 remi rpm 和编译)。

我的 php 文件设置如下:

<?php
print_r ( libvirt_version() );
echo '<br>';
$uri="qemu+tcp:///system";
$credentials=array(VIR_CRED_AUTHNAME=>"fred",VIR_CRED_PASSPHRASE=>"fred");
echo ("Connecting to libvirt (URI:$uri)<BR>");
$conn=libvirt_connect($uri,false,$credentials);
if ($conn==false)
{
    echo ("Libvirt last error: ".libvirt_get_last_error()."<br>");
    exit;
} else {
    $hostname=libvirt_get_hostname($conn);
    echo ("hostname:$hostname<br>");
?>

但是当我加载页面时:

Array ( [libvirt.release] => 2 [libvirt.minor] => 10 [libvirt.major] => 0 [connector.version] => 0.4.8 [connector.major] => 0 [connector.minor] => 4 [connector.release] => 8 ) 
Connecting to libvirt (URI:qemu+tcp:///system)
Libvirt last error: unable to connect to server at 'localhost:16509': Permission denied

当我运行时,它可以从命令行正常运行

# virsh -c qemu+tcp:///系统列表 请输入您的认证名称:fred 请输入您的密码: Id 名称 状态 -------------------------------------------------- --

我已经从另一台服务器尝试了命令行,以确保它可以远程工作并且没问题。

我尝试了 fred@hostname,但没有成功。我试过 VIR_CRED_USERNAME 也没有用。

可能是什么问题?

【问题讨论】:

    标签: php centos qemu kvm libvirt


    【解决方案1】:

    libvirtd TCP 连接的默认认证机制是 SASL。到目前为止,TCP 连接正在侦听,现在我们必须配置基于 SASL 的身份验证。编辑 /etc/libvirt/libvirtd.conf,他们正在使用 auth_tcp = "none",但如果尚未完成,请使用 auth_tcp = "sasl"。现在执行以下命令。

    sudo saslpasswd2 -a libvirt fred
    Password: fred
    Again (for verification): fred
    

    在您的情况下,libvirtd 正在侦听 TCP 连接,但有时我们需要进行一些更改以使其侦听给定端口。参考文献中的第一个链接对此很有用。

    参考资料:

    https://askubuntu.com/questions/423425/i-cant-use-libvirt-with-listen-tcp

    http://libvirt.org/auth.html#ACL_server_username

    https://www-01.ibm.com/support/knowledgecenter/linuxonibm/liabp/liabpkvmsecsrmsasl.htm

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-29
      • 2018-08-07
      • 2017-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      相关资源
      最近更新 更多