您的位置:首页 > 其它

KVM 实践webvirtmgr 安装与配置

2016-10-19 15:22 627 查看
1. Installation
$ yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm$ yum -y install git python-pip libvirt-python
libxml2-python python-websockify supervisor nginx
======================================================================================================
2. Install python requirements and setup Django environment
$ git clone git://github.com/retspen/webvirtmgr.git$ cd webvirtmgr$ pip install -r requirements.txt # or python-pip (RedHat,
Fedora, CentOS, OpenSuse)$ ./manage.py syncdb$ ./manage.py collectstatic
Adding additional superusers
$ ./manage.py createsuperuser
#这个是管理员账号,用上面的admin和这个管理员账号都可以登陆webvirtmgr的web界面管理平台

[root@localhost ~]# git clone git://github.com/retspen/webvirtmgr.git
Initialized empty Git repository in /root/webvirtmgr/.git/
remote: Counting objects: 5721, done.
remote: Total 5721 (delta 0), reused 0 (delta 0), pack-reused 5721
Receiving objects: 100% (5721/5721), 3.01 MiB | 467 KiB/s, done.
Resolving deltas: 100% (3683/3683), done.
[root@localhost ~]# cd webvirtmgr
[root@localhost webvirtmgr]# pip install -r requirements.txt # or python-pip (RedHat, Fedora, CentOS, OpenSuse)
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting django==1.5.5 (from -r requirements.txt (line 1))
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to
4000
fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning
Downloading Django-1.5.5.tar.gz (8.1MB)
100% |████████████████████████████████| 8.1MB 62kB/s
Collecting gunicorn==18.0 (from -r requirements.txt (line 2))
Downloading gunicorn-18.0.tar.gz (366kB)
100% |████████████████████████████████| 368kB 390kB/s
Collecting lockfile>=0.9 (from -r requirements.txt (line 3))
Downloading lockfile-0.12.2-py2.py3-none-any.whl
Installing collected packages: django, gunicorn, lockfile
Running setup.py install for django
Running setup.py install for gunicorn
Successfully installed django-1.5.5 gunicorn-18.0 lockfile-0.12.2
[root@localhost webvirtmgr]# ./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: liujianfei@uzai.com
Password:
Password (again):
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)
[root@localhost webvirtmgr]# ./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 '/root/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.woff'
Copying '/root/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.eot'
Copying '/root/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.ttf'
Copying '/root/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.svg'
Copying '/root/webvirtmgr/webvirtmgr/static/img/desc.gif'
Copying '/root/webvirtmgr/webvirtmgr/static/img/favicon.ico'
Copying '/root/webvirtmgr/webvirtmgr/static/img/bg.gif'
Copying '/root/webvirtmgr/webvirtmgr/static/img/asc.gif'
Copying '/root/webvirtmgr/webvirtmgr/static/js/jquery-migrate-1.2.1.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/bootstrap-multiselect.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/jquery-1.10.2.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/Chart.min.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/infrastructure.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/jquery.tablesorter.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/bootstrap.min.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/Orbitron700.ttf'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/input.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/rfb.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/websock.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/black.css'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/base.css'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/util.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/jsunzip.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/playback.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/display.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/base64.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/logo.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/des.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/webutil.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/blue.css'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/ui.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/Orbitron700.woff'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/web-socket-js/web_socket.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/web-socket-js/WebSocketMain.swf'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/web-socket-js/README.txt'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/web-socket-js/swfobject.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/novnc/chrome-app/tcp-client.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/filexfer.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/bitmap.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/prng4.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/spicedataview.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/wire.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/enums.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/utils.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/spicemsg.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/resize.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/cursor.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/lz.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/playback.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/png.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/display.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/spicearraybuffer.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/spicetype.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/atKeynames.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/webm.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/rng.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/inputs.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/simulatecursor.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/rsa.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/jsbn.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/ticket.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/spiceconn.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/sha1.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/quic.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/main.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/prng4.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/rng.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/rsa.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/jsbn.js'
Copying '/root/webvirtmgr/webvirtmgr/static/js/spice-html5/thirdparty/sha1.js'
Copying '/root/webvirtmgr/webvirtmgr/static/css/webvirtmgr.css'
Copying '/root/webvirtmgr/webvirtmgr/static/css/bootstrap-multiselect.css'
Copying '/root/webvirtmgr/webvirtmgr/static/css/table-sort.css'
Copying '/root/webvirtmgr/webvirtmgr/static/css/bootstrap.min.css'
Copying '/root/webvirtmgr/webvirtmgr/static/css/signin.css'

75 static files copied.
[root@localhost webvirtmgr]# ./manage.py createsuperuser
WARNING:root:No local_settings file found.
Username (leave blank to use 'root'): admin
Error: That username is already taken.
Username (leave blank to use 'root'): uzai
Email address: uzai@uzai.com
Password:
Password (again):
Superuser created successfully.
[root@localhost webvirtmgr]#

Setup Nginx

$ cd ..$ sudo mv webvirtmgr /var/www/ ( CentOS, RedHat, Fedora, Ubuntu )

[root@localhost webvirtmgr]# cd ..
[root@localhost ~]# mv webvirtmgr/ /var/www


Add file webvirtmgr.conf in /etc/nginx/conf.d:

[root@localhost ~]# vi /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 $scheme;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M; # Set higher depending on your needs
}
}


