Webvirtmgr на Debian Jessie. Веб интерфейс для Linux KVM

Материал из support.qbpro.ru


aptitude update aptitude install git python-pip python-libvirt python-libxml2 novnc supervisor qemu-kvm libvirt-bin virtinst sasl2-bin apache2 libapache2-mod-wsgi bridge-utils

Настраиваем KVM

vim /etc/default/libvirtd:
libvirtd_opts="-d -l"
vim /etc/libvirt/libvirtd.conf:
listen_tls = 0
listen_tcp = 1
invoke-rc.d libvirtd restart

Делаем сетевой мост для KVM

vim /etc/network/interfaces:
auto br0
allow-hotplug br0
iface br0 inet static
       address 192.168.10.1
       gateway 192.168.10.1
       bridge_ports eth0
       bridge_stp off
       bridge_maxwait 0
invoke-rc.d networking stop && invoke-rc.d networking start

Настраиваем webvirtmgr

apt-get install git python-pip python-libvirt python-libxml2 novnc supervisor nginx
cd /var/www
git clone git://github.com/retspen/webvirtmgr.git
cd webvirtmgr
pip install -r requirements.txt
./manage.py syncdb
./manage.py collectstatic
vim conf/gunicorn.conf.py:

bind = '0.0.0.0:8000'
chown -R www-data:www-data /var/www/webvirtmgr

Добавляем пользователя, который получит доступ к веб интерфейсу

/var/www/webvirtmgr/manage.py createsuperuser

Потом для того же пользователя

saslpasswd2 -a libvirt user

Статус пользователей

sasldblistusers2 -f /etc/libvirt/passwd.db
vim /etc/supervisor/conf.d/webvirtmgr.conf:
[program:webvirtmgr]
command=/usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr.log
redirect_stderr=true
user=www-data 

[program:webvirtmgr-console]
command=/usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-console
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=www-data 
invoke-rc.d supervisor restart
invoke-rc.d supervisor restart
invoke-rc.d novnc stop
insserv -r novnc
vim /etc/insserv/overrides/novnc:
#!/bin/sh
### BEGIN INIT INFO
# Provides:          nova-novncproxy
# Required-Start:    $network $local_fs $remote_fs $syslog
# Required-Stop:     $remote_fs
# Default-Start:     
# Default-Stop:      
# Short-Description: Nova NoVNC proxy
# Description:       Nova NoVNC proxy
### END INIT INFO 

Делаем виртуальный хост для webvirtmgr

vim /etc/apache2/sites-available/webvirtmgr.conf:
WSGISocketPrefix /var/run/apache2/wsgi
<VirtualHost *:8000>
    ServerAdmin admin@example.com
    ServerName example.com 

   WSGIDaemonProcess webvirtmgr display-name=%{GROUP} python-path=/var/www/webvirtmgr
   WSGIProcessGroup webvirtmgr
   WSGIScriptAlias / /var/www/webvirtmgr/webvirtmgr/wsgi.py

   Alias /static /var/www/webvirtmgr/webvirtmgr/static/
   Alias /media /var/www/webvirtmgr/webvirtmgr/media/

   <Directory /var/www/webvirtmgr/webvirtmgr>
       <Files wsgi.py>
       Require all granted
       </Files>
   </Directory>

   CustomLog ${APACHE_LOG_DIR}/webvirtmgr-access.log common
   ErrorLog ${APACHE_LOG_DIR}/webvirtmgr-error.log
</VirtualHost>
a2ensite webvirtmgr
invoke-rc.d apache2 reload

Устанавливаем службу фаерволла (https://github.com/antoncohen/iptables-persistent/blob/master/debian/iptables-persistent.init)

wget http://tehnikpc.net/ftp/repo/debian/iptables -P /etc/init.d/
chmod +x /etc/init.d/iptables
insserv -d iptables

Открываем порты

iptables -I INPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -I INPUT 2 -s 192.168.10.0/24 -d 192.168.10.1 -i eth0 -p tcp -m state --state NEW -m multiport --dports 80,6080,8000,16509 -j ACCEPT
invoke-rc.d iptables save

Веб интерфейс будет доступен по адресу http://example.com:8000