dongzhuo7291 2014-11-24 14:45 采纳率: 100%
浏览 146

libvirt-php收到错误:无法连接到服务器权限被拒绝

I have installed php-libvirt as well as all required packages (I tried the remi rpm and compiling).

I have setup my php file as follows:

<?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>");
?>

However when I load the page I get:

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

It works fine from the command line when I run

# virsh -c qemu+tcp:///system list

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

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

I have tried the command line from another server to make sure it would work remotely and it was fine.

I have tried fred@hostname and that didn't work. I have tried VIR_CRED_USERNAME and that also didn't work.

What could be the issue?

  • 写回答

1条回答 默认 最新

  • douzhi7661 2015-05-07 19:33
    关注

    By default authentication mechanism for libvirtd TCP connection is SASL. Till now TCP connection is listening and now we have to configure SASL based authentication. Edit /etc/libvirt/libvirtd.conf, they are using auth_tcp = "none", but use auth_tcp = "sasl" if not done already. Now execute the following command.

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

    In your case libvirtd is listening for a TCP connection, but some time we need to make some changes to make it listen on the given port. First link in the references will be useful for that.

    References:

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?