注释掉default.conf
[root@localhost ~]# vi /etc/nginx/conf.d/default.conf
#
# The default server
#

#server {
#    listen       80 default_server;
#    listen       [::]:80 default_server;
#    server_name  _;
#    root         /usr/share/nginx/html;
#
#    # Load configuration files for the default server block.
#    include /etc/nginx/default.d/*.conf;
#
#    location / {
#    }
#
#    error_page 404 /404.html;
#        location = /40x.html {
#    }
#
#    error_page 500 502 503 504 /50x.html;
#        location = /50x.html {
#    }
#
#}


Restart nginx service:

$ sudo service nginx restart

Update SELinux policy

/usr/sbin/setsebool httpd_can_network_connect true

make it permanet service: ( OpenSusE ,CentOS, RedHat, Fedora)

$ chkconfig supervisord on

4. Setup Supervisor

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

[root@localhost ~]# chown -R nginx:nginx /var/www/webvirtmgr
Create file /etc/supervisord.d/webvirtmgr.ini with following content:
[root@localhost ~]# mkdir /etc/supervisord.d
[root@localhost ~]# vi /etc/supervisord.d/webvirtmgr.ini
[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


重起服务

$ service supervisord stop$ service supervisord start
[root@localhost ~]# service supervisord stop
Stopping supervisord:                                      [FAILED]
[root@localhost ~]# service supervisord start
Starting supervisord:                                      [  OK  ]


5.1 Update 

$ cd /var/www/webvirtmgr$ git pull$ ./manage.py collectstatic$ service supervisord restart

启动服务

$ ./manage.py runserver 0:8000

用浏览器打开
HTTP://ip+:8000
下面开始设置客户端

我们现在设置用TCP方式连接客户端

客户端配置。

Setup libvirt and KVM

$ curl http://retspen.github.io/libvirt-bootstrap.sh | sudo sh

or if haven't curl

$ wget -O - http://retspen.github.io/libvirt-bootstrap.sh | sudo sh

[root@localhost ~]# curl http://retspen.github.io/libvirt-bootstrap.sh | sudo sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 26177 100 26177 0 0 35024 0 --:--:-- --:--:-- --:--:-- 42772
* INFO: Found function install_centos
* DEBUG: INSTALL_FUNC=install_centos
* INFO: Running install_centos()
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.nwsuaf.edu.cn
* extras: mirrors.btte.net
* updates: mirrors.btte.net
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
updates
b009
| 3.4 kB 00:00
Package 2:qemu-kvm-0.12.1.2-2.491.el6_8.3.x86_64 already installed and latest version
Package libvirt-0.10.2-60.el6.x86_64 already installed and latest version
Package bridge-utils-1.2-10.el6.x86_64 already installed and latest version
Nothing to do
* INFO: Found function install_centos_post
* DEBUG: POST_INSTALL_FUNC=install_centos_post
* INFO: Running install_centos_post()
* INFO: Found function daemons_running_centos
* DEBUG: DAEMONS_RUNNING_FUNC=daemons_running_centos
* INFO: Running daemons_running_centos()
Starting libvirtd daemon: [ OK ]

Resuming guests on default URI...
Resuming guest win2012A: done
Resuming guest kvm-web: done


验证是否安装成功
[root@localhost ~]# netstat -antp |grep 16509
tcp        0      0 0.0.0.0:16509               0.0.0.0:*                   LISTEN      18280/libvirtd
tcp        0      0 :::16509                    :::*                        LISTEN      18280/libvirtd


Setup TCP Authorization

用saslpasswd2命令增加授权用户 我们现在增加一个xiaohai用户密码默认

$ saslpasswd2 -a libvirt fredPassword: xxxxxxAgain (for verification): xxxxxx

[root@localhost ~]# saslpasswd2 -a libvirt xiaohai
Password:
Again (for verification):

如果想查看所有用户可以用以下命令

$ sasldblistusers2 -f /etc/libvirt/passwd.dbfred@webvirtmgr.net: userPassword

[root@localhost ~]# sasldblistusers2 -f /etc/libvirt/passwd.db

xiaohai@localhost.localdomain: userPassword

如果想禁止用户访问可以用 -d

$saslpasswd2 -a libvirt -d fred

Verify settings 从服务端验证设置

[root@localhost www]# virsh -c qemu+tcp://10.1.4.13/system nodeinfo
Please enter your authentication name: xiaohai (用户名)
Please enter your password: (密码)
CPU model: x86_64
CPU(s): 12
CPU frequency: 2400 MHz
CPU socket(s): 1
Core(s) per socket: 6
Thread(s) per core: 2
NUMA cell(s): 1
Memory size: 32765636 KiB

If you have same error:

$ virsh -c qemu+tcp://IP_address/system nodeinfoPlease enter your authentication name: fredPlease enter your password:error: authentication failed: authentication failederror:
failed to connect to the hypervisor

Try input login with domain (hostname):

$ sasldblistusers2 -f /etc/libvirt/passwd.dbfred@webvirtmgr.net: userPassword

现在遇到一个问题

就是我想远程连接桌面的时候 出现下面情况

Server disconnected (code: 1006)

解决方法

问题找了半天 才发现是一个python脚本没有执行成功 ./var/www/console/webvirtmgr-console
#./var/www/console/webvirtmgr-console
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: