简介
管理平台:WebVirMgr
WebVirMgr简介
WebVirtMgr作为kvm虚拟化的web管理工具,图形化的WEB,让人能更方便的查看kvm 宿主机的情况和操作,使用kvm+webvirtmgr便可满足当前场景的业务需求,虚拟化的同时,也能够进行便捷的管理。
介绍:
WebVirtMgr采用几乎纯Python开发,其前端是基于Python的Django,后端是基于Libvirt的 Python接口,将日常kvm的管理操作变的更加的可视化。
特点:
操作简单,易于使用
通过libvirt的API接口对kvm进行管理
提供对虚拟机生命周期管理
功能:
宿主机管理支持以下功能 :
CPU利用率
内存利用率
网络资源池管理
存储资源池管理
虚拟机镜像
虚拟机克隆
快照管理
日志管理
虚拟机迁移
虚拟机管理支持以下功能 :
CPU利用率
内存利用率
光盘管理
关/开/暂停虚拟机
安装虚拟机
VNC console连接
创建快照
WebVirtMgr部署
WebVirtMgr 管理服务器配置
1、安装epel源、git,gcc等软件
[root@kvm02 ~]# yum -y install https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[root@kvm02 ~]# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx
[root@kvm02 ~]# yum -y install gcc gcc-c++ make python-devel
2、安装数据库
[root@kvm02 ~]# yum install mariadb-server -y
[root@kvm02 ~]# systemctl start mariadb
[root@kvm02 ~]# mysql -e 'create database webvirtmgr default character set utf8; '
[root@kvm02 ~]# mysql -e 'grant all on webvirtmgr.* to webvirtmgr@"localhost" identified by "webvirtmgr";'
3、从github中下载相关的webvirtmgr代码
[root@kvm02 ~]#mkdir /application/
[root@kvm02 ~]#cd /application/
(1)本地源码上传及解压
[root@kvm02 application]# ls
webvirtmgr-master.zip
[root@kvm02 application]# yum install -y unzip
#安装解压工具
[root@kvm02 application]# unzip webvirtmgr-master.zip
#解压软件包
(2)通过网上源码下载
[root@kvm02 application]# git clone git://github.com/retspen/webvirtmgr.git
或git clone https://github.com/retspen/webvirtmgr.git
注意:github无法下载时,通过码云下载
[root@kvm02 application]# git clone https://gitee.com/huasuifengqu/webvirtmgr.gitgithu
[root@kvm02 application]# cd /application/webvirtmgr
[root@kvm02 webvirtmgr-master]# pip install --upgrade pip
#更新pip
[root@kvm02 webvirtmgr-master]# pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
#安装python依赖包
4、配置webvirtmgr
# 编辑/application/webvirtmgr/webvirmgr/settings.py
# 将sqlite3改为mysql数据库
[root@kvm02 webvirtmgr]# vim webvirtmgr/settings.py
# 替换为
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', 'NAME': 'webvirtmgr',
'USER': 'webvirtmgr', 'PASSWORD': 'webvirtmgr',
'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '3306', # Set to empty string for default.
}
}
#初始化数据库
[root@kvm02 webvirtmgr]# yum install -y MySQL-python
[root@kvm02 webvirtmgr]#./manage.py syncdb
#同步数据库
[root@kvm02 webvirtmgr]./manage.py collectstatic
[root@kvm02 webvirtmgr]./manage.py createsuperuser
#添加超级管理员
5、配置nginx
# mkdir -pv /var/www
# cp -Rv /application/webvirtmgr /var/www/webvirtmgr
# 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 $remote_addr;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M; # Set higher depending on your needs
}
}
[root@KVM01 webvirtmgr]# chown -R nginx:nginx /var/www/webvirtmgr #修改文件的权限
6、配置supervisord服务
其实是在supervisord服务增加webvirtmgr进程的启动,依赖这个服务而已。
[root@KVM02 webvirtmgr]## vim /etc/supervisord.conf #末尾添加以下配置
[program:webvirtmgr]
command=/usr/bin/python2 /var/www/webvirtmgr/manage.py run_gunicorn -c
/var/www/webvirtmgr/conf/gunicorn.conf.py #启动8000端口
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/python2 /var/www/webvirtmgr/console/webvirtmgr-console #启动6080端口(这是控制台vnc端口)
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=nginx
确保下面bind绑定的是本机的8000端口,这个在nginx配置中定义了, 被代理的端口
[root@KVM01 webvirtmgr]# grep '^bind =' /var/www/webvirtmgr/conf/gunicorn.conf.py
#bind = '127.0.0.1:8000'
[root@KVM02 webvirtmgr]#vim /etc/nginx/nginx.conf
注释掉默认的80端口
[root@KVM02 webvirtmgr]# systemctl restart nginx.service
[root@KVM02 webvirtmgr]# systemctl restart supervisord
#重启服务
7、权限设置,设置local登陆的一种方式
[root@KVM02 webvirtmgr]# groupadd libvirtd
#增加权限组
[root@KVM02 webvirtmgr]# usermod -a -G libvirtd root
[root@KVM02 webvirtmgr]# usermod -a -G libvirtd nginx
#增加用户到权限组
[root@KVM02 webvirtmgr]# vim /etc/libvirt/libvirtd.conf
unix_sock_group = "libvirtd"
#设置kvm服务libvirtd启动权限增加权限启动配置
[root@KVM02 webvirtmgr]# vim /etc/polkit-1/localauthority/50-local.d/50-org.libvirtd-group-access.pkla
[libvirtd group Management Access]
Identity=unix-group:libvirtd
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
#增加权限启动配置
[root@KVM02 webvirtmgr]# systemctl restart libvirtd supervisord
#重启服务
WebVirtMgr部署(webvirtmgr服务器(服务端)与kvm服务器(客服端)连接配置 )
webvirtmgr与kvm之间使用ssh方式连接管理
1> 在webvirtmgr服务器(服务端)上:
[root@KVM02 ~]# mkdir -p /home/nginx
[root@KVM02 ~]# chown nginx.nginx /home/nginx
[root@KVM02 ~]# chmod 700 -R /home/nginx/
[root@KVM02 ~]# su - nginx -s /bin/bash
-bash-4.2$ ssh-keygen -f ~/.ssh/id_rsa -N '' -q
-bash-4.2$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.2$ chmod 0600 ~/.ssh/config
webvirtmgr服务器(服务端)与kvm服务器(客服端)连接配置
方式一:webvirtmgr与kvm之间使用ssh方式连接管理
1、在kvm(客户端)服务器上配置webvirt用户
[root@KVM01 ~]# useradd -G libvirt webvirtmgr
[root@KVM01 ~]# echo "123456" | passwd --stdin webvirtmgr
更改用户 webvirtmgr 的密码 。
passwd:所有的身份验证令牌已经成功更新。
2、在webvirtmgr服务器(服务端)上,将ssh-key上传到kvm服务器上
[root@KVM02 ~]# su - nginx -s /bin/bash
-bash-4.2$ ssh-copy-id webvirtmgr@192.168.16.55
3、 在kvm(客户端)服务器上配置 libvirt ssh授权
[root@KVM01 ~]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
Identity=unix-user:webvirtmgr
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[root@KVM01 ~]# chown -R webvirtmgr.webvirtmgr /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
#修改文件的权限
[root@KVM01 ~]# systemctl restart libvirtd
重启 libvirtd 服务
方式二:webvirtmgr与kvm之间使用tcp方式连接管理
1、Libvirtd服务监听配置(kvm服务器)
修改/etc/sysconfig/libvirtd文件,去掉下面一行的注释,使Libvirt服务处于监听状态:
[root@KVM01 ~]# vim /etc/sysconfig/libvirtd
LIBVIRTD_ARGS="--listen"
2、配置Libvirt服务,允许通过tcp方式通讯
[root@KVM01 ~]# vim /etc/libvirt/libvirtd.conf
listen_tcp = 1 #允许tcp监听
tcp_port = "16509" #开放tcp端口
listen_addr = "0.0.0.0" #监听地址修改为0.0.0.0
auth_tcp ="sasl" #配置tcp通过sasl认证
listen_tls = 0 #取消CA认证功能
[root@KVM01 ~]# systemctl restart libvirtd
#重启服务
[root@KVM01 ~]# curl http://retspen.github.io/libvirt-bootstrap.sh | sudo sh
#下载并执行脚本:libvirt-bootstrap.sh,同时iptables放行相应的端口
3、创建libvirt管理用户
[root@KVM01 ~]# vim /etc/sasl2/libvirt.conf
mech_list: digest-md5 #注释原有行,修改为此
sasldb_path: /etc/libvirt/passwd.db #去掉该行注释
#需改配置文件
#注意:客户端如果不修改以上两行,创建用户不会生成
4、添加认证用户
[root@KVM01 ~]# saslpasswd2 -a libvirt admins
Password:
Again (for verification):
查看用户:
[root@KVM01 ~]# sasldblistusers2 -f /etc/libvirt/passwd.db
admins@kvm01: userPassword
删除用户:saslpasswd2 -a libvirt -d admins
测试webvirtmgr服务器(服务端)与kvm服务器(客服端)连接配置
服务器端ssh测试是否可以连接客户端
[root@KVM02 ~]# yum install libvirt-client
[root@KVM02 ~]# su - nginx -s /bin/bash
-bash-4.2$ virsh -c qemu+ssh://webvirtmgr@192.168.16.55/system nodeinfo
CPU 型号: x86_64
CPU: 4
CPU 频率: 2496 MHz
CPU socket: 2
每个 socket 的内核数: 2
每个内核的线程数: 1
NUMA 单元: 1
内存大小: 5945140 KiB
服务器端tcp测试是否可以链接客户端
[root@KVM02 ~]# yum install cyrus-sasl-md5 -y
[root@KVM02 ~]# su - nginx -s /bin/bash
-bash-4.2$ virsh -c qemu+tcp://192.168.16.55/system nodeinfo
Please enter your authentication name: admins
Please enter your password:
CPU 型号: x86_64
CPU: 4
CPU 频率: 2496 MHz
CPU socket: 2
每个 socket 的内核数: 2
每个内核的线程数: 1
NUMA 单元: 1
内存大小: 5945140 KiB