当前位置:首页 > Web开发 > 正文

05 密码保护:Kvm管理之WebVirtMgr

2024-03-31 Web开发

密码保护:Kvm管理之WebVirtMgr 1. 前言

? 当Kvm宿主机越来越多,需要对宿主机的状态进行调控,决定采用WebVirtMgr作为Kvm虚拟化的web管理工具,图形化的WEB,让人能更方便的查看Kvm宿主机的情况和操作。

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

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

2. 特点

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

3. 功能

宿主机管理支持以下功能CPU利用率内存利用率网络资源池管理存储资源池管理虚拟机镜像虚拟机克隆快照管理日志管理虚机迁移

虚拟机管理支持以下功能

CPU利用率

内存利用率

光盘管理

关/开/暂停虚拟机

安装虚拟机VNC

console连接创建快照

4. 部署 1)、安装相关依赖

查看官网:https://github.com/retspen/webvirtmgr/wiki/Install-WebVirtMgr

首先要安装Kvm虚拟化环境,这里我将WebVirtMgr服务器和Kvm服务器放在同一台机器上部署的,即单机部署。

#1.安装epel源 [[email protected] ~]# yum install epel-release #2.安装依赖及环境 [[email protected] ~]# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx #3.安装编译软件 [[email protected] ~]# yum -y install gcc python-devel #4.安装numpy(Python进行科学计算的基础软件包) [[email protected] webvirtmgr]# pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple [[email protected] ~]# pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple 2)、安装Python需求环境 #1.从git-hub中下载相关的webvirtmgr代码 [[email protected] ~]# cd /usr/local/src/ [[email protected] /usr/local/src]# git clone git://github.com/retspen/webvirtmgr.git #2.安装WebVirtMgr [[email protected] /usr/local/src]# cd webvirtmgr/ [[email protected] /usr/local/src/webvirtmgr]# pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple #3.检查sqlite3 (备注:自带不需要安装,导入模块检查一下。) [[email protected] /usr/local/src/webvirtmgr]# python Python 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> exit() #4.初始化账号 [[email protected] /usr/local/src/webvirtmgr]# chmod +x manage.py [[email protected] /usr/local/src/webvirtmgr]# ./manage.py syncdb

技术图片

#5.生成配置文件 [[email protected] /usr/local/src/webvirtmgr]# ./manage.py collectstatic

技术图片

#6.添加管理员账号,这个是管理员账号,用上面的admin和这个账号都可以登录 [[email protected] /usr/local/src/webvirtmgr]# ./manage.py createsuperuser WARNING:root:No local_settings file found. Username (leave blank to use 'root'): ops Email address: [email protected] Password: Password (again): Superuser created successfully. #7.拷贝web到相关目录 [[email protected] /usr/local/src/webvirtmgr]# mkdir -pv /var/www mkdir: created directory '/var/www' [[email protected] /usr/local/src/webvirtmgr]# cp -rp /usr/local/src/webvirtmgr /var/www/webvirtmgr #8.设置ssh [[email protected] ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:CAIi5mok4liJ/kdhHu45iknOPhfla3rG+NLyNVSPwCk [email protected] The key's randomart image is: +---[RSA 2048]----+ |+. | |=o . . . | |+o+ .E + . | |O. .+o+.o o | |o+ o+..S. . | |. ..o.o | | . .==.o | |+.o=oBo . | |.*ooXo | +----[SHA256]-----+ #传密钥给当前主机 [[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub 10.0.0.162 #设置加密连接 [[email protected] ~]# ssh 10.0.0.162 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60 3)、配置Nginx #1.打开/etc/nginx/nginx.conf文件,注释server段 #2.编辑配置文件 [[email protected] ~]# cat /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 :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 } } #3.重新启动nginx服务 [[email protected] ~]# systemctl restart nginx #4.设置权限 [[email protected] ~]# chown -R nginx:nginx /var/www/webvirtmgr #5.创建/etc/supervisord.d/webvirtmgr.ini具有以下内容的文件 [[email protected] ~]# cat /etc/supervisord.d/webvirtmgr.ini [program:webvirtmgr] command=http://www.mamicode.com/usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py directory=http://www.mamicode.com/var/www/webvirtmgr autostart=true autorestart=true stdout_logfile=http://www.mamicode.com/var/log/supervisor/webvirtmgr.log redirect_stderr=true user=nginx [program:webvirtmgri-console] command=http://www.mamicode.com/usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-console directory=http://www.mamicode.com/var/www/webvirtmgr autostart=true autorestart=true stdout_logfile=http://www.mamicode.com/var/log/supervisor/webvirtmgr-console.log redirect_stderr=true user=nginx #6.启动守护进程supervisord [[email protected] ~]# systemctl start supervisord.service [[email protected] ~]# systemctl enable supervisord.service #7.查看端口 [[email protected] ~]# netstat -lntp |grep -E '6080|8000' tcp 0 0 127.0.0.1:6080 0.0.0.0:* LISTEN 14866/ssh tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 14866/ssh tcp6 0 0 ::1:6080 :::* LISTEN 14866/ssh tcp6 0 0 ::1:8000 :::* LISTEN 14866/ssh

8.浏览器IP地址访问

技术图片

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/41041.html