生產環境的KVM宿主機越來越多,需要對宿主機的狀態進行調控。這里用webvirtmgr進行管理。圖形化的WEB,讓人能更方便的查看kvm 宿主機的情況和操作
1 安裝支持的軟件源
yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
2 安裝相關軟件
yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx
3 從git-hub中下載相關的webvirtmgr代碼
cd /usr/local/src/
git clone git://github.com/retspen/webvirtmgr.git
4 安裝webvirtmgr
cd webvirtmgr/
pip install -r requirements.txt
5 安裝數據庫
yum install python-sqlite2
6 對django進行環境配置
./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: 2733176200@qq.com
Password:*********
Password (again):*********
./manage.py collectstatic #生成配置文件
./manage.py createsuperuser #添加管理員賬號
7 拷貝web到 相關目錄
cd ..
mkdir -pv /var/www
cp -Rv webvirtmgr /var/www/webvirtmgr
8 設置ssh
ssh-keygen
ssh-copy-id 192.168.2.32
ssh 192.168.2.32 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:6080
9 編輯nginx配置文件
vim /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 /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; # Set higher depending on your needs
}
}
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
10 啟動nginx
/etc/init.d/nginx restart
11 修改防火牆規則
/usr/sbin/setsebool httpd_can_network_connect true
12 設置 supervisor
chown -R nginx:nginx /var/www/webvirtmgr
vim /etc/supervisord.conf #在文件末尾添加
[program:webvirtmgr]
command=/usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
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/python /var/www/webvirtmgr/console/webvirtmgr-console
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=nginx
修改/var/www/webvirtmgr/conf/gunicorn.conf.py
bind = "0:8000"
13 設置開機啟動
chkconfig supervisord on
vim /etc/rc.local
/usr/sbin/setsebool httpd_can_network_connect true
14 啟動進程
/etc/init.d/supervisord restart
15查看進程
netstat -lnpt 即可以看到6080和8000已經啟動
16 web訪問
http://192.168.0.194/login/
