kvm管理平台webvirtmgr的部署

來源:互聯網
上載者:User

標籤:kvm管理平台webvirtmgr的部署

kvm管理平台webvirtmgr的部署


git地址:https://github.com/retspen/webvirtmgr 
環境: 
system:centos6.2 
libvirt: 0.10.2 
webvirtmgr的安裝,參考:https://github.com/retspen/webvirtmgr/wiki/Install-WebVirtMgr 
1.安裝虛擬化環境

yum -y groupinstall ‘Virtualization Tools‘yum -y groupinstall ‘Virtualization‘yum -y groupinstall ‘Virtulization Client‘yum -y groupinstall ‘Virtulization Platform‘

2.安裝依賴包

$ sudo yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm$ sudo yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx

3.複製代碼

$ git clone git://github.com/retspen/webvirtmgr.git$ cd webvirtmgr$ sudo pip install -r requirements.txt # or python-pip (RedHat, Fedora, CentOS, OpenSuse)

用pip安裝django不太順利,報錯: 
[[email protected] ~]# pip install Django==1.5.5 
Collecting Django==1.5.5 
Could not find a version that satisfies the requirement Django==1.5.5 (from versions: 1.7plus-email-as-username-1.7.0, 4store-0.3, 503-0.1) 
No matching distribution found for Django==1.5.5 
折騰許久,只能去django官網下載了個Django-1.5.12.tar.gz包來安裝

4.Django環境初始化 
執行syncdb時,報錯,未安裝mysqldb 
於是下載MySQL-python-1.2.5.zip,解壓安裝,又是一個報錯:command ‘gcc’ failed with exit status 1 
原因是未安裝:mysql-devel,python-devel,mysql-python

$ ./manage.py syncdb$ ./manage.py collectstatic

5.配置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 $scheme;        proxy_connect_timeout 600;        proxy_read_timeout 600;        proxy_send_timeout 600;        client_max_body_size 1024M; # Set higher depending on your needs     }}

注釋掉nginx的default內容,vim /etc/nginx/conf.d/default.conf 。然後啟動nginx

 sudo service nginx restart

6.啟動django

./manage.py runserver 0.0.0.0:8000

訪問:http://x.x.x.x:8000 (x.x.x.x - your server IP address ),輸入建立的django使用者和密碼,如果沒有建立,請用python manager.py createsuperuser,命令建立。登入後如所示

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_0.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

webvirtmgr用戶端就這樣搭建完了,接下來需要配置虛擬機器所在宿主機的,參考git地址:https://github.com/retspen/webvirtmgr/wiki/Setup-Host-Server

配置宿主機環境: 
system: centos 6.6 
libvirt: 0.10.2 
1.下載並執行指令碼:libvirt-bootstrap.sh 
如果虛擬機器比較多,該指令碼執行時間會比較長,因為會執行service libvirt-guests restart,會將所有啟動並執行虛擬機器掛起然後再恢複

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

2.設定防火牆:

 sudo iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 16509 -j ACCEPT

3.設定TCP認證Setup TCP authorization

參考:https://github.com/retspen/webvirtmgr/wiki/Setup-TCP-authorization,webvirtmgr建立伺服器串連時需要此帳號

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

查看新加的帳號

$ sudo sasldblistusers2 -f /etc/libvirt/passwd.db[email protected]: userPassword

刪除新加的帳號:

sudo saslpasswd2 -a libvirt -d fred

驗證新加的帳號:

virsh -c qemu+tcp://IP_address/system nodeinfoPlease enter your authentication name: [email protected] enter your password: xxxxxxCPU model:           x86_64CPU(s):              2CPU frequency:       2611 MHzCPU socket(s):       1Core(s) per socket:  2Thread(s) per core:  1NUMA cell(s):        1Memory size:         2019260 kB

注意:帳號全名帶hostname,如[email protected]

4.設定ssh認證 
ssh和tcp設定一種即可,其實就是設定無密碼登入,要注意的是從webvirtmgr的什麼使用者到宿主機的什麼使用者的無密碼登入,比如我用root跑的django webvirtmgr,而宿主機也是root跑的virsh,所以需要設定root到root的無密碼登入。而git官網推薦的是用nginx使用者跑django webvirtmgr,webvirtmgr使用者跑的virsh,所以設定的是nginx使用者到宿主機webvirtmgr使用者的無密碼登入。 
參考:https://github.com/retspen/webvirtmgr/wiki/Setup-SSH-Authorization

5.使用tcp認證串連伺服器 
訪問:http://xxxx:8000,xxxx是webvirtmgr的ip地址,點擊new connection

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_1.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

