KVM WEB管理工具 WebVirtMgr

一、webvirtmgr介绍及环境说明

温馨提示:安装KVM是需要2台都操作的,因为我们是打算将2台都设置为宿主机所有都需要安装KVM相关组件

github地址https://github.com/retspen/webvirtmgr

WebVirtMgr是一个基于libvirt的Web界面,用于管理虚拟机。它允许您创建和配置新域,并调整域的资源分配。VNC查看器为来宾域提供完整的图形控制台。KVM是目前唯一支持的虚拟机管理程序。

4cba1ec9e3cfb396c9c82009d554e4c6.png

查看服务器版本号

[root@webc ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

内核版本

[root@webc ~]# uname -r
3.10.0-1160.42.2.el7.x86_64

关闭Selinux & 防火墙

[root@webc ~]# systemctl stop firewalld
[root@webc ~]# systemctl disable firewalld
[root@webc ~]# setenforce 0
setenforce: SELinux is disabled
[root@webc ~]# sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

更新软件包并安装epel扩展源

[root@webc ~]# yum update
[root@webc ~]# yum install epel*

查看python版本

[root@webc ~]# python -V
Python 2.7.5
[root@webc ~]#

查看KVM 驱动是否加载

[root@webc ~]# lsmod | grep kvm
kvm_intel             188740  0
kvm                   637515  1 kvm_intel
irqbypass              13503  1 kvm
[root@webc ~]#
[root@webc ~]#
[root@webc ~]# modprobe -a kvm
[root@webc ~]# modprobe -a kvm_intel
[root@webc ~]#

免密配置

[root@webc ~]# ssh-keygen
[root@webc ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.104

二、安装KVM

安装KVM依赖包及管理工具

kvm属于内核态,不需要安装。但是需要一些管理工具包

[root@webc ~]# yum install qemu-img qemu-kvm qemu-kvm-tools virt-manager virt-viewer virt-v2v virt-top libvirt libvirt-Python libvirt-client python-virtinst bridge-utils tunctl
[root@webc ~]# yum install -y virt-install
[root@webc ~]#
[root@webc ~]# systemctl start libvirtd.service
[root@webc ~]# systemctl enable libvirtd.service
[root@webc ~]#
[root@webc ~]# cd cby/kvm/
[root@webc kvm]#
[root@webc kvm]#
[root@webc kvm]#  git clone https://github.com/palli/python-virtinst.git
[root@webc kvm]# cd python-virtinst/
[root@webc python-virtinst]#  python setup.py install
[root@webc python-virtinst]# virt-install
[root@webc python-virtinst]# yum install bridge-utils
[root@webc python-virtinst]#
[root@webc python-virtinst]# vim /etc/sysconfig/network-scripts/ifcfg-br0
[root@webc python-virtinst]#
[root@webc python-virtinst]#
[root@webc python-virtinst]#
[root@webc python-virtinst]#
[root@webc python-virtinst]#
[root@webc python-virtinst]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.49
NETMASK=255.225.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
[root@webc python-virtinst]# brctl show
bridge name bridge id       STP enabled interfaces
br-0d093958d245     8000.0242d5824d14   no      
br-2e2d3c481379     8000.0242884030e2   no      
br-36a6ad3375a8     8000.0242d7d7f1ef   no      
br-66a9675a6dd5     8000.024248a61c72   no      
br-b7daf4844ff7     8000.024263dd4715   no      
br-deba197eb09e     8000.0242b290e104   no      
br0     8000.000000000000   no      
docker0     8000.0242858c017c   no      vethe14f7ac
docker_gwbridge     8000.0242588c6db0   no      
virbr0      8000.5254009ba65a   yes     virbr0-nic
[root@webc python-virtinst]# ln -s /usr/libexec/qemu-kvm /usr/sbin/

三、WebVirtMgr 安装

安装pip、git及supervisor && Nginx

WebVirtMgr只在管理端安装

[root@webc ~]# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor gcc python-devel

使用pip安装Python扩展程序库

[root@webc ~]# pip install numpy

git克隆配置并运行WebVirMgr

[root@webc ~]# cd cby/
[root@webc cby]# mkdir kvm
[root@webc cby]# cd kvm
[root@webc kvm]# pwd
/root/cby/kvm
[root@webc kvm]#
[root@webc kvm]# git clone git://github.com/retspen/webvirtmgr.git
正克隆到 'webvirtmgr'...
remote: Enumerating objects: 5614, done.
remote: Total 5614 (delta 0), reused 0 (delta 0), pack-reused 5614
接收对象中: 100% (5614/5614), 2.97 MiB | 748.00 KiB/s, done.
处理 delta 中: 100% (3606/3606), done.
[root@webc kvm]#
[root@webc kvm]#
[root@webc kvm]# cd webvirtmgr
[root@webc webvirtmgr]# pip install -r requirements.txt
#初始化环境
[root@webc webvirtmgr]# ./manage.py syncdb


#配置Django 静态页面
[root@webc webvirtmgr]# ./manage.py collectstatic

启动WebVirMgr

前台启动WebVirMgr,默认是Debug模式同时日志打印在前台

b4ec61572736fa334c22619dfcedeeac.png

用户名和密码是我们刚刚创建的

下载Nginx

[root@webc webvirtmgr]# cd ..
[root@webc kvm]# ls
webvirtmgr
[root@webc kvm]#
[root@webc kvm]# mkdir nginx
[root@webc kvm]# cd nginx
[root@webc nginx]# wget https://nginx.org/download/nginx-1.20.1.tar.gz
[root@webc nginx]# tar xf nginx-1.20.1.tar.gz
[root@webc nginx]# cd nginx-1.20.1/
[root@webc nginx-1.20.1]#

修改nginx配置文件

[root@webc conf]# vim nginx.conf
[root@webc conf]#
[root@webc conf]# cat nginx.conf
user  root;
worker_processes  1;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       90;
        server_name  192.168.1.104;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            #root   html;
            #index  index.html index.htm;
            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 $remote_addr;
            proxy_connect_timeout 600;
            proxy_read_timeout 600;
            proxy_send_timeout 600;
            client_max_body_size 5120M;
        }
        location /static/ {
            root /root/cby/kvm/webvirtmgr;
            expires max;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
[root@webc conf]#

安装Nginx

[root@webc nginx-1.20.1]# yum install -y gcc glibc gcc-c++ prce-devel openssl-devel pcre-devel
[root@webc nginx-1.20.1]# useradd -s /sbin/nologin nginx -M
[root@webc nginx-1.20.1]# ./configure --prefix=/root/cby/kvm/nginx/ --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
[root@webc nginx-1.20.1]# make && make install

启动Nginx

[root@webc nginx-1.20.1]# cd /root/cby/kvm/nginx/sbin/
[root@webc sbin]# /root/cby/kvm/nginx/sbin/nginx -t
nginx: the configuration file /root/cby/kvm/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /root/cby/kvm/nginx//conf/nginx.conf test is successful
[root@webc sbin]# /root/cby/kvm/nginx/sbin/nginx

使用systemctl启停服务

[root@webc sbin]# cat > /etc/supervisord.d/webvirtmgr.ini << EOF
[program:webvirtmgr]
command=/usr/bin/python /root/cby/kvm/webvirtmgr/manage.py run_gunicorn -c /root/cby/kvm/webvirtmgr/conf/gunicorn.conf.py
directory=/root/cby/kvm/webvirtmgr
autostart=true
autorestart=true
logfile=/var/log/supervisor/webvirtmgr.log
log_stderr=true
user=root
 
[program:webvirtmgr-console]
command=/usr/bin/python /root/cby/kvm/webvirtmgr/console/webvirtmgr-console
directory=/root/cby/kvm/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=root
EOF

启动supervisor

[root@webc webvirtmgr]# systemctl daemon-reload
[root@webc webvirtmgr]# systemctl stop supervisord
[root@webc webvirtmgr]# systemctl start supervisord

查看是否启动成功

[root@webc webvirtmgr]# supervisorctl status
webvirtmgr                       RUNNING   pid 23783, uptime 0:00:11
webvirtmgr-console               RUNNING   pid 23782, uptime 0:00:11
[root@webc webvirtmgr]#

53305912f26019891b76b52a190b8e62.png

四、Web界面配置webvirtmgr

4.1 添加主机设置存储

1.Add Connection 添加宿主机(即KVM主机)

2.点击SSH连接

3.Label 为主机名,必须为主机名做免密

4.IP 为宿主机IP

5.用户名为服务器用户名

6.点击添加

510476145f05e2b5b0e633a7c349d964.png

d3f598d248f1a9abfa2592a08f9a4870.png

<think>好的,我需要帮助用户找到关于KVM虚拟机的Web管理工具或方法。用户提到了通过Web界面管理或者推荐相关工具。首先,我需要回忆一下KVM常用的管理工具,特别是基于Web的。 我记得之前有看到过Cockpit这个工具,它可以通过浏览器来管理服务器,包括KVM虚拟机。引用中的第三个资料提到通过Cockpit管理KVM虚拟机,安装相关套件后,通过浏览器访问。所以Cockpit应该是一个可行的选项。需要详细说明安装和配置步骤,比如安装kvm套件、cockpit,配置防火墙,启动服务等步骤。 另一个可能的工具是WebVirtMgr,这是一个专门为KVM设计的Web管理界面。用户需要安装Python和相关依赖,配置Nginx作为反向代理,然后通过浏览器访问。不过用户提供的引用中没有提到这个,可能需要补充说明,但根据我的知识,这是一个常见工具。 还有Proxmox VE,它是一个完整的虚拟化管理平台,基于Web界面,支持KVM和容器。但可能需要安装整个Proxmox系统,而不仅仅是作为插件。这可能适合需要更全面解决方案的用户。 在回答时,需要按照用户的要求,结构清晰,分步骤说明。每个工具单独列出,包括安装步骤和使用方法。同时要注意引用中的信息,比如引用3提到的Cockpit的安装和访问方式,必须正确引用。 需要检查是否有其他Web工具,比如Ovirt,但Ovirt可能更复杂,适合企业环境。而用户可能更需要简单易用的工具,所以重点推荐Cockpit和WebVirtMgr,并提到Proxmox作为备选。 另外,用户的问题是如何通过Web界面管理,所以需要确保每个方法都明确说明是通过浏览器访问的。例如,Cockpit的访问地址是https://服务器IP:9090,WebVirtMgr可能需要配置Nginx和端口,Proxmox有自己的Web界面。 安装步骤需要具体,比如使用yum或apt安装包,启动服务,防火墙设置等。同时要注意不同Linux发行版的命令可能不同,用户可能需要根据系统调整。 最后,生成相关问题,可能需要考虑其他管理方式、安全性、性能优化等。</think>### 通过Web界面管理KVM虚拟机的工具及方法 #### 1. **Cockpit(推荐)** Cockpit是一个轻量级Web控制台,可直接管理KVM虚拟机,适合无图形界面(GUI)的服务器环境。 **配置步骤**: 1. 安装KVM虚拟化套件与Cockpit: ```bash # CentOS/RHEL sudo yum install cockpit cockpit-machines qemu-kvm libvirt # Ubuntu/Debian sudo apt install cockpit cockpit-machines qemu-kvm libvirt-daemon ``` 2. 启动服务并开放防火墙: ```bash sudo systemctl enable --now cockpit.socket sudo firewall-cmd --add-service=cockpit --permanent # CentOS/RHEL sudo ufw allow 9090/tcp # Ubuntu/Debian ``` 3. 浏览器访问: 输入 `https://<服务器IP>:9090`,使用系统账户登录后,通过“Virtual Machines”模块管理KVM虚拟机[^3]。 --- #### 2. **WebVirtMgr** WebVirtMgr是专为KVM设计的开源Web管理工具,支持虚拟机创建、快照和资源监控。 **部署步骤**: 1. 安装依赖: ```bash sudo apt install git python3-pip libvirt-dev nginx # Ubuntu/Debian ``` 2. 克隆仓库并配置: ```bash git clone https://github.com/retspen/webvirtmgr.git cd webvirtmgr pip3 install -r requirements.txt ./manage.py migrate ./manage.py collectstatic ``` 3. 配置Nginx反向代理并启动服务,通过浏览器访问 `http://<服务器IP>:8000`。 --- #### 3. **Proxmox VE** Proxmox VE是集成KVM/LXC的虚拟化平台,提供完整的Web管理界面,适合企业级部署。 **使用方法**: 1. 下载ISO镜像并安装Proxmox VE系统。 2. 访问 `https://<服务器IP>:8006`,通过Web界面创建KVM虚拟机并分配资源。 --- ### 工具对比 | 工具 | 复杂度 | 适用场景 | 功能特性 | |-------------|--------|------------------------|------------------------------| | Cockpit | 低 | 简单运维、单机管理 | 集成系统监控、轻量化 | | WebVirtMgr | 中 | 中小规模虚拟化环境 | 支持多主机、快照管理 | | Proxmox VE | 高 | 企业级虚拟化集群 | 存储集群、高可用性、备份恢复 | ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值