WebVirtMgr部署

第1章 系统环境说明

1.1 部署环境说明

1.1.1 CentOS准备环境

[root@function ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@function ~]# uname -r
3.10.0-693.el7.x86_64

1.1.2 Deepin准备环境

root@webvirtmgr-PC:~# cat /etc/os-release
PRETTY_NAME="Deepin 15"
NAME="Deepin"
VERSION_ID="15.7"
VERSION="15.7"
ID=deepin
HOME_URL="https://www.deepin.org/"
BUG_REPORT_URL="http://feedback.deepin.org/feedback/"

1.1.3 程序部署说明

此程序可与KVM部署在不同的服务器上,并且一个程序可以管理多个KVM宿主机,此次部署在KVM虚拟机中来管理KVM宿主机。

1.1.4 防火墙开放端口

  • 80:nginx反向代理设置的端口
  • 6080:noVNC服务端口,未开通的话会导致无法通过VNC远程连接虚拟机
  • 8000:webvirtmgr程序端口,也可不开通外网访问

1.2 参考文档

https://www.centos.bz/2018/07/centos7-2-kvm%E8%99%9A%E6%8B%9F%E5%8C%96%E7%AE%A1%E7%90%86%E5%B9%B3%E5%8F%B0webvirtmgr%E9%83%A8%E7%BD%B2/

https://www.cnblogs.com/kevingrace/p/5737724.html

https://www.cnblogs.com/kevingrace/p/5739009.html

第2章 CentOS7.x部署WebVirtMgr

2.1 安装依赖程序

[root@function ~]# yum install -y git python-pip libvirt-python libxml2-python python-websockify supervisor gcc python-devel
[root@function ~]# yum localinstall -y /server/tools/nginx-1.12.1-1.x86_64.rpm
[root@function ~]# pip install numpy -i https://pypi.douban.com/simple/  # 此处可以指定自己的pip源

2.2 部署WebVirtMgr

[root@function ~]# cd /usr/local/nginx/html/
[root@function html]# git clone git://github.com/retspen/webvirtmgr.git
[root@function html]# cd webvirtmgr
[root@function webvirtmgr]# pip install -r requirements.txt -i https://pypi.douban.com/simple/

2.3 配置WebVirtMgr

[root@function webvirtmgr]# ./manage.py syncdb
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
Username (leave blank to use 'root'): admin     # 此处用户名为登陆WebVirtMgr的管理员用户名
Email address: [email protected]
Password: 123456                                # 此处为上面设置的管理员用户密码
Password (again): 123456
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)

[root@function webvirtmgr]# ./manage.py collectstatic
Type 'yes' to continue, or 'no' to cancel: yes

# 此处为新建额外的管理员用户,视实际情况创建即可
[root@function webvirtmgr]# ./manage.py createsuperuser
Username (leave blank to use 'root'): root
Email address: [email protected]
Password: 123456
Password (again): 123456
Superuser created successfully.

2.4 配置nginx

[root@function ~]# mkdir -p /usr/local/nginx/conf/extras
[root@function ~]# cd /usr/local/nginx/conf/extras/
[root@function extras]# vim webvirtmgr.conf
server {
    listen 80 default_server;

    server_name $hostname;
    access_log logs/webvirtmgr_access_log;

    location /static/ {
        root html/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; # Set higher depending on your needs
    }
}

[root@function extras]# vim /usr/local/nginx/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    include extras/webvirtmgr.conf;
}

[root@function extras]# chown -R nginx.nginx /usr/local/nginx/html/webvirtmgr/
[root@function extras]# nginx

2.5 配置supervisord

[root@function ~]# vim /etc/supervisord.d/webvirtmgr.ini
[program:webvirtmgr]
command=/usr/bin/python /usr/local/nginx/html/webvirtmgr/manage.py run_gunicorn -c /usr/local/nginx/html/webvirtmgr/conf/gunicorn.conf.py
directory=/usr/local/nginx/html/webvirtmgr
autostart=true
autorestart=true
logfile=/var/log/supervisor/webvirtmgr.log
log_stderr=true
user=nginx

[program:webvirtmgr-console]
command=/usr/bin/python /usr/local/nginx/html/webvirtmgr/console/webvirtmgr-console
directory=/usr/local/nginx/html/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=nginx

