linux

kvm虚拟化管理平台WebVirtMgr部署

发布时间:7年前热度: 3655 ℃评论数:

一、WebVirtMgr 说明

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

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

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

二、安装kvm虚拟环境

1、系统环境

CentOS Linux release 7.2.1511  selinx 关闭

2、安装依赖包

# yum -y install epel-release

# 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

#  ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvm

3、 配置网桥

# cd /etc/sysconfig/network-scripts/

# cp ifcfg-em1 ifcfg-br0

# cat ifcfg-em1

TYPE=Ethernet
BOOTPROTO=static
NAME=em1
DEVICE=em1
ONBOOT=yes
NM_CONTROLLED=no
BRIDGE=br0

# cat  ifcfg-br0

TYPE=Bridge
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NM_CONTROLLED=no
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.1.11
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114

# /etc/init.d/network restart

4、关闭虚拟网卡virtbr0

# virsh net-destroy default

# virsh net-undefine default

 

# systemctl restart libvirtd

三、安装WebVirtMg

1、安装依赖包

# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx python-sqlite2 novnc

2、下载WebVirtMgr

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

# 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: [email protected]
Password:*********
Password (again):*********

# ./manage.py collectstatic // 生成配置文件

3、配置WebVirtMgr启动

# vim /etc/supervisord.conf // 在文件末尾添加

[program:webvirtmgr]
command=/usr/bin/python /usr/share/nginx/html/webvirtmgr/manage.py run_gunicorn -c /usr/share/nginx/html/webvirtmgr/conf/gunicorn.conf.py // 启动8000端口
directory=/usr/share/nginx/html/webvirtmgr
autostart=true
autorestart=true
logfile=/var/log/supervisor/webvirtmgr.log
log_stderr=true
user=nginx

[program:webvirtmgr-console]
command=/usr/bin/python /usr/share/nginx/html/webvirtmgr/console/webvirtmgr-console  //启动 vnc 6080端口
directory=/usr/share/nginx/html/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=nginx

# systemctl restart supervisord && systemctl enable supervisord

4、拷贝web到nginx目录

# mv webvirtmgr  /usr/share/nginx/html/

# chown -R nginx:nginx /usr/share/nginx/html/* -R

5、配置nginx

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html/webvirtmgr;

root /usr/share/nginx/html/webvirtmgr;

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

location /static/ {
root /usr/share/nginx/html/webvirtmgr;
expires max;
}

}

# systemctl start nginx && systemctl enable nginx

6、配置ssh密钥

# ssh-keygen -t rsa // 生成公钥

# ssh-copy-id 192.168.1.11

7、访问WebVirtMg

29.png

8、配置libvirtd远程TCP 连接

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.service

9、添加主机

30.png

手机扫码访问