文章目录
WebVirtMgr简介
采用几乎纯Python开发,其前端是基于Python的Django,后端是基于Libvirt的Python接口,将日常kvm的管理操作变的更加的可视化。
WebVirtMgr运行原理:
通过libvirt的API接口对kvm进行管理,提供对虚拟机生命周期管理
WebVirtMgr 功能
#宿主机管理支持以下功能
CPU利用率,内存利用率,网络资源池管理,存储资源池管理,虚拟机镜像,虚拟机克隆,快照管理,日志管理,虚机迁移
#虚拟机管理支持以下功能
CPU利用率,内存利用率,光盘管理,关/开/暂停虚拟,安装虚拟机,VNC console连接,创建快照
系统环境:
CentOS Linux release 7.3.1611 (Core),以及kvm虚拟化套件
安装webvirtmgr
#第一:安装所需软件
yum -y install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
#注意这一步后面的版本号可能会随着时间的推移而改变,正确的方法是,分析上面的url,找到特点,最后进入到网页里,找到对应的epel-release包
#这一步其实就是yum install epel*
yum -y install gcc python-devel
yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx
#第二:(若是提升pip版本升级,可以选择)升级pip
pip install --upgrade pip
#第三:创建一个目录用于临时存放下载的webvirtmgr代码
mkdir /kvm-webmanager
cd /kvm-webmanager
#第四:下载webvirtmgr.git软件
git clone git://github.com/retspen/webvirtmgr.git
#第五:使用pip安装django #(进入到webvirtmgr目录,然后再安装)
cd /kvm-webmanager/webvirtmgr
pip install -r requirements.txt
./manage.py syncdb #中途会让你创建一个账户,这是用于登录webvirtmgr的,当然下面也可以创建
./manage.py collectstatic #配置数据库的账户(生成配置文件)
./manage.py createsuperuser #创建一个用于登录webvirtmgr的账户
#第六:将webvirtmgr目录移到nginx的web目录下
mv /kvm-webmanager/webvirtmgr /usr/share/nginx/html/
#第七:配置nginx
vim /etc/nginx/conf.d/webvirtmgr.conf #创建一个nginx的webvirtmgr配置文件,内容如下
server {
listen 80 default_server;
server_name $hostname;
#access_log /var/log/nginx/webvirtmgr_access_log;
location /static/ {
root /usr/share/nginx/html/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
}
}
#第八:让nginx读取刚才创建的文件webvirtmgr.conf
vim /etc/nginx/nginx.conf #编辑nginx的主配置文件,让其加载conf.d下的文件,内容如下
include /etc/nginx/conf.d/*.conf;
#第九:测试nginx的配置文件有无错误
nginx -t
nginx -t -c /etc/nginx/conf.d/webvirtmgr.conf
#第十:将目录的权限赋予nginx用户(若是不做这部,可能会导致无法启动8000和6080端口)
chown nginx:nginx /usr/share/nginx/html -R
#第十一:配置 Supervisor (注意路径)
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端口,若是ubuntu环境,可能要将/usr/bin/python改成/usr/bin/python2(使用时去掉本行注释)
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
#这是启动6080端口,(使用时去掉本行注释)
directory=/usr/share/nginx/html/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=nginx
#第十二:关闭selinux
#第十三:启动Supervisor
systemctl restart supervisord
#第十四:启动相关服务,及加入开机自起
systemctl start supervisord
systemctl start nginx
systemctl enable supervisord
systemctl enable nginx
#第十五:在浏览器输入ip后面接8000端口就可以登录了
http://192.168.1.1:8000
若是不成功,可以手动执行/usr/share/nginx/html/webvirtmgr/manage.py run_gunicorn -c /usr/share/nginx/html/webvirtmgr/conf/gunicorn.conf.py
配置KVM能够被webvirtmgr管理
(其连接方式有基于TCP,ssh,TLS等,这里介绍前面两种)
配置tcp相连接
#第一:修改配置(在kvm机器上)
vim /etc/sysconfig/libvirtd #修改去掉下面行的注释
LIBVIRTD_ARGS="--listen"
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认证,若是后期发现无法创建存储池,可以改成none
listen_tls = 0 #取消CA认证功能
#第二:创建libvirt管理用户(用于sasl认证的账户及密码)
saslpasswd2 -a libvirt admin
#第三:重新启动服务:
systemctl restart libvirtd
配置ssh相连接
#第一:在webvirtmgr服务器(服务端)上:
cd /home/
mkdir nginx
chown nginx.nginx nginx/
chmod 700 nginx/ -R
su - nginx -s /bin/bash
ssh-keygen #---期间输入yes后直接回车,回车
touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
chmod 0600 ~/.ssh/config
#第二:在kvm(客服端)服务器上配置webvirt用户
useradd webvirtmgr
echo "123456" | passwd --stdin webvirtmgr
groupadd libvirt
usermod -G libvirt -a webvirtmgr
#第三:在webvirtmgr服务器(服务端)上,将ssh-key上传到kvm服务器上
su - nginx -s /bin/bash
ssh-copy-id webvirtmgr@192.168.1.1
#第四:在kvm(客服端)服务器上配置 libvirt ssh授权
vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:webvirtmgr
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
chown -R webvirtmgr.webvirtmgr /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
#第五:重启 libvirtd 服务
systemctl restart libvirtd
如果文章对你有帮助,欢迎点击上方按钮打赏作者
暂无评论