Webvirtmgr-Server端安装

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连接
  • 创建快照

Server安装

1. Centos6

1
2
$ sudo yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
$ sudo yum -y install git python-pip libvirt-python libxml2-python python-websockify nginx

自带的官方pip源较慢,推荐阿里的pip源
mirrors.aliyun.com/help/pypi/
这里我们使用pip安装supervisor,因为yum安装的版本太低了
具体的安装过程请移步
http://www.vincentblog.cn/%2FLinux%E5%90%8E%E5%8F%B0%E8%BF%9B%E7%A8%8B%E7%AE%A1%E7%90%86-Supervisor.html

2. 安装python依赖并设置Django环境

运行

1
2
3
4
5
$ git clone git://github.com/retspen/webvirtmgr.git
$ cd webvirtmgr
$ sudo pip install -r requirements.txt # or python-pip (RedHat, Fedora, CentOS, OpenSuse)
$ ./manage.py syncdb
$ ./manage.py collectstatic

如果git clone 比较慢去github推荐Donwload zip包下来解压

https://github.com/retspen/webvirtmgr/archive/master.zip

输入用户信息

1
2
3
4
5
6
7
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 (Put: yes)
Username (Leave blank to use 'admin'): admin (Put: your username or login)
E-mail address: username@domain.local (Put: your email)
Password: xxxxxx (Put: your password)
Password (again): xxxxxx (Put: confirm password)
Superuser created successfully.

创建超级用户

1
$ ./manage.py createsuperuser

3. nginx配置

1
2
3
$ cd ..
$ sudo mv webvirtmgr /var/www/ ( CentOS, RedHat, Fedora, Ubuntu )
$ sudo mv webvirtmgr /srv/www/ ( OpenSuSe )

添加webvirtmgr.conf到/etc/nginx/conf.d目录下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
}
}
1
$ sudo vim /etc/nginx/nginx.conf

注释掉Server段示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#    server {
# listen 80 default_server;
# server_name localhost;
# root /usr/share/nginx/html;
#
# #charset koi8-r;
#
# #access_log /var/log/nginx/host.access.log main;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# # redirect server error pages to the static page /40x.html
# #
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# # redirect server error pages to the static page /50x.html
# #
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }

删除默认配置虚拟主机

1
$ sudo rm -rf /etc/nginx/conf.d/default.conf

启动nginx

1
2
sudo service nginx start
chkconfig nginx --level 345 on

4. Supervisor配置

1
$ sudo chown -R nginx:nginx /var/www/webvirtmgr

创建文件

1
2


[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

1
2

重启supervisor

$ sudo service supervisord stop
$ sudo service supervisord start

1
2
3

## 访问
在浏览器输入

http://x.x.x.x
`

参考

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

坚持原创技术分享,您的支持将鼓励我继续创作!