1.1、安装依赖包
[root@bogon ]# yum install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx -y
1.2、从git-hub中下载相关的webvirtmgr代码
[root@bogon ]# cd /usr/local/src/
[root@bogon ]# git clone git://github.com/retspen/webvirtmgr.git
1.3、安装webvirtmgr
[root@bogon ]# cd webvirtmgr/
[root@bogon webvirtmgr]# pip install -r requirements.txt
如果pip没有安装 ,先安装一下
首先安装epel扩展源:
yum -y install epel-release
更新完成之后,就可安装pip:
yum -y install python-pip
1.4、检查sqlite3 (备注:自带不需要安装,导入模块检查一下。)
[root@bogon webvirtmgr]# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
import sqlite3
exit()
1.5、初始化账号
[root@bogon webvirtmgr]# pwd
/usr/local/src/webvirtmgr
[root@bogon webvirtmgr]# ./manage.py syncdb
WARNING:root:No local_settings file found.
Creating tables …
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table servers_compute
Creating table instance_instance
Creating table create_flavor
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
Email address: 12345678@qq.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL …
Installing indexes …
Installed 6 object(s) from 1 fixture(s)
1.6、拷贝web到 相关目录
[root@bogon webvirtmgr]# mkdir -pv /var/www
[root@bogon webvirtmgr]# cp -Rv /usr/local/src/webvirtmgr /var/www/webvirtmgr
1.7、设置ssh
[root@bogon webvirtmgr]# ssh-keygen -t rsa //产生公私钥
[root@bogon webvirtmgr]# ssh-copy-id 192.168.168.139 //由于这里webvirtmgr和kvm服务部署在同一台机器,所以这里本地信任。如果kvm部署在其他机器,那么这个是它的ip
[root@bogon webvirtmgr]# ssh 192.168.168.139 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60
1.8、编辑nginx配置文件(如果没有nignx,先安装,)
#添加这行代码: include /etc/nginx/conf.d/*.conf;
[root@bogon etc]# cd /etc/nginx/
[root@bogon nginx]# mv nginx.conf /tmp
[root@bogon nginx]# cp nginx.conf.default nginx.conf
#编辑配置文件
[root@bogon nginx]# cd /etc/nginx/
[root@bogon nginx]# vi nginx.conf
[root@bogon nginx]# cat nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
#log_format main '$remote_addr -
r
e
m
o
t
e
u
s
e
r
[
remote_user [
remoteuser[time_local] “KaTeX parse error: Expected 'EOF', got '#' at position 16: request" ' #̲ …status
b
o
d
y
b
y
t
e
s
s
e
n
t
"
body_bytes_sent "
bodybytessent"http_referer” ’
# ‘“
h
t
t
p
u
s
e
r
a
g
e
n
t
"
"
http_user_agent" "
httpuseragent""http_x_forwarded_for”’;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
#添加 /etc/nginx/conf.d/webvirtmgr.conf 配置文件
[root@bogon nginx]# vi /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
h
o
s
t
:
host:
host:server_port;
proxy_set_header X-Forwarded-Proto $remote_addr;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M; # Set higher depending on your needs
}
}
#重启nginx服务
systemctl restart nginx
1.9、修改防火墙规则
#修改防火墙规则
[root@ops ~]# vim /etc/sysconfig/selinux
…
SELINUX=disabled
#临时生效
[root@ops ~]# setenforce 0
setenforce: SELinux is disabled
#查看状态
[root@ops ~]# getenforce
Disabled
#直接执行这行
/usr/sbin/setsebool httpd_can_network_connect true
2.0、授权
[root@bogon nginx]# chown -R nginx:nginx /var/www/webvirtmgr
2.1、设置 supervisor (如果iptables防火墙开启的话,就必须要开通80、8000、6080端口访问)
[root@bogon nginx]# vi /etc/supervisord.conf
[program:webvirtmgr]
command=/usr/bin/python2 /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py //启动8000端口
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
logfile=/var/log/supervisor/webvirtmgr.log
log_stderr=true
user=nginx
[program:webvirtmgr-console]
command=/usr/bin/python2 /var/www/webvirtmgr/console/webvirtmgr-console //启动6080端口(这是控制台vnc端口)
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=nginx
#检查
[root@bogon nginx]# cat /var/www/webvirtmgr/conf/gunicorn.conf.py //确保下面bind绑定的是本机的8000端口,这个在nginx配置中定义了,被代理的端口
bind = ‘127.0.0.1:8000’
#设置开机启动
#如果提示supervisor未安装重新安装,[root@bogon ~]# yum -y install supervisor
[root@bogon ~]# systemctl enable supervisord.service
#设置开机加载