第1章 系统环境说明
1.1 部署环境说明
1.1.1 CentOS准备环境
[[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [[email protected] ~]# uname -r 3.10.0-693.el7.x86_64
1.1.2 Deepin准备环境
[email protected]:~# 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 参考文档
第2章 CentOS7.x部署WebVirtMgr
2.1 安装依赖程序
[[email protected] ~]# yum install -y git python-pip libvirt-python libxml2-python python-websockify supervisor gcc python-devel [[email protected] ~]# yum localinstall -y /server/tools/nginx-1.12.1-1.x86_64.rpm [[email protected] ~]# pip install numpy -i https://pypi.douban.com/simple/ # 此处可以指定自己的pip源
2.2 部署WebVirtMgr
[[email protected] ~]# cd /usr/local/nginx/html/ [[email protected] html]# git clone git://github.com/retspen/webvirtmgr.git [[email protected] html]# cd webvirtmgr [[email protected] webvirtmgr]# pip install -r requirements.txt -i https://pypi.douban.com/simple/
2.3 配置WebVirtMgr
[[email protected] 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) [[email protected] webvirtmgr]# ./manage.py collectstatic Type 'yes' to continue, or 'no' to cancel: yes # 此处为新建额外的管理员用户,视实际情况创建即可 [[email protected] 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
[[email protected] ~]# mkdir -p /usr/local/nginx/conf/extras [[email protected] ~]# cd /usr/local/nginx/conf/extras/ [[email protected] 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 } } [[email protected] 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; } [[email protected] extras]# chown -R nginx.nginx /usr/local/nginx/html/webvirtmgr/ [[email protected] extras]# nginx
2.5 配置supervisord
[[email protected] ~]# 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 [[email protected] ~]# systemctl start supervisord.service [[email protected] ~]# systemctl enable supervisord.service
2.6 配置ssh互认
[[email protected] ~]# mkdir -p /home/nginx [[email protected] ~]# chown -R nginx.nginx /home/nginx/ [[email protected] ~]# chmod -R 700 /home/nginx/ [[email protected] ~]# 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 [[email protected] ~]# nginx -s reload
2.7 KVM宿主机配置认证(非必需)
[[email protected] ~]# 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 [[email protected] ~]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla [[email protected] ~]# systemctl restart libvirtd
第3章 deepin部署WebVirtMgr
3.1 安装依赖程序
[email protected]:~# apt-get install git python-pip python-libvirt python-libxml2 novnc supervisor nginx
3.2 部署WebVirtMgr
[email protected]:~# cd /var/www/ [email protected]: /var/www# git clone git://github.com/retspen/webvirtmgr.git [email protected]: /var/www# cd webvirtmgr [email protected]: /var/www/webvirtmgr# pip install -r requirements.txt -i https://pypi.douban.com/simple/
3.3 配置WebVirtMgr
[email protected]: /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) [email protected]: /var/www/webvirtmgr# ./manage.py collectstatic Type 'yes' to continue, or 'no' to cancel: yes # 此处为新建额外的管理员用户,视实际情况创建即可 [email protected]: /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
[email protected]:~# 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 } } [email protected]:~# vim /etc/nginx/sites-enabled/default # 注释掉此文件所有内容 [email protected]:~# chown -R www-data:www-data /var/www [email protected]:~# systemctl restart nginx
3.5 配置novnc和supervisor
[email protected]:~# service novnc stop Failed to stop novnc.service: Unit novnc.service not loaded. # 忽略此处错误 roo[email protected]:~# insserv -r novnc insserv: novnc: No such file or directory # 忽略此处错误 [email protected]:~# 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 [email protected]:~# 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 [email protected]:~# service supervisor start [email protected]:~# systemctl enable supervisor
3.6 配置ssh互认
[email protected]:~# su - www-data -s /bin/bash [email protected]:~$ ssh-keygen [email protected]:~$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config [email protected]:~$ chmod 0600 ~/.ssh/config [email protected]:~$ ssh-copy-id [email protected] # 此处为KVM宿主机的用户名及IP地址 [email protected]:~$ exit
3.7 KVM宿主机配置认证(非必)
[[email protected] ~]# 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 [[email protected] ~]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla [[email protected] ~]# systemctl restart libvirtd

我的微信
如果有技术上的问题可以扫一扫我的微信