首頁 > 軟體

CentOS 7.2下KVM虛擬化管理平台WebVirtMgr部署

2020-06-16 17:21:51

WebVirtMgr採用幾乎純Python開發,其前端是基於Python的Django,後端是基於Libvirt的Python介面,將日常kvm的管理操作變的更加的視覺化。

WebVirtMgr特點:
操作簡單,易於使用
通過libvirt的API介面對kvm進行管理
提供對虛擬機器生命週期管理
WebVirtMgr 功能

宿主機管理支援以下功能
CPU利用率
記憶體利用率
網路資源池管理
儲存資源池管理
虛擬機器映象
虛擬機器克隆
快照管理
紀錄檔管理
虛機遷移

虛擬機器管理支援以下功能
CPU利用率
記憶體利用率
光碟管理
關/開/暫停虛擬機器
安裝虛擬機器
VNC console連線
建立快照

系統環境:
CentOS Linux release 7.2.1511 (Core)

1、yum源的設定及安裝所需軟體包

yum -y install http://dl.Fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
yum -y install Git Python-pip libvirt-python libxml2-python python-websockify supervisor nginx
yum -y install gcc python-devel
pip install numpy   

2、下載webvirtmgr.git軟體
mkdir /application/
cd /application/
git clone git://github.com/retspen/webvirtmgr.git 
git clone https://github.com/retspen/webvirtmgr.git                                   
 
3、資料庫安裝
cd /application/
wget http://www.sqlite.org/sqlite-3.5.6.tar.gz
cd sqlite-3.5.6/
./configure --disable-tcl 
make
make install

4、webvirtmgr安裝
cd /application/webvirtmgr
pip install -r requirements.txt
-----------------------------------------------------------------------------------------------------
./manage.py syncdb 
WARNING:root:No local_settings file found.
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table servers_compute
Creating table instance_instance
Creating table create_flavor

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: 10880347@qq.com
Password: 123456
Password (again): 123456
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)
--------------------------------------------------------------------------------------------------------                                                                 
./manage.py collectstatic

WARNING:root:No local_settings file found.

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Copying '/application/webvirtmgr/webvirtmgr/static/css/bootstrap-multiselect.css'
Copying '/application/webvirtmgr/webvirtmgr/static/css/bootstrap.min.css'
Copying '/application/webvirtmgr/webvirtmgr/static/css/signin.css'
Copying '/application/webvirtmgr/webvirtmgr/static/css/table-sort.css'
Copying '/application/webvirtmgr/webvirtmgr/static/css/webvirtmgr.css'
Copying '/application/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.eot'
Copying '/application/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.svg'
Copying '/application/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.ttf'
Copying '/application/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.woff'
Copying '/application/webvirtmgr/webvirtmgr/static/img/asc.gif'
Copying '/application/webvirtmgr/webvirtmgr/static/img/bg.gif'
Copying '/application/webvirtmgr/webvirtmgr/static/img/desc.gif'
Copying '/application/webvirtmgr/webvirtmgr/static/img/favicon.ico'
Copying '/application/webvirtmgr/webvirtmgr/static/js/Chart.min.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/bootstrap-multiselect.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/bootstrap.min.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/infrastructure.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/jQuery-1.10.2.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/jquery-migrate-1.2.1.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/jquery.tablesorter.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/Orbitron700.ttf'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/Orbitron700.woff'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/base.css'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/base64.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/black.css'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/blue.css'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/des.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/display.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/input.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/jsunzip.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/logo.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/playback.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/rfb.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/ui.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/util.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/websock.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/webutil.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/chrome-app/tcp-client.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/web-socket-js/README.txt'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/web-socket-js/WebSocketMain.swf'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/web-socket-js/swfobject.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/novnc/web-socket-js/web_socket.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-HTML5/atKeynames.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-Html5/bitmap.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/cursor.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/display.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/enums.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/filexfer.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/inputs.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/jsbn.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/lz.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/main.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/playback.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/png.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/prng4.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/quic.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/resize.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/rng.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/rsa.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/sha1.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/simulatecursor.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/spicearraybuffer.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/spiceconn.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/spicedataview.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/spicemsg.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/spicetype.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/ticket.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/utils.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/webm.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/wire.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/jsbn.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/prng4.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/rng.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/rsa.js'
Copying '/application/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/sha1.js'

75 static files copied.
-------------------------------------------------------------------------------------------------------------
./manage.py createsuperuser 
WARNING:root:No local_settings file found.
Username (leave blank to use 'root'): mgruser
Email address: 10880347@qq.com
Password: 123456
Password (again): 123456
Superuser created successfully.
---------------------------------------------------------------------------------------------------------------
5、webvirtmgr設定
mkdir -pv /var/www
cp -Rv /application/webvirtmgr /var/www/webvirtmgr

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
}
}

chown -R nginx:nginx /var/www/webvirtmgr

vim /etc/supervisord.conf
[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

確保下面bind系結的是本機的8000埠,這個在nginx設定中定義了,被代理的埠
grep '^bind =' /var/www/webvirtmgr/conf/gunicorn.conf.py
bind = '127.0.0.1:8000'

systemctl restart nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
vi /etc/nginx/nginx.conf
注釋掉39行
39    #    listen      80 default_server;

systemctl restart nginx.service
systemctl start supervisord.service 

後台執行
nohup /usr/bin/python2 /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py &

 


IT145.com E-mail:sddin#qq.com