2. kvm虚拟化管理平台WebVirtMgr部署

  • WebVirtMgr特点

    • 操作简单,易于使用
    • 通过libvirt的API接口对kvm进行管理
    • 提供对虚拟机生命周期管理
    • WebVirtMgr 功能
  • 宿主机管理支持以下功能

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

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

开始部署

一、基础环境

#配置yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release
#kvm虚拟化环境
[root@didi ~]# rpm -qa virt*
virt-what-1.18-4.el7.x86_64
virt-manager-common-1.5.0-7.el7.noarch
virt-manager-1.5.0-7.el7.noarch
virt-install-1.5.0-7.el7.noarch
#关闭防火墙SELinux
systemctl stop firewalld && systemctl disable firewalld
#

二、安装WebVirtMgr

1、安装依赖包

[root@didi ~]# yum install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx -y

2、从git-hub中下载相关的webvirtmgr代码

[root@didi ~]# cd /usr/local/src/
[root@didi src]# git clone git://github.com/retspen/webvirtmgr.git

3、安装webvirtmgr

[root@didi src]# cd webvirtmgr/
[root@openstack webvirtmgr]# pip install -r requirements.txt

4、检查sqlite3 (备注:自带不需要安装,导入模块检查一下。)

[root@didi webvirtmgr]# python
Python 2.7.5 (default, Nov 20 2015, 02:00:19) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> exit()   

5、初始化账号

[root@didi ~]# cd /usr/local/src/webvirtmgr
[root@didi webvirtmgr]#  ./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: 
Password: 
Password (again): 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)

6、拷贝代码到/var/www/下

[root@didi ~]# mkdir -pv /var/www
[root@didi ~]# cp -Rv /usr/local/src/webvirtmgr /var/www/webvirtmgr

7、添加ssh免密

[root@didi ~]# ssh-keygen -t rsa             //产生公私钥
[root@didi ~]# ssh-copy-id 192.168.18.254       //由于这里webvirtmgr和kvm服务部署在同一台机器,所以这里本地信任。如果kvm部署在其他机器,那么这个是它的ip
[root@didi ~]# ssh 192.168.18.254 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60

8、编辑nginx配置文件

在nginx.conf中添加include /etc/nginx/conf.d/*.conf;

[root@didi ~]# cd /etc/nginx/
[root@didi nginx]# mv nginx.conf /tmp
[root@didi nginx]# cp nginx.conf.default nginx.conf
[root@didi nginx]# sed -ri '/default_type/ainclude /etc/nginx/conf.d/*.conf;'

9、添加/etc/nginx/conf.d/webvirtmgr.conf配置文件

[root@didi nginx]# vim /etc/nginx/conf.d/webvirtmgr.conf  
server {
    
    
    listen 8889 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; 
}
}

# 重启nginx服务
[root@didi ~]# systemctl restart nginx && systemctl enable nginx

10、文件授权

[root@didi ~]#  chown -R nginx:nginx /var/www/webvirtmgr

11、设置 supervisor (如果iptables防火墙开启的话,就必须要开通80、8000、6080端口访问)

[root@didi ~]# vim /etc/supervisord.conf     //在文件末尾添加,注意将默认的python改为python2,因为上面只有用这个版本执行才不报错!
[program:webvirtmgr]
command=/usr/bin/python2 /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/python2 /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

#检查
[root@didi ~]# vim /var/www/webvirtmgr/conf/gunicorn.conf.py    //确保下面bind绑定的是本机的8000端口,这个在nginx配置中定义了,被代理的端口
bind = '127.0.0.1:8000'

#设置开机启动
[root@didi nginx]# systemctl enable supervisord.service

#设置开机加载
[root@didi nginx]#vim /etc/rc.local /usr/sbin/setsebool httpd_can_network_connect true

#重启服务
[root@didi nginx]# systemctl restart supervisord && systemctl enable supervisord
[root@didi nginx]# systemctl status supervisord

#查看端口  检查6080和8000是否启动
[root@didi nginx]# netstat -lnpt

11、设置nginx程序账户的免密钥

解决措施:
1)在webvirtmgr服务器(服务端)上(这里kvm和WebVirtMgr部署在同一台机器上)创建nginx用户家目录(默认nginx服务安装时是没有nginx家目录的),生成nginx的公私钥
[root@didi]# cd /home/
[root@didi home]# mkdir nginx
[root@didi home]# chown nginx.nginx nginx/
[root@didi home]# chmod 700 nginx/ -R
[root@tdidi home]# su - nginx -s /bin/bash
-bash-4.1$ ssh-keygen                             #期间输入yes后直接回车,回车
-bash-4.1$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.1$ chmod 0600 ~/.ssh/config
#在webvirtmgr服务器(服务端)上(这里kvm和WebVirtMgr部署在同一台机器上),将nginx用户的ssh-key上传到kvm服务器上(这里kvm和WebVirtMgr部署在同一台机器上)

[root@didi ~]# su - nginx -s /bin/bash
-bash-4.1$ ssh-copy-id [email protected]
Warning: Permanently added '192.168.18.254' (RSA) to the list of known hosts.
[email protected]'s password: 
Now try logging into the machine, with "ssh '[email protected]'", and check in:
.ssh/authorized_keys
#在kvm(客服端)服务器上(这里kvm和WebVirtMgr部署在同一台机器上)配置 libvirt ssh授权

[root@didi ~]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:root #注意这里采用的是root用户
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes

[root@didi ]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
#重启服务

[root@didi ]# systemctl restart nginx
[root@didi ]# systemctl restart libvirtd

12、访问地址:http://192.168.18.254/login/

账户信息 admin/adminroot
在这里插入图片描述
添加kvm虚拟机
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sgvSBcv2-1617199585542)(./210331-214342.png)]

配置完成后就会显示虚拟机信息
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-JWVX4I3l-1617199585549)(./210331-215120.png)]

猜你喜欢

转载自blog.csdn.net/weixin_43357497/article/details/115362464