-
WebVirtMgr features
- Simple operation and easy to use
- Manage kvm through the API interface of libvirt
- Provides lifecycle management of virtual machines
- WebVirtMgr function
-
Host management supports the following functions
- CPU utilization
- Memory utilization
- Network resource pool management
- Storage resource pool management
- Virtual machine image
- Virtual machine clone
- Snapshot management
- Log management
- Virtual machine migration
-
Virtual machine management supports the following functions
- CPU utilization
- Memory utilization
- Disc management
- Turn off/on/pause the virtual machine
- Install virtual machine
- VNC console connection
- Create a snapshot
Start deployment
1. Basic environment
#配置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
#
Two, install WebVirtMgr
1. Install dependent packages
[root@didi ~]# yum install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx -y
2. Download the relevant webvirtmgr code from git-hub
[root@didi ~]# cd /usr/local/src/
[root@didi src]# git clone git://github.com/retspen/webvirtmgr.git
3. Install webvirtmgr
[root@didi src]# cd webvirtmgr/
[root@openstack webvirtmgr]# pip install -r requirements.txt
4. Check sqlite3 (Note: It does not need to be installed, import the module to check.)
[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. Initialize the account
[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. Copy the code to /var/www/
[root@didi ~]# mkdir -pv /var/www
[root@didi ~]# cp -Rv /usr/local/src/webvirtmgr /var/www/webvirtmgr
7. Add ssh without password
[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. Edit the nginx configuration file
Add include /etc/nginx/conf.d/*.conf in nginx.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. Add the /etc/nginx/conf.d/webvirtmgr.conf configuration file
[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. Document authorization
[root@didi ~]# chown -R nginx:nginx /var/www/webvirtmgr
11. Set up the supervisor (if the iptables firewall is enabled, port 80, 8000, 6080 must be opened for access)
[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. Set up the key-free of the nginx program account
解决措施:
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. Access address: http://192.168.18.254/login/
Account information admin/adminroot
add kvm virtual machine
After the configuration is complete, the virtual machine information will be displayed