生产环境的KVM宿主机越来越多,需要对宿主机的状态进行调控。这里用webvirtmgr进行管理。图形化的WEB,让人能更方便的查看kvm 宿主机的情况和操作.
Install
安装支持的软件源
yum install -y epel-release
安装相关软件
yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx
从git-hub中下载相关的webvirtmgr代码
cd /usr/local/src/git clone git://github.com/retspen/webvirtmgr.git
安装webvirtmgr
cd webvirtmgr/pip install -r requirements.txt
安装数据库
yum install python-sqlite2
对django进行环境配置
./manage.py syncdbYou just installed Django's auth system, which means you don't have any superusers defined.Would you like to create one now? (yes/no): yesUsername (leave blank to use 'root'): adminEmail address: luchuanjia@msn.comPassword:*********Password (again):*********./manage.py collectstatic #生成配置文件./manage.py createsuperuser #添加管理员账号
拷贝web到 相关目录
cd ..rm -rf /var/wwwmkdir -pv /var/wwwcp -Rv webvirtmgr /var/www/webvirtmgr
设置ssh
ssh-keygenssh-copy-id 192.168.2.32ssh 192.168.2.32 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080
编辑nginx配置文件
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bakvim /etc/nginx/conf.d/webvirtmgr.conf #添加下面内容到文件中server {listen 80 default_server;server_name $hostname;#access_log /var/log/nginx/webvirtmgr_access_log;location /static/ {root /var/www/webvirtmgr/webvirtmgr; # or /srv instead of /varexpires 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; # Set higher depending on your needs}}
启动nginx
service nginx start
修改防火墙规则 ( 如果关闭selinux,此步可省略)
/usr/sbin/setsebool httpd_can_network_connect true
设置 supervisor
chown -R nginx:nginx /var/www/webvirtmgrvim /etc/supervisord.conf #在文件末尾添加[program:webvirtmgr]command=/usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.pydirectory=/var/www/webvirtmgrautostart=trueautorestart=truelogfile=/var/log/supervisor/webvirtmgr.loglog_stderr=trueuser=nginx[program:webvirtmgr-console]command=/usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-consoledirectory=/var/www/webvirtmgrautostart=trueautorestart=truestdout_logfile=/var/log/supervisor/webvirtmgr-console.logredirect_stderr=trueuser=nginx修改/var/www/webvirtmgr/conf/gunicorn.conf.pybind = "0:8000"
设置开机启动
chkconfig supervisord onchkconfig nginx onvim /etc/rc.local/usr/sbin/setsebool httpd_can_network_connect true
启动进程
service nginx startservice supervisord start
访问
http://$server_ip/login/
