[GH-ISSUE #240] Error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied #159

Closed
opened 2026-02-27 15:57:34 +03:00 by kerem · 16 comments
Owner

Originally created by @TurboCheetah on GitHub (Jun 10, 2019).
Original GitHub issue: https://github.com/retspen/webvirtcloud/issues/240

I have just installed it and have not changed anything. I added a compute node and then got this error. I added myself to the libvirt group and virt-manager works just fine. Only Webvirtcloud has this issue. Help?

Originally created by @TurboCheetah on GitHub (Jun 10, 2019). Original GitHub issue: https://github.com/retspen/webvirtcloud/issues/240 I have just installed it and have not changed anything. I added a compute node and then got this error. I added myself to the libvirt group and virt-manager works just fine. Only Webvirtcloud has this issue. Help?
kerem closed this issue 2026-02-27 15:57:34 +03:00
Author
Owner

@catborise commented on GitHub (Jun 10, 2019):

where did you install webvirtcloud?
on kvm host or a vm instance?
which protocol did you use while adding host(ssh, tcp, ...)

image

<!-- gh-comment-id:500392934 --> @catborise commented on GitHub (Jun 10, 2019): where did you install webvirtcloud? on kvm host or a vm instance? which protocol did you use while adding host(ssh, tcp, ...) ![image](https://user-images.githubusercontent.com/1725643/59194322-54c18c00-8b91-11e9-91ec-1d16b8615dec.png)
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

After fresh install on ubuntu 18.04 I've got the same issue after adding compute machine by selecting local option. What should I do? Compute status says: Connected. But I cannot create Instance on it.

<!-- gh-comment-id:550418546 --> @shinebayar-g commented on GitHub (Nov 6, 2019): After fresh install on ubuntu 18.04 I've got the same issue after adding compute machine by selecting **local** option. What should I do? Compute status says: Connected. But I cannot create Instance on it.
Author
Owner

@catborise commented on GitHub (Nov 6, 2019):

Have you run that script on the host?
wget -O - https://clck.ru/9V9fH | sudo sh
Before you run that script you can look what is it. What configs have it.

What is the error while creating instance?

<!-- gh-comment-id:550421730 --> @catborise commented on GitHub (Nov 6, 2019): Have you run that script on the host? wget -O - https://clck.ru/9V9fH | sudo sh Before you run that script you can look what is it. What configs have it. What is the error while creating instance?
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

Yes I've run the script. But I guess I mixed up users. I initially started process as sudo user and then run that script as root user. I guess this fucked up my installation. Recreating fresh VPS again.

<!-- gh-comment-id:550422434 --> @shinebayar-g commented on GitHub (Nov 6, 2019): Yes I've run the script. But I guess I mixed up users. I initially started process as sudo user and then run that script as root user. I guess this fucked up my installation. Recreating fresh VPS again.
Author
Owner

@catborise commented on GitHub (Nov 6, 2019):

I recommend you that isolate webvirtcloud from hypervisor host.
How;

  1. If you want to manage more than one host, you can create a vm and install webvirtcloud on it.
  2. If you do not want to reserve a vm for webvirtcloud. You could use containers. Docker installation is simple as dead.
    So that your users and other Configurations do not mixed up.
<!-- gh-comment-id:550425655 --> @catborise commented on GitHub (Nov 6, 2019): I recommend you that isolate webvirtcloud from hypervisor host. How; 1. If you want to manage more than one host, you can create a vm and install webvirtcloud on it. 2. If you do not want to reserve a vm for webvirtcloud. You could use containers. Docker installation is simple as dead. So that your users and other Configurations do not mixed up.
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

I see thank you very much for your suggestion. Right now this is my first try of webvirtcloud. So I'm just testing things out. Once I get familiar with the project concepts I'll create dedicated host for webvirtcloud :)

Also I'll try to enhance docs here and there If I see something broken.

<!-- gh-comment-id:550426561 --> @shinebayar-g commented on GitHub (Nov 6, 2019): I see thank you very much for your suggestion. Right now this is my first try of webvirtcloud. So I'm just testing things out. Once I get familiar with the project concepts I'll create dedicated host for webvirtcloud :) Also I'll try to enhance docs here and there If I see something broken.
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

Okay, just finished installing. I'm still seeing this error. Here is my whole installation steps.

