作者:SRE运维博客

博客地址: https://www.cnsre.cn/

文章地址:https://www.cnsre.cn/posts/211117937177/

相关话题:https://www.cnsre.cn/tags/kvm/


WebVirtMgr是近两年来发展较快,比较活跃,非常清新的一个KVM管理平台,提供对宿主机和虚机的统一管理,它有别于kvm自带的图形管理工具(virtual machine manager),让kvm管理变得更为可视化,对中小型kvm应用场景带来了更多方便。

WebVirtMgr介绍

WebVirtMgr采用几乎纯Python开发,其前端是基于Python的Django,后端是基于Libvirt的Python接口,将日常kvm的管理操作变的更加的可视化。

  • WebVirtMgr 特点

操作简单,易于使用 、通过libvirt的API接口对kvm进行管理、提供对虚拟机生命周期管理

  • WebVirtMgr 功能

宿主机管理支持以下功能、CPU利用率、内存利用率、网络资源池管理、存储资源池管理、虚拟机镜像、虚拟机克隆、快照管理、日志管理、虚机迁移、虚拟机管理支持以下功能、CPU利用率、内存利用率、光盘管理、关/开/暂停虚拟机、安装虚拟机、VNC console连接、创建快照

官方文档

https://github.com/retspen/webvirtmgr/wiki/Install-WebVirtMgr

安装前的部署

安装一些依赖包

yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx gcc python-devel wget vim net-tools lrzsz

安装pip

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip -V 

pip install numpy

安装python的需要包和配置Django环境

git clone git://github.com/retspen/webvirtmgr.git

安装nginx

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx -y

安装supervisor

安装参考

https://www.2cto.com/kf/201712/702837.html

开机自启参考

https://blog.csdn.net/binggoogle/article/details/53203991

cat  /etc/supervisord.conf

{{< alert theme="warning" dir="ltr" >}}

️ 注意

如果没有这个文件按照一下步骤安装

有的话忽略此步骤

{{< /alert >}}

pip install supervisor
mkdir /etc/supervisord.d/
echo_supervisord_conf > /etc/supervisord.conf

新建文件夹

vim /etc/supervisord.d/app.conf

配置文件 app.conf

内容为

[program:appname]
command=/root/soft/push.api
directory=/root/soft/push.api
autostart=true
autorestart=true
user=root
stdout_logfile = /var/log/supervisor/pushapi.log
stderr_logfile = /var/log/supervisor/pushapi-error.log

修改 在配置文件最下方修改为

