生产环境的KVM宿主机越来越多,需要对宿主机的状态进行调控。这里用webvirtmgr进行管理。图形化的WEB,让人能更方便的查看kvm 宿主机的情况和操作.

GitHub Project.

Install

安装支持的软件源

  1. yum install -y epel-release

安装相关软件

  1. yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx

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

  1. cd /usr/local/src/
  2. git clone git://github.com/retspen/webvirtmgr.git

安装webvirtmgr

  1. cd webvirtmgr/
  2. pip install -r requirements.txt

安装数据库

  1. yum install python-sqlite2

对django进行环境配置

  1. ./manage.py syncdb
  2. You just installed Django's auth system, which means you don't have any superusers defined.
  3. Would you like to create one now? (yes/no): yes
  4. Username (leave blank to use 'root'): admin
  5. Email address: luchuanjia@msn.com
  6. Password:*********
  7. Password (again):*********
  8. ./manage.py collectstatic #生成配置文件
  9. ./manage.py createsuperuser #添加管理员账号

拷贝web到 相关目录

  1. cd ..
  2. rm -rf /var/www
  3. mkdir -pv /var/www
  4. cp -Rv webvirtmgr /var/www/webvirtmgr

设置ssh

  1. ssh-keygen
  2. ssh-copy-id 192.168.2.32
  3. ssh 192.168.2.32 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080

编辑nginx配置文件

  1. mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
  2. vim /etc/nginx/conf.d/webvirtmgr.conf #添加下面内容到文件中
  3. server {
  4. listen 80 default_server;
  5. server_name $hostname;
  6. #access_log /var/log/nginx/webvirtmgr_access_log;
  7. location /static/ {
  8. root /var/www/webvirtmgr/webvirtmgr; # or /srv instead of /var
  9. expires max;
  10. }
  11. location / {
  12. proxy_pass http://127.0.0.1:8000;
  13. proxy_set_header X-Real-IP $remote_addr;
  14. proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
  15. proxy_set_header Host $host:$server_port;
  16. proxy_set_header X-Forwarded-Proto $remote_addr;
  17. proxy_connect_timeout 600;
  18. proxy_read_timeout 600;
  19. proxy_send_timeout 600;
  20. client_max_body_size 1024M; # Set higher depending on your needs
  21. }
  22. }

启动nginx

  1. service nginx start

修改防火墙规则 ( 如果关闭selinux,此步可省略)

  1. /usr/sbin/setsebool httpd_can_network_connect true

设置 supervisor

  1. chown -R nginx:nginx /var/www/webvirtmgr
  2. vim /etc/supervisord.conf #在文件末尾添加
  3. [program:webvirtmgr]
  4. command=/usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
  5. directory=/var/www/webvirtmgr
  6. autostart=true
  7. autorestart=true
  8. logfile=/var/log/supervisor/webvirtmgr.log
  9. log_stderr=true
  10. user=nginx
  11. [program:webvirtmgr-console]
  12. command=/usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-console
  13. directory=/var/www/webvirtmgr
  14. autostart=true
  15. autorestart=true
  16. stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
  17. redirect_stderr=true
  18. user=nginx
  19. 修改/var/www/webvirtmgr/conf/gunicorn.conf.py
  20. bind = "0:8000"

设置开机启动

  1. chkconfig supervisord on
  2. chkconfig nginx on
  3. vim /etc/rc.local
  4. /usr/sbin/setsebool httpd_can_network_connect true

启动进程

  1. service nginx start
  2. service supervisord start

访问

  1. http://$server_ip/login/