[root@function ~]# systemctl start supervisord.service
[root@function ~]# systemctl enable supervisord.service

2.6 配置ssh互认

[root@function ~]# mkdir -p /home/nginx
[root@function ~]# chown -R nginx.nginx /home/nginx/
[root@function ~]# chmod -R 700 /home/nginx/
[root@function ~]# su - nginx -s /bin/bash
-bash-4.2$ ssh-keygen
-bash-4.2$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.2$ chmod 0600 ~/.ssh/config
-bash-4.2$ ssh-copy-id [email protected]       # 此处为KVM宿主机的用户名及IP地址
-bash-4.2$ exit
[root@function ~]# nginx -s reload

2.7 KVM宿主机配置认证(非必需)

[root@kvm ~]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:root
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes

[root@kvm ~]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[root@kvm ~]# systemctl restart libvirtd

第3章 deepin部署WebVirtMgr

3.1 安装依赖程序

root@webvirtmgr-PC:~# apt-get install git python-pip python-libvirt python-libxml2 novnc supervisor nginx

3.2 部署WebVirtMgr

root@webvirtmgr-PC:~# cd /var/www/
root@webvirtmgr-PC: /var/www# git clone git://github.com/retspen/webvirtmgr.git
root@webvirtmgr-PC: /var/www# cd webvirtmgr
root@webvirtmgr-PC: /var/www/webvirtmgr# pip install -r requirements.txt -i https://pypi.douban.com/simple/

3.3 配置WebVirtMgr

root@webvirtmgr-PC: /var/www/webvirtmgr# ./manage.py syncdb
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
Username (leave blank to use 'root'): admin     # 此处用户名为登陆WebVirtMgr的管理员用户名
Email address: [email protected]
Password: 123456                                # 此处为上面设置的管理员用户密码
Password (again): 123456
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)

root@webvirtmgr-PC: /var/www/webvirtmgr# ./manage.py collectstatic
Type 'yes' to continue, or 'no' to cancel: yes

# 此处为新建额外的管理员用户,视实际情况创建即可
root@webvirtmgr-PC: /var/www/webvirtmgr# ./manage.py createsuperuser
Username (leave blank to use 'root'): root
Email address: [email protected]
Password: 123456
Password (again): 123456
Superuser created successfully.

3.4 配置nginx

root@webvirtmgr-PC:~# vim /etc/nginx/conf.d/webvirtmgr.conf
server {
    listen 80 default_server;
    server_name $hostname;
    access_log /var/log/nginx/webvirtmgr_access_log;

    location /static/ {
        root /var/www/webvirtmgr/webvirtmgr; # or /srv instead of /var
        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; # Set higher depending on your needs
    }
}

root@webvirtmgr-PC:~# vim /etc/nginx/sites-enabled/default
# 注释掉此文件所有内容

root@webvirtmgr-PC:~# chown -R www-data:www-data /var/www
root@webvirtmgr-PC:~# systemctl restart nginx

3.5 配置novnc和supervisor

root@webvirtmgr-PC:~# service novnc stop
Failed to stop novnc.service: Unit novnc.service not loaded.    # 忽略此处错误
root@webvirtmgr-PC:~# insserv -r novnc
insserv: novnc: No such file or directory                       # 忽略此处错误

root@webvirtmgr-PC:~# 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

root@webvirtmgr-PC:~# 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

root@webvirtmgr-PC:~# service supervisor start
root@webvirtmgr-PC:~# systemctl enable supervisor

3.6 配置ssh互认

root@webvirtmgr-PC:~# su - www-data -s /bin/bash
www-data@tets-PC:~$ ssh-keygen
www-data@tets-PC:~$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
www-data@tets-PC:~$ chmod 0600 ~/.ssh/config
www-data@tets-PC:~$ ssh-copy-id [email protected]      # 此处为KVM宿主机的用户名及IP地址
www-data@tets-PC:~$ exit

3.7 KVM宿主机配置认证(非必)

[root@kvm ~]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:root
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes

[root@kvm ~]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[root@kvm ~]# systemctl restart libvirtd
温馨提示:本文最后更新于2022-12-20 20:57:45,已超过483天没有更新。某些文章具有时效性,若文章内容或图片资源有错误或已失效,请联系站长。谢谢!
转载请注明本文链接:https://blog.leonshadow.cn/763482/1296.html
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享