KVM之web管理工具webvirtmgr安装

KVM之web管理工具webvirtmgr安装

由于一直使用命令行对kvm虚拟机进行管理,虽然某些操作很快捷,但是有新同事对kvm不熟悉的时候就需要一个界面管理工具来对kvm虚拟机进行操作了,webvirtmgr是一个aliyun平台的超级简化版界面管理工具,基于python编程、数据库由sqlite3提供支持对kvm进行管理,支持通过tcp、ssh、TLS、socket等方式对kvm服务器进行连接管理。界面也是极为简洁,很适合轻量化管理。

webvirtmgr安装

依赖组件安装

由于webvirtmgr基于python编程所以需要安装相关的python模块:python-pip libvirt-python python-websockify libxml2-python supervisor Nginx novnc

pip : python 模块、包管理工具
libvirt-python: libvirt的python接口
supervisor : python 专用的后台进程管理工具,它可以让python程序变为后台daemon,
             并监控其进程状态,异常退出时可以自动重启
nginx:反向代理,让我们通过nginx来访问webvirtmgr
novnc:由于webvirtmgr使用了novnc提供网页版的VNC功能,所以需要安装novnc。

由于这些安装包有的在自带的yum源中没有,所以使用epel源,进行安装。在这里使用阿里云的epel源进行安装

#安装epel源
#CentOS7/RHEL7
wget -O /etc/yum.repos.d/epel-aliyun.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

#CentOS6/RHEL6
wget -O /etc/yum.repos.d/epel-aliyun.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum makecache

#安装所需组件
yum -y install novnc python-pip libvirt-python libxml2-python python-websockify supervisor nginx git

下载webvirtmgr

webvirtmgr的安装包可以从github获取,https://github.com/retspen/webvirtmgr ,获取方法如下:

#创建web目录用于存放webvirtmgr
mkdir /web    
git clone https://github.com/retspen/webvirtmgr.git
cd /web/webvirtmgr
pip install -r requirements.txt

初始化Django环境

[root@node40 ~]# cd /web/webvirtmgr/
[root@node40 webvirtmgr]# ./manage.py syncdb
WARNING:root:No local_settings file found.
Creating tables ...
Creating table auth_permission
...
Creating table create_flavor

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    # 这里输入Django认证系统的超级管理员
Email address: yunwei@daqsoft.com   
Password:                # 输入密码
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)
[root@node40 webvirtmgr]# ./manage.py collectstatic
WARNING:root:No local_settings file found.

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Copying '/data/webvirtmgr/webvirtmgr/static/js/infrastructure.js'
Copying '/data/webvirtmgr/webvirtmgr/static/js/bootstrap-multiselect.js'
......
Copying '/data/webvirtmgr/webvirtmgr/static/img/favicon.ico'
Copying '/data/webvirtmgr/webvirtmgr/static/img/desc.gif'
Copying '/data/webvirtmgr/webvirtmgr/static/img/asc.gif'

75 static files copied.    
[root@node40 webvirtmgr]# chown -R nginx.nginx /web

配置supervisor,使webvirtmgr和webvirtmgr-console以daemon方式运行。

[root@node40 webvirtmgr]# cp /etc/supervisord.conf{,_bak}
# supervisor 在CentOS6中配置时编辑配置文件/etc/supervisord.conf
[root@node40 webvirtmgr]# cat << EOF >> /etc/supervisord.conf
[program:webvirtmgr]
command=/usr/bin/python /data/webvirtmgr/manage.py run_gunicorn -c /data/webvirtmgr/conf/gunicorn.conf.py
directory=/data/webvirtmgr
autostart=true
autorestart=true
logfile=/var/log/supervisor/webvirtmgr.log
log_stderr=true
user=webvirtmgr

[program:webvirtmgr-console]
command=/usr/bin/python /data/webvirtmgr/console/webvirtmgr-console
directory=/data/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=webvirtmgr
EOF

# 添加supervisord到自启动,并启动服务
chkconfig  supervisord on
service supervisord start
#检查是否启动成功
ps -ef | grep webvirtmgr
ss -anlt | egrep --color "(8000|6080)"

配置nginx代理webvirtmgr

[root@node40 webvirtmgr]# vim /etc/nginx/conf.d/webvirtmgr.conf
server {
    listen 80 ;
    server_name kvm.daqsoft.com;
    access_log /var/log/nginx/access_webvirtmgr.log;

    location /static/ {
        root /data/webvirtmgr;
        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;
    }
}

[root@node40 webvirtmgr]# mv /etc/nginx/conf.d/default.conf{,_bak}
[root@node40 webvirtmgr]# chkconfig nginx on
[root@node40 webvirtmgr]# service nginx start

安装完成,访问webvirtmgr

虽然这里已经配置完成,但是需要对libvirtd服务进行配置,才能在webvirtmgr中对kvm服务器进行远程管理

安装完成

配置kvm服务器

由于kvm服务器与webvirtmgr是分离部署,所以现在要对kvm服务器进行配置,如果有多台KVM服务器配置方法一样。

webvirtmgr连接KVM虚拟机常用的方式是:tcp和ssh 两种,socket方式适用于连接webvirtmgr本地kvm服务器;在此以TCP访问方式配置进行介绍。

  1. 设置libvirtd服务以tcp监听模式进行启动;配置文件:/etc/sysconfig/libvirtd
    在kvm服务器上找到 /etc/sysconfig/libvirtd ,去掉其中LIBVIRTD_ARGS及LIBVIRTD_CONFIG前的注释符号(#)。

     cp /etc/sysconfig/libvirtd{,_bak}
     sed -i -e "s/^#\(LIBVIRTD_ARGS\)/\1/" -e "s/^#\(LIBVIRTD_CONFIG\)/\1/" /etc/sysconfig/libvirtd
    
  2. 配置libvirtd服务监听参数;配置文件:/etc/libvirt/libvirtd.conf
    需要修改的配置参数:

        cp /etc/libvirt/libvirtd.conf{,_bak}
        vim /etc/libvirt/libvirtd.conf
        listen_tcp=1           # 允许进行tcp监听
        tcp_port="16509"       # 服务端口
        listen_addr="0.0.0.0"  # socket监听时采用的IP,在此为在所有IP地址上进行监听,
                               # 建议只配置到服务器的管理接口所在IP上进行监听
        auth_tcp=sasl          # 使用sasl进行认证
        listen_tls=0           # 不使用tls进行监听,在不使用CA进行认证时一定要启该配置
  1. 设置认证用户密码,启动服务

     saslpasswd2 -a libvirt admin
     chkconfig libvirtd on
     service libvirtd start
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,560评论 4 361
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,104评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,297评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,869评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,275评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,563评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,833评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,543评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,245评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,512评论 2 244
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,011评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,359评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,006评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,062评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,825评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,590评论 2 273
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,501评论 2 268

推荐阅读更多精彩内容