sudo apt-get update
sudo apt-get -y install git virtualenv python-virtualenv python-dev python-lxml libvirt-dev zlib1g-dev libxslt1-dev nginx supervisor libsasl2-modules gcc pkg-config python-guestfs
git clone https://github.com/retspen/webvirtcloud
cd webvirtcloud
cp webvirtcloud/settings.py.template webvirtcloud/settings.py
python # Generating secret key in python shell
vim webvirtcloud/settings.py # putting the key here
sudo cp conf/supervisor/webvirtcloud.conf /etc/supervisor/conf.d
sudo cp conf/nginx/webvirtcloud.conf /etc/nginx/conf.d
cd ..
sudo mv webvirtcloud /srv
sudo chown -R www-data:www-data /srv/webvirtcloud
cd /srv/webvirtcloud
virtualenv venv # This line gave error, because folder was owned by www-data:www-data now
sudo chown -R me:me venv # So I had to change back permission to my current user
pip install -r conf/requirements.txt
python manage.py migrate
sudo chown -R www-data:www-data /srv/webvirtcloud # fixing permissions back after installing things
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
sudo service supervisor restart
wget -O - https://clck.ru/9V9fH | sudo sh

Now I'm here.

image

image

I guess I followed everything correctly, are you seeing anything abnormal here?

