小规模kvm宿主机管理-webvirtmgr安装

1、前言
WebVirtMgr是近两年来发展较快,比较活跃,非常清新的一个KVM管理平台,提供对宿主机和虚机的统一管理,它有别于kvm自带的图形管理工具(virtual machine manager),
让kvm管理变得更为可视化,对中小型kvm应用场景带来了更多方便。
WebVirtMgr采用几乎纯Python开发,其前端是基于Python的Django,后端是基于Libvirt的Python接口,将日常kvm的管理操作变的更加的可视化

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

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

虚拟机管理支持以下功能
CPU利用率
内存利用率
光盘管理
关/开/暂停虚拟机
安装虚拟机
VNC console连接
创建快照

4、 WebVirtMgr的使用范围
针对小规模物理主机的上虚机管理(十几台左右)


5、kvm 安装
关闭selinux,重启后生效

关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
安装kvm软件包
yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install virt-manager python-virtinst libvirt-client virt-viewer 
systemctl enable libvirtd && systemctl start libvirtd

6、安装WebVirtMgr
1)安装相关软件
yum -y install epel-release
yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx 
2)从git-hub中下载webvirtmgr代码
cd /usr/local/src/
git clone git://github.com/retspen/webvirtmgr.git 
3)安装webvirtmgr
cd webvirtmgr/
pip install -r requirements.txt
4)安装数据库
yum install python-sqlite2 //默认情况下,centos系统一般会自带sqlite软件(执行sqlite3 命令,不报错就说明已经安装了)
5)对django进行环境配置
cd /usr/local/src/webvirtmgr
./manage.py syncdb //默认是python执行,如下报错,换用其他版本的python
./manage.py collectstatic //生成配置文件
./manage.py createsuperuser //添加管理员账号

6)拷贝web到 相关目录
mkdir -pv /var/www
cp -Rv /usr/local/src/webvirtmgr /var/www/webvirtmgr
7)在/etc/nginx/conf.d目录下添加webvirtmgr.conf文件:
提前确保/etc/nginx/nginx.conf文件里开启了“include /etc/nginx/conf.d/*.conf;”
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
}
}

把/etc/nginx/nginx.conf文件中,默认的server信息,注释掉
8)设置 supervisor
chown -R nginx:nginx /var/www/webvirtmgr
vim /etc/supervisord.conf
[program:webvirtmgr]
command=/usr/bin/python /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/python /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

systemctl enable supervisord
systemctl restart supervisord

9)权限设置,也是设置Local登录的一种方式
增加权限组
groupadd libvirtd
增加用户到权限组
usermod -a -G libvirtd root
usermod -a -G libvirtd nginx
设置kvm服务libvirtd启动权限
vi /etc/libvirt/libvirtd.conf
unix_sock_group="libvirtd"

7、配置KVM宿主机
下载并执行脚本:libvirt-bootstrap.sh,如果虚拟机比较多,该脚本执行时间会比较长
curl http://retspen.github.io/libvirt-bootstrap.sh | sh
systemctl restart messagebus
systemctl restart libvirtd

8、配置tcp连接libvirtd
1)修改文件/etc/sysconfig/libvirtd,用来启用tcp的端口
cat /etc/sysconfig/libvirtd

LIBVIRTD_CONFIG=/etc/libvirt/libvirtd.conf
LIBVIRTD_ARGS="--listen"

2)修改文件/etc/libvirt/libvirtd.conf
vim /etc/libvirt/libvirtd.conf
listen_tls = 0
listen_tcp = 1
tcp_port = "16509"
listen_addr = "0.0.0.0"
auth_tcp = "none"

3)运行 libvirtd
systemctl restart libvirtd

4)查看运行进程
ps aux | grep libvirtd
root 16563 1.5 0.1 925880 7056 ? Sl 16:01 0:28 libvirtd -d -l --config /etc/libvirt/libvirtd.conf

5)查看端口
lsof -i:16509

6)在source host连接dest host远程libvirtd查看信息(也可以用公网ip)
virsh -c qemu+tcp://192.168.1.17/system
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh #

9、登录web
http://${webvirtmgr_host_ip}/login 账号密码就是安装webvirtmgr时,设置的密码和账号

参考文章:

https://www.cnblogs.com/EasonJim/p/9592751.html

原文地址:https://www.cnblogs.com/potato-chip/p/10515392.html