使用TCP串連,label填寫ip地址,FQDN/IP 填寫ip地址,使用者名稱填寫第三步設定tcp認證所增加的帳號,這裡的使用者名稱不用加@hostname,點擊添加完成。如:

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_2.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />
650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_3.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

6.使用ssh認證串連伺服器 
訪問訪問:http://xxxx:8000,xxxx是webvirtmgr的ip地址,點擊new connection,使用ssh認證涉及到一個問題,比如我用帳號webvirtmgr登入了宿主機,但是使用命令virsh list的時候,並不能列出虛擬機器資訊,只有root使用者使用virsh list時才能查看資訊。於是我設定了nginx到宿主機root的ssh認證,但是在使用webvirtmgr網頁登入時,發現並不能登入,需要手動輸入,而且手動輸入後發現,是可用的。

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_4.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

後來找到原因了,因為我用root跑的webvirtmgr,所以需要設定webvirtmgr伺服器的root使用者宿主機的root使用者的無密碼登入,設定後,可以使用。

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_5.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

7.虛擬機器控制台使用 
點擊虛機執行個體,每台虛機最後的按鈕”控制台”,點擊後發現報錯,如所示

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_6.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />
650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_7.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

查看django背景錯誤為: 
ERROR:django.request:Internal Server Error: /console/ 
Traceback (most recent call last): 
File “/usr/lib/python2.6/site-packages/django/core/handlers/base.py”, line 113, in get_response 
response = callback(request, *callback_args, **callback_kwargs) 
File “/data/apps/webvirtmgr/console/views.py”, line 58, in console 
response.set_cookie(‘token’, token) 
AttributeError: ‘str’ object has no attribute ‘set_cookie’ 
尋找其原始碼,發現可能的錯誤是由於虛機沒有安裝vnc等圖形管理工具,於是在虛機的xml設定檔添加如下配置: 
virsh edit oss.webvirtmgr.001

<graphics type=‘vnc‘ port=‘5910‘ autoport=‘no‘ listen=‘0.0.0.0‘>      <listen type=‘address‘ address=‘0.0.0.0‘/></graphics>

再重啟虛機,如果還是不行,就先undefine,然後重新根據xml配置create試試。下載個VNC-Viewer,輸入IP:5910,看能否訪問,如所示:說明設定VNC是成功

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_8.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

但是從網頁點擊控制台按鈕,發現還是不行,報錯是server disconnected

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_9.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

訪問時django後台只有如下資訊: 
[26/Apr/2016 05:59:56] “GET /console/?token=4-bcc6ca3b-ca6d-6e51-505a-9c86cf58a6b2 HTTP/1.1” 200 7270

參考這篇:http://ju.outofmemory.cn/entry/145497 
安裝了novnc,仍然報同樣的錯,百度Google也找不到相應的資訊。yum -y install novnc後,無意間在伺服器上發現了這個命令novnc-server

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_10.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

於是敲了如下命令:novnc_server –vnc IPADDR:5920,其中IPADDR為宿主機ip地址,5920是定義的虛擬機器的vnc連接埠號碼。

[[email protected] ~]# novnc_server –vnc 192.168.200.230:5920 
Warning: could not find self.pem 
Starting webserver and WebSockets proxy on port 6080 
WebSocket server settings: 
- Listen on :6080 
- Flash security policy server 
- Web server. Web root: /usr/share/novnc 
- No SSL/TLS support (no cert file) 
- proxying from :6080 to 192.168.200.230:5920

Navigate to this URL:

http://oss-webvirtmgr-001:6080/vnc.html?host=oss-webvirtmgr-001&port=6080

Press Ctrl-C to exit

1: 10.1.196.211: Plain non-SSL (ws://) WebSocket connection 
1: 10.1.196.211: Version hybi-13, base64: ‘False’ 
1: connecting to: 192.168.200.230:5920

結果居然ok了,console控制台起來了

650) this.width=650;" src="http://itfish.net/Home/Modules/Images/itfish_58805_11.jpg" alt="這裡寫圖片描述" title="" style="border:0px;vertical-align:middle;margin:0px;padding:0px;" />

問題是:假如我有30台虛擬機器,每個虛擬機器都有一個vnc連接埠,我是不是得寫30條這樣的命令,監控每一個連接埠??


本文出自 “尼古風鎖絲愁過” 部落格,請務必保留此出處http://smoke520.blog.51cto.com/9256117/1796042

kvm管理平台webvirtmgr的部署

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.