<!-- gh-comment-id:550429311 --> @shinebayar-g commented on GitHub (Nov 6, 2019): Okay, just finished installing. I'm still seeing this error. Here is my whole installation steps. ```sh sudo apt-get update sudo apt-get -y install git virtualenv python-virtualenv python-dev python-lxml libvirt-dev zlib1g-dev libxslt1-dev nginx supervisor libsasl2-modules gcc pkg-config python-guestfs git clone https://github.com/retspen/webvirtcloud cd webvirtcloud cp webvirtcloud/settings.py.template webvirtcloud/settings.py python # Generating secret key in python shell vim webvirtcloud/settings.py # putting the key here sudo cp conf/supervisor/webvirtcloud.conf /etc/supervisor/conf.d sudo cp conf/nginx/webvirtcloud.conf /etc/nginx/conf.d cd .. sudo mv webvirtcloud /srv sudo chown -R www-data:www-data /srv/webvirtcloud cd /srv/webvirtcloud virtualenv venv # This line gave error, because folder was owned by www-data:www-data now sudo chown -R me:me venv # So I had to change back permission to my current user pip install -r conf/requirements.txt python manage.py migrate sudo chown -R www-data:www-data /srv/webvirtcloud # fixing permissions back after installing things sudo rm /etc/nginx/sites-enabled/default sudo service nginx restart sudo service supervisor restart wget -O - https://clck.ru/9V9fH | sudo sh ``` Now I'm here. ![image](https://user-images.githubusercontent.com/3091558/68324215-e19d5100-0101-11ea-8143-99533ffbb362.png) ![image](https://user-images.githubusercontent.com/3091558/68324181-d2b69e80-0101-11ea-875c-ab603541818f.png) I guess I followed everything correctly, are you seeing anything abnormal here?
Author
Owner

@catborise commented on GitHub (Nov 6, 2019):

Hmm, i never try local connection. I should ...
Have you install virt-manager? Can you run it to check if libvirt service is working. This problem seems to libvirt service problem.

<!-- gh-comment-id:550431358 --> @catborise commented on GitHub (Nov 6, 2019): Hmm, i never try local connection. I should ... Have you install virt-manager? Can you run it to check if libvirt service is working. This problem seems to libvirt service problem.
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

I didn't install virt-manager. I guess it wasn't needed.

$ sudo service libvirt status
Unit libvirt.service could not be found.

Edit: Ah it is called libvirtd

$ sudo service libvirtd status
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-11-06 17:54:25 UTC; 12min ago
     Docs: man:libvirtd(8)
           https://libvirt.org
 Main PID: 20575 (libvirtd)
    Tasks: 19 (limit: 32768)
   CGroup: /system.slice/libvirtd.service
           ├─20575 /usr/sbin/libvirtd
           ├─20937 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
           └─20938 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper

Nov 06 17:54:27 instance-2 dnsmasq[20937]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify
Nov 06 17:54:27 instance-2 dnsmasq-dhcp[20937]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
Nov 06 17:54:27 instance-2 dnsmasq-dhcp[20937]: DHCP, sockets bound exclusively to interface virbr0
<!-- gh-comment-id:550431773 --> @shinebayar-g commented on GitHub (Nov 6, 2019): I didn't install virt-manager. I guess it wasn't needed. ``` $ sudo service libvirt status Unit libvirt.service could not be found. ``` Edit: Ah it is called libvirtd ```sh $ sudo service libvirtd status ● libvirtd.service - Virtualization daemon Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-11-06 17:54:25 UTC; 12min ago Docs: man:libvirtd(8) https://libvirt.org Main PID: 20575 (libvirtd) Tasks: 19 (limit: 32768) CGroup: /system.slice/libvirtd.service ├─20575 /usr/sbin/libvirtd ├─20937 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper └─20938 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper Nov 06 17:54:27 instance-2 dnsmasq[20937]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify Nov 06 17:54:27 instance-2 dnsmasq-dhcp[20937]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h Nov 06 17:54:27 instance-2 dnsmasq-dhcp[20937]: DHCP, sockets bound exclusively to interface virbr0 ```
Author
Owner

@catborise commented on GitHub (Nov 6, 2019):

Virt-manager does not need. But to check somethings, it is useful.
Please run on the host:
virsh list

<!-- gh-comment-id:550432859 --> @catborise commented on GitHub (Nov 6, 2019): Virt-manager does not need. But to check somethings, it is useful. Please run on the host: virsh list
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

Ran command as my current user

$ virsh list
error: failed to connect to the hypervisor
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied

$ sudo virsh list
 Id    Name                           State
----------------------------------------------------
<!-- gh-comment-id:550433103 --> @shinebayar-g commented on GitHub (Nov 6, 2019): Ran command as my current user ```sh $ virsh list error: failed to connect to the hypervisor error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied $ sudo virsh list Id Name State ---------------------------------------------------- ```
Author
Owner

@catborise commented on GitHub (Nov 6, 2019):

As you see it is related with users and permissions.
This link mention that permission problem, could you look:
http://thelinuxerrors.blogspot.com/2012/10/failed-to-connect-socket-to.html

<!-- gh-comment-id:550434382 --> @catborise commented on GitHub (Nov 6, 2019): As you see it is related with users and permissions. This link mention that permission problem, could you look: http://thelinuxerrors.blogspot.com/2012/10/failed-to-connect-socket-to.html
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

It is indeed. Okay I've fixed it. I've added myself to libvirt group. Now virsh list command works fine for my user. But on the web I'm still seeing the error?
I've tried to restart all supervisor processes, rebooted server no help. What should I do now? Should I add www-data user into libvirt group too? @catborise

Edit: adding www-data user to libvirt group helped? After reboot now I got rid of error.

<!-- gh-comment-id:550434860 --> @shinebayar-g commented on GitHub (Nov 6, 2019): It is indeed. Okay I've fixed it. I've added myself to `libvirt` group. Now `virsh list` command works fine for my user. But on the web I'm still seeing the error? I've tried to restart all supervisor processes, rebooted server no help. What should I do now? Should I add `www-data` user into `libvirt` group too? @catborise Edit: adding `www-data` user to `libvirt` group helped? After reboot now I got rid of error.
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

Now I'm seeing this error. How can I add storage?

image

<!-- gh-comment-id:550440022 --> @shinebayar-g commented on GitHub (Nov 6, 2019): Now I'm seeing this error. How can I add storage? ![image](https://user-images.githubusercontent.com/3091558/68326330-2d51f980-0106-11ea-823e-f5792123a6a3.png)
Author
Owner

@catborise commented on GitHub (Nov 6, 2019):

Libvirt-sock problem Seems to solved.
Latest one is not related with that problem.
—-
You should create a storage pool on the host.
Go to computes.
Storages, create a pool which will contain disk images.

<!-- gh-comment-id:550441045 --> @catborise commented on GitHub (Nov 6, 2019): Libvirt-sock problem Seems to solved. Latest one is not related with that problem. —- You should create a storage pool on the host. Go to computes. Storages, create a pool which will contain disk images.
Author
Owner

@shinebayar-g commented on GitHub (Nov 6, 2019):

Just double checked it by removing www-data user from libvirt group again. Error was caused by this indeed. I'll make PR changes to document these things.

Oh thank you! I didn't know I actually had to click on the compute name. Now I'm seeing whole lot of menus out there! Thank you very much.

/close

<!-- gh-comment-id:550442119 --> @shinebayar-g commented on GitHub (Nov 6, 2019): Just double checked it by removing `www-data` user from `libvirt` group again. Error was caused by this indeed. I'll make PR changes to document these things. Oh thank you! I didn't know I actually had to click on the compute name. Now I'm seeing whole lot of menus out there! Thank you very much. /close
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/webvirtcloud#159
No description provided.