docker 部署 kvm 图形化管理工具 WebVirtMgr

镜像构建

  • 官方最后一次更新已经是 2015年6月22日 了,官方也没有 docker 镜像,这边选择咱们自己构建
  • 如果你的服务器有魔法,可以直接 git clone 一下 webvirtmgr 的包,没有的话,可以和我一样,提前从 github 上下载下来,上传到机器上,然后 ADD 到容器里面
  • 这个项目已经很悠久了,只能用 2.x 的 python,这里就直接用 centos 作为基础镜像,对比过 debian 和 python 镜像,构建完都要1G多,用 centos 构建完只有 560MB
  • 官方地址【先把包下载下来】:Release WebVirtMgr · retspen/webvirtmgr · GitHub
复制代码
FROM docker.m.daocloud.io/centos:7.6.1810

ADD start.sh /start.sh
ADD webvirtmgr-4.8.9.tar.gz /

WORKDIR /webvirtmgr-4.8.9

# yum 相关的依赖
RUN rm -f /etc/yum.repos.d/*.repo && \
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo && \
    yum install -y epel* && \
    yum install -y python-pip libvirt-python libxml2-python python-websockify gcc python-devel && \
    yum clean all

# python 相关的依赖
RUN pip install numpy==1.16.3 -i https://mirrors.aliyun.com/pypi/simple/ && \
    pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ && \
    echo no | python manage.py syncdb && \
    echo yes | python manage.py collectstatic

# webvirtmgr 通过 tcp 连接 kvm 相关的依赖
RUN yum install -y cyrus-sasl cyrus-sasl-scram cyrus-sasl-devel cyrus-sasl-md5 && \
    yum clean all

CMD ["/usr/bin/bash","/start.sh"]

这里是 ADD 里面的启动脚本 start.sh,本地记得 chmod +x start.sh 加个执行权限

复制代码
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@localhost', '1qaz@WSX')" | /usr/bin/python /webvirtmgr-4.8.9/manage.py shell
/usr/bin/python /webvirtmgr-4.8.9/manage.py run_gunicorn --bind 0.0.0.0:8000 --log-file /webvirtmgr-4.8.9/webvirtmgr.log --daemon
if [ $? -eq 0 ];then
  nohup /usr/bin/python /webvirtmgr-4.8.9/console/webvirtmgr-console &> /dev/null &
  sleep 3
  tail -f /webvirtmgr-4.8.9/webvirtmgr.log
fi

构建镜像

复制代码
docker build -t webvirtmgr:4.8.9-centos-7.6 .

启动 webvirtmgr

启动参数仅供参考,里面有些配置是我本地环境相关的

  • 如果 kvm 和 webvirtmgr 是相同机器,可以把 /var/run/libvirt/libvirt-sock 文件带入到容器内,就可以实现 local socket 的方式连接 kvm 宿主机了
复制代码
docker run -d \
--restart=always \
--network host \
--memory 1024m \
--name webvirtmgr \
-v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock \
webvirtmgr:4.8.9-centos-7.6
创建其他 superuser

进入 webvirtmgr 容器

复制代码
docker exec -it webvirtmgr bash

创建其他超级用户

复制代码
python manage.py createsuperuser

浏览器访问 IP:8000 看看能不能访问到 webvirtmgr 的页面

默认的用户名是 admin,密码是 1qaz@WSX,在启动脚本里面可以找到

修改密码:python manage.py changepassword admin

配置 nginx 反向代理和域名访问

这一步不是必须的,有需求就做,这里也是用的 docker 容器的方式运行的,下面是需要打包到容器内的配置文件

复制代码
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    # access_log  /var/log/nginx/access.log  main;

    # sendfile        on;
    # tcp_nopush     on;

    keepalive_timeout  65;
    gzip  on;

    server {
        listen       80;
        # 这里的域名,修改成自己的
        server_name  virtmgr.icu;
        # access_log /var/log/nginx/webvirtmgr_access_log;

        location / {
            proxy_pass http://192.168.18.222: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;
            # 这里的配置,也可以再放大一点,这个会影响 iso 镜像的上传
            ## 如果直接放到指定的 iso 目录下,那就不受影响
            client_max_body_size 5120M;
        }

        location /static {
            proxy_pass http://192.168.18.222:8000/static;
        }
    }
}

下面是 Dockerfile

复制代码
FROM docker.m.daocloud.io/nginx:1.26.0
ADD ./nginx.conf /etc/nginx/nginx.conf

构建镜像

复制代码
docker build -t webvirtmgr-static:4.8.9-nginx-1.26.0 .

启动镜像

复制代码
docker run -d --rm \
-p 80:80 \
--memory 200m \
--name webvirtmgr-static \
webvirtmgr-static:4.8.9-nginx-1.26.0

使用域名访问,域名没有 dns 解析的,可以本地自己配置一下 hosts

纳管KVM 宿主机,采用ssh方式

进入 webvirtmgr 容器

复制代码
docker exec -it webvirtmgr bash
bash 复制代码
cd ~

ssh-keygen 

一直选择y

ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.100.234

测试免密是否生效:

ssh root@192.168.100.234

免密没问题就可以在界面加入要管理的KVM宿主机了

相关推荐
tuokuac18 小时前
docker中nginx配置报错解决
linux·运维·服务器
Joren的学习记录20 小时前
【Linux运维大神系列】docker详解(四)
linux·运维·docker
Elastic 中国社区官方博客21 小时前
让我们把这个 expense 工具从 n8n 迁移到 Elastic One Workflow
大数据·运维·elasticsearch·搜索引擎·ai·信息可视化·全文检索
( •̀∀•́ )92021 小时前
GitHub Actions SSH 部署密钥
运维·ssh·github
louqle21 小时前
docker基本知识及常用命令汇总
运维·docker·容器
学烹饪的小胡桃1 天前
【运维学习】实时性能监控工具 WGCLOUD v3.6.2 更新介绍
linux·运维·服务器·学习·工单系统
叫致寒吧1 天前
Docker
运维·docker·容器
杨浦老苏1 天前
现代流媒体聚合播放器冬瓜TV MAX
docker·群晖·多媒体
白露与泡影1 天前
使用systemd,把服务装进 Linux 心脏里~
linux·运维·python
l1t1 天前
用docker安装oracle 19c
运维·数据库·docker·oracle·容器