1.拉取容器
docker run -itd --privileged -p 8090:80 -p 6080:6080 -p 8000:8000 --name webvirtmgr-kvm /usr/sbin/init
2.进入容器
docker exec -it webvirtmgr /bin/bash
3.安装相关依赖
yum -y install epel-release
yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx gcc python-devel
pip install numpy==1.16 #1.17及以上版本不支持python2,高版本的可以用自行安装python3以及更高的numpy
4.获取源码
git clone git://github.com/retspen/webvirtmgr.git
cd webvirtmgr
pip install -r requirements.txt # 使用清华大学镜像站 -i https://pypi.tuna.tsinghua.edu.cn/simple
5.安装配置
./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 (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 collectstatic
#WARNING:root:No local_settings file found.
#You have requested to collect static files at the destination
#location as specified in your settings.
#This will overwrite existing files!
#Are you sure you want to do this?
#Type 'yes' to continue, or 'no' to cancel: yes
6.配置nginx
mkdir -pv /var/www
cp -raf webvirtmgr /var/www/ #将webvirtmgr源码拷贝到/var/www/
chown -R nginx:nginx /var/www/webvirtmgr
vim /etc/nginx/nginx.conf
#注释以下内容
# server {
# listen 80 default_server;
# server_name localhost;
# root /usr/share/nginx/html;
#
# #charset koi8-r;
#
# #access_log /var/log/nginx/host.access.log main;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# # redirect server error pages to the static page /40x.html
# #
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# # redirect server error pages to the static page /50x.html
# #
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
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 ~ .*\.(js|css)$ {
proxy_pass http://127.0.0.1:8000;
}
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
}
}
7.重启nginx
systemctl restart nginx
8.配置supervisor拉起进程
chkconfig supervisord on
vim /etc/supervisord.d/webvirtmgr.ini
#添加以下内容
[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
logfile=/var/log/supervisor/webvirtmgr.log
log_stderr=true
user=nginx
[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=nginx
# 在docker中安装webvirtmgr,需要修改/var/www/webvirtmgr/conf/gunicorn.conf.py
vim /var/www/webvirtmgr/conf/gunicorn.conf.py
# 将bind = "127.0.0.1:8000" 修改为
bind = "0.0.0.0:8000"
9. 设置ssh免密
mkdir /home/nginx
chown -R nginx:nginx /home/nginx
chmod -R 700 /home/nginx
su - nginx -s /bin/bash
ssh-keygen
touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
chmod 0600 ~/.ssh/config
ssh-copy-id remote_kvm_ip #宿主机所在的ip地址