2014-11-24 119 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

相關問題