系統版本:CentOS 7.4
WebVirtMgr版本:master分支的20180720版本,下載鏈接(鏈接:https://pan.baidu.com/s/1kl060hPHDGbwJUR_iMFb3Q 密碼:iozj)
用到的目錄:/data/service/nginx,/data/service/nginx_vhost/,/data/service/webvirtmgr
安裝成功並成功運行的標志位:/var/log/supervisor/supervisord.log,/var/log/supervisor/webvirtmgr-console.log這兩個日志文件會自動生成。
說明:其實網上流傳了很多安裝的版本,基本都非常亂,要不是這里加一句沒用的,就是那里根本不用這么復雜的配置,記住,一切的安裝配置以官方文檔為准,並且官方這么少的配置都能成功時,自己更應該注意有沒有配置錯誤等問題。
注意:整篇文章未改動過官方的過多配置,如果你運行不起來,那么90%都出在權限以及權限組上!下面安裝的步驟都是使用root賬號。
一、准備工作
0、准備操作:
##關閉selinux # sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config #修改配置文件則永久生效,但是必須要重啟系統。 ##生效命令 # setenforce 0
1、設置目錄並安裝nginx
git clone http://github.com/easonjim/centos-shell.git cd centos-shell/directory sh init-directory.sh cd ../../ cd centos-shell/nginx sh install-nginx_1.14.0.sh
cd ../../
2、安裝kvm(這一步不要求按照這個,只需要安裝成功即可)
cd centos-shell/kvm sh install-kvm_centos_7.sh
參考:https://www.cnblogs.com/EasonJim/p/9150733.html
3、安裝WebVirtMgr依賴
yum install epel-release
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo # 這一步的epel源是關鍵,如果安裝不成功,那么下面的依賴也會安裝不成功 yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx yum -y install gcc python-devel pip install numpy
4、正式安裝WebVirtMgr並配置超級登錄用戶
cd /data/service
git clone git://github.com/retspen/webvirtmgr.git cd webvirtmgr pip install -r requirements.txt ./manage.py syncdb ./manage.py collectstatic
說明:如果上面的版本不能安裝,那么建議下載離線版本,隨着時間的推移,不保證會不會改變。
配置超級用戶,信息類似如下:
You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now? (yes/no): yes (Put: yes) Username (Leave blank to use 'admin'): admin (Put: your username or login) E-mail address: username@domain.local (Put: your email) Password: xxxxxx (Put: your password) Password (again): xxxxxx (Put: confirm password) Superuser created successfully.
如果想再增加多一個超級用戶,可以再執行如下命令:
./manage.py createsuperuser
配置信息類似如上所示。
5、設置nginx
vi /data/service/nginx_vhost/webvirtmgr.conf
server { listen 8001; server_name $hostname; access_log /data/weblog/nginx/webvirtmgr_access_log; location /static/ { root /data/service/webvirtmgr/webvirtmgr; expires max; } location / { proxy_pass http://127.0.0.1:8000; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for; proxy_set_header Host $host:$server_port; proxy_set_header X-Forwarded-Proto $scheme; proxy_connect_timeout 600; proxy_read_timeout 600; proxy_send_timeout 600; client_max_body_size 1024M; } }
service nginx restart
6、配置supervisord服務
設置權限
chown -R nginx:nginx /data/service/webvirtmgr 
        其實是在supervisord服務增加webvirtmgr進程的啟動,依賴這個服務而已。
# 開機自啟
systemctl enable supervisord 
        增加進程啟動配置
vi /etc/supervisord.d/webvirtmgr.ini
[program:webvirtmgr] command=/usr/bin/python /data/service/webvirtmgr/manage.py run_gunicorn -c /data/service/webvirtmgr/conf/gunicorn.conf.py directory=/data/service/webvirtmgr autostart=true autorestart=true logfile=/var/log/supervisor/webvirtmgr.log log_stderr=true user=nginx [program:webvirtmgr-console] command=/usr/bin/python /data/service/webvirtmgr/console/webvirtmgr-console directory=/data/service/webvirtmgr autostart=true autorestart=true stdout_logfile=/var/log/supervisor/webvirtmgr-console.log redirect_stderr=true user=nginx
重啟服務
service supervisord restart
7、權限設置(重點),也是設置Local登錄的一種方式
增加權限組
groupadd libvirtd
增加用戶到權限組
usermod -a -G libvirtd root
usermod -a -G libvirtd nginx 
        設置kvm服務libvirtd啟動權限
vi /etc/libvirt/libvirtd.conf

增加權限啟動配置
vi /etc/polkit-1/localauthority/50-local.d/50-org.libvirtd-group-access.pkla
[libvirtd group Management Access] Identity=unix-group:libvirtd Action=org.libvirt.unix.manage ResultAny=yes ResultInactive=yes ResultActive=yes
最后重啟服務
service libvirtd restart
service supervisord start
上面的權限檢查:
①、確定是否已libvirtd組啟動licvirtd服務
ls -l /var/run/libvirt/libvirt-sock srwxrwx--- 1 root libvirtd 0 févr. 12 16:03 /var/run/libvirt/libvirt-sock
②、確定WebVirtMgr啟動的用戶
ps -ef | grep run_gunicorn | awk 'NR==1{ print $1 }'
nginx 
        ③、確定用戶已經加入到libvirtd組
groups root
libvirtd
groups nginx
libvirtd 
        8、配置到這里基本全部配置完成,可以直接使用Local添加運行
登錄http://x.x.x.x:8001


放心,如果按照以上配置絕對可以運行的起來,已經測試了100+台。
參考:
https://github.com/retspen/webvirtmgr/wiki/Install-WebVirtMgr(官方配置文檔)
