2014-11-24 115 views
0

我已经安装了php-libvirt以及所有必需的软件包(我试过remi rpm和编译)。libvirt-php收到错误:无法连接到服务器权限被拒绝

我安装我的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:///system list 

Please enter your authentication name: fred 
Please enter your password: 

Id Name       State 
---------------------------------------------------- 

我已经尝试从另一台服务器的命令行,以确保它可以远程工作,这很好。

我试过fred @ hostname,但没有奏效。我尝试了VIR_CRED_USERNAME,但也没有奏效。

可能是什么问题?

回答

0

缺省情况下,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

相关问题