vim  /etc/supervisord.conf
[include]
files = /etc/supervisord.d/*.ini

supervisord -c /etc/supervisord.conf
/usr/bin/supervisorctl start all
/usr/bin/supervisorctl stop all

安装环境

cd webvirtmgr
pip install -r requirements.txt

./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
Email address: 275301281@qq.com
Password: admin
Password (again):admin
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)
./manage.py collectstatic

配置一个超级用户

./manage.py createsuperuser

WARNING:root:No local_settings file found.
Username (leave blank to use 'root'): yes
Email address: 275301281@qq.com
Password: Lenovo@123
Password (again): Lenovo@123
Superuser created successfully.

设置nginx

a、使用:8000端口

移动这个 webvirtmgr 目录到 /var/www

cd  ..
mv webvirtmgr /var/www/

{{< alert theme="warning" dir="ltr" >}}

注意:

webvirtmgr 目录下还有一个名称为webvirtmgr 的文件夹

不要单独移动 webvirtmgr/webvirtmgr 文件

{{< /alert >}}

编辑配置文件

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
}
}

启动nginx并设置开机自启动

(如果不设置开机自启动,重启服务器supervisor无法管理Django进程),并开机自启动supervisord

/etc/init.d/nginx start

或者

systemctl restart   nginx
systemctl enable supervisord

分配权限

chown nginx.nginx /var/www/webvirtmgr

设置supervisor

/etc/supervisord.conf末尾加入下面的配置:

vi /etc/supervisord.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
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

{{< alert theme="warning" dir="ltr" >}}

注意

进程无法启动或者报错 可以选择吧 log 注释取消

{{< /alert >}}

重启supervisord

开机自启参考

https://blog.csdn.net/binggoogle/article/details/53203991

设置完之后重启即可

systemctl restart  supervisord.service
systemctl enable supervisord.service
systemctl status supervisord.service

更新

cd /var/www/webvirtmgr git pull

./manage.py collectstatic

systemctl  restart supervisord

如果有错误或不运行

 ./manage.py runserver 0:8000
#或者后台运行脚本
nohup python /var/www/webvirtmgr/manage.py runserver 0:8000 >/dev/null &
nohup python /var/www/console/webvirtmgr-console >/dev/null &

访问:http://x.x.x.x:8000(x.x.x.x - your server IP address ),输入创建的用户和密码,如果没有创建,请用python manager.py createsuperuser,命令创建。登录后如下图所示

配置虚拟机所在宿主机

webvirtmgr客户端就这样搭建完了,接下来需要配置虚拟机所在宿主机的,参考git地址.

配置宿主机

下载并执行脚本

如果虚拟机比较多,该脚本执行时间会比较长,因为会执行 service libvirt-guests restart,会将所有运行的虚拟机挂起然后再恢复,感觉这一步不是必须的,因为我有一台只设置ssh认证,也可以正常连接。

curl http://retspen.github.io/libvirt-bootstrap.sh | sudo sh

如果没有curl就用wget

wget -O - http://retspen.github.io/libvirt-bootstrap.sh | sudo sh

配置防火墙

iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 16509 -j ACCEPT

设置TCP授权

参考:https://github.com/retspen/webvirtmgr/wiki/Setup-TCP-authorization

webvirtmgr新建服务器连接时需要此账号

用saslpasswd2命令给libvirt的用户cnsre设置密码

saslpasswd2 -a libvirt cnsre
Password: cnsre
Again (for verification): cnsre

生成一个密码库

sasldblistusers2 -f /etc/libvirt/passwd.db 

cnsre@webvirtmgr.cn: userPassword

设置ssh授权

ssh-keygen -t rsa       # 产生公私钥

直接回车,回车,回车

ssh-copy-id 192.168.1.120

{{< alert theme="warning" dir="ltr" >}}

注意

由于这里webvirtmgr和kvm服务部署在同一台机器,所以这里本地信任。

如果kvm部署在其他机器,那么这个是其他它的ip 同时也要设置ssh key密钥

{{< /alert >}}

提示输入密码的时候直接输入之前1.120的密码

ssh 192.168.1.120 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080

web 平台加入其他kvm宿主机

在部署web管理的主机上执行命令

ssh-keygen -t rsa

然后在执行

ssh-copy-id 192.168.1.165

添加新的kvm宿主机

查看新加的kvm宿主机状态 看有无报错

删除新加的账号

sudo saslpasswd2 -a libvirt -d cnsre

确认验证新加的账号配置

virsh -c qemu+tcp://IP_address/system nodeinfo
(virsh -c qemu+tcp://192.168.1.50/system nodeinfo)
Please enter your authentication name: cnsre
Please enter your password: xxxxxx
CPU model: x86_64
CPU(s): 2
CPU frequency: 2611 MHz
CPU socket(s): 1
Core(s) per socket: 2
Thread(s) per core: 1
NUMA cell(s): 1
Memory size: 2019260 kB

{{< alert theme="warning" dir="ltr" >}}

注意

账号全名带hostname,如 cnsre@webvirtmgr.cn

测试的时候这一步测试没有成功 但是可以链接

{{< /alert >}}

设置ssh认证

{{< notice warning "注意" >}}

ssh和tcp设置一种即可,其实就是设置无密码登录,要注意的是从webvirtmgr的什么用户到宿主机的什么用户的无密码登录,比如我用root跑的django webvirtmgr,而宿主机也是root跑的virsh,所以需要设置root到root的无密码登录。而git官网推荐的是用nginx用户跑django webvirtmgr,webvirtmgr用户跑的virsh,所以设置的是nginx用户到宿主机webvirtmgr用户的无密码登录。

{{< /notice >}}

参考:https://github.com/retspen/webvirtmgr/wiki/Setup-SSH-Authorizatio

使用tcp认证连接服务器

访问:http://192.168.1.120:8000,xxxx是webvirtmgr的ip地址,点击new connection

填写kvm宿主机的一些信息

基础架构可以看到一些vm虚拟机

KVM WEB管理常见报错

网页控制台 远程链接报错1006

安装vnc即可

yum install -y novnc

网页控制台 远程链接报错505

cd /var/www/console/
./webvirtmgr-console &

后台运行脚本

nohup python  /var/www/webvirtmgr/manage.py runserver 0:8000  >/dev/null &
nohup python /var/www/console/webvirtmgr-console >/dev/null &

作者:SRE运维博客

博客地址: https://www.cnsre.cn/

文章地址:https://www.cnsre.cn/posts/211117937177/

相关话题:https://www.cnsre.cn/tags/kvm/


快速搭建 kvm web 管理工具 WebVirtMgr的更多相关文章

  1. KVM web管理工具——WebVirtMgr(一)

    WebVirtMgr 介绍     WebVirtMgr采用几乎纯Python开发,其前端是基于Python的Django,后端是基于Libvirt的Python接口,将日常kvm的管理操作变的更加的 ...

  2. KVM WEB管理工具webvirtmgr安装和使用

    生产环境的KVM宿主机越来越多,需要对宿主机的状态进行调控.这里用webvirtmgr进行管理.图形化的WEB,让人能更方便的查看kvm 宿主机的情况和操作 1 安装支持的软件源 yum -y ins ...

  3. KVM WEB管理工具——WebVirtMgr(二)日常配置

    配置宿主机 1.登录WebVirtMgr管理平台 2.添加宿主机 选择首页的WebVirtMgr -->Addd Connection 选择“SSH链接“,设置Label,IP,用户 注意:La ...

  4. KVM web管理工具——WebVirtMgr

    系统环境: [root@kvm-admin ~]# cat /etc/redhat-release CentOS Linux release (Core) 关闭防火墙.selinux [root@kv ...

  5. KVM Web管理平台 WebVirtMgr

    WebVirtMgr介绍 WebVirtMgr是一个KVM管理平台,让kvm管理变得更为可视化,对中小型kvm应用场景带来了更多方便.WebVirtMgr采用几乎纯Python开发,其前端是基于Pyt ...

  6. 虚拟化技术之kvm WEB管理工具kimchi

    在前面的博客中,我们介绍了kvm的各种工具,有基于图形管理的virt-manager.有基于命令行管理的virt-install .qemu-kvm.virsh等等:今天我们来介绍一款基于web界面的 ...

  7. CentOS 7搭建KVM在线管理面板WebVirtMgr之使用SSH授权登录

    环境:CentOS 7.4 1.创建SSH私钥和ssh配置选项(在安装了WebVirtMgr的系统上): # 切换到nginx用户su - nginx -s /bin/bash # 生产ssh密钥 s ...

  8. KVM网页管理工具WebVirtMgr部署

    KVM-WebVirtMgr 0ther https://github.com/retspen/webvirtmgr/wiki System Optimization(Only CentOS6.X) ...

  9. CentOS 7搭建KVM在线管理面板WebVirtMgr

    系统版本:CentOS 7.4 WebVirtMgr版本:master分支的20180720版本,下载链接(链接:https://pan.baidu.com/s/1kl060hPHDGbwJUR_iM ...

随机推荐

  1. 三种方法求解最大子区间和:DP、前缀和、分治

    题目 洛谷:P1115 最大子段和 LeetCode:最大子序和 给出一个长度为 \(n\) 的序列 \(a\),选出其中连续且非空的一段使得这段和最大. 挺经典的一道题目,下面分别介绍 \(O(n) ...

  2. css新增属性之边框

    css3新增属性 边框属性 背景属性 文字属性 颜色属性 边框属性 属性 说明 border-radius 设置边框圆角 border-image 设置图像边框 border-shadow 设置边框阴 ...

  3. docker采用registry部署简易仓库

    解释:registry部署简易仓库,实现免密上传拉取镜像(解决不在一个容器里,也能够实现镜像拉取成功) 1.安装启动registry服务 docker pull registry docker run ...

  4. 单体应用 适合采用 dapr 构建吗?

    缘起今天在微信群里有同学问 "纯.net 项目,有必要上dapr吗?" 当时不假思索的说不是微服务没必要,其他群友也说没必要.下午细想了一下,觉得这个和微服务没有关系,如果我的应用 ...

  5. 洛谷4234最小差值生成树 (LCT维护生成树)

    这也是一道LCT维护生成树的题. 那么我们还是按照套路,先对边进行排序,然后顺次加入. 不过和别的题有所不同的是: 在本题中,我们需要保证LCT中正好有\(n-1\)条边的时候,才能更新\(ans\) ...

  6. Windows 10下CUDA及cuDNN的安装 —— Pytorch

    Windows 10下CUDA及cuDNN的安装 CUDA简介与下载地址 CUDA(ComputeUnified Device Architecture),是显卡厂商NVIDIA推出的运算平台. CU ...

  7. TCC分布式事务的实现原理

    目录 一.写在前面 二.业务场景介绍 三.进一步思考 四.落地实现TCC分布式事务 (1)TCC实现阶段一:Try (2)TCC实现阶段二:Confirm (3)TCC实现阶段三:Cancel 五.总 ...

  8. Dapr-服务调用

    前言 上一篇对Dapr进行了了解,并搭建了Dapr环境.接下来就对Dapr的各个构建块类型的了解.应用实际案例. 一.服务调用: 在许多具有多个需要相互通信的服务的环境中,都会面临着很多问题. 如: ...

  9. Apache Zookeeper Java客户端Curator使用及权限模式详解

    这篇文章是让大家了解Zookeeper基于Java客户端Curator的基本操作,以及如何使用Zookeeper解决实际问题. Zookeeper基于Java访问 针对zookeeper,比较常用的J ...

  10. [对对子队]会议记录4.17(Scrum Meeting8)

    今天已完成的工作 何瑞 ​ 工作内容:修复了一些bug,优化了UI ​ 相关issue:搭建关卡1 ​ 相关签入:4.17签入1 吴昭邦 ​ 工作内容:做了一些流水线系统的错误处理,添加了合成失败了之 ...