公司機房有一臺2U的服務器(64G內存,32核),因爲近期新增業務比較多,測試機也要新增,服務器資源十分有限。因此打算在這臺2U服務器上部署kvm虛擬化,虛出多臺VM出來,以應對新的測試需求。
當KVM宿主機愈來愈多,須要對宿主機的狀態進行調控,決定採用WebVirtMgr做爲kvm虛擬化的web管理工具,圖形化的WEB,讓人能更方便的查看kvm 宿主機的狀況和操做
WebVirtMgr是近兩年來發展較快,比較活躍,很是清新的一個KVM管理平臺,提供對宿主機和虛機的統一管理,它有別於kvm自帶的圖形管理工具(virtual machine manager),讓kvm管理變得更爲可視化,對中小型kvm應用場景帶來了更多方便。
WebVirtMgr採用幾乎純Python開發,其前端是基於Python的Django,後端是基於Libvirt的Python接口,將平常kvm的管理操做變的更加的可視化。html
WebVirtMgr特色
操做簡單,易於使用
經過libvirt的API接口對kvm進行管理
提供對虛擬機生命週期管理
WebVirtMgr 功能前端
宿主機管理支持如下功能
CPU利用率
內存利用率
網絡資源池管理
存儲資源池管理
虛擬機鏡像
虛擬機克隆
快照管理
日誌管理
虛機遷移python
虛擬機管理支持如下功能
CPU利用率
內存利用率
光盤管理
關/開/暫停虛擬機
安裝虛擬機
VNC console鏈接
建立快照linux
下面對部署過程進行記錄,但願能幫助到有用到的朋友們。
這裏我將webvirtmgr服務器和kvm服務器放在同一臺機器上部署的,即單機部署
系統:Centos 6.8
內存:64G
CPU:32核
ip:192.168.1.17(內網),111.101.186.163(外網)nginx
1、首先要安裝KVM虛擬化環境,參考下面的一篇博客進行安裝:git
kvm虛擬化管理平臺WebVirtMgr部署-虛擬化環境安裝-完整記錄(0)github
2、Kvm的管理工具webvirtmgr安裝和使用web
1)安裝支持的軟件源
[root@openstack ops]#yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpmsql
2)安裝相關軟件
---------------------------------------------------------------------------------------------------------------------
若是報錯說沒有下面安裝的某些軟件,則下載http://pan.baidu.com/s/1bX3vkE (密碼:6ucs)
將下載的yum.tar.gz解壓後的文件替換到/etc/yum.repos.d目錄下,而後執行yum clean all && yum makecache
---------------------------------------------------------------------------------------------------------------------
[root@openstack ops]#yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx (如果centos7系統,須要先執行"yum -y install epel-release")數據庫
3)從git-hub中下載相關的webvirtmgr代碼
[root@openstack ops]# cd /usr/local/src/
[root@openstack src]# git clone git://github.com/retspen/webvirtmgr.git (下載地址:https://pan.baidu.com/s/1pLS3kCj 獲取密碼:8efm)
4)安裝webvirtmgr
[root@openstack src]# cd webvirtmgr/
[root@openstack webvirtmgr]# pip install -r requirements.txt
5)安裝數據庫
[root@openstack webvirtmgr]# yum install python-sqlite2 //默認狀況下,centos系統通常會自帶sqlite軟件(執行sqlite3 命令,不報錯就說明已經安裝了)
6)對django進行環境配置
[root@openstack webvirtmgr]#pwd
/usr/local/src/webvirtmgr
[root@openstack webvirtmgr]#./manage.py syncdb //默認是python執行,以下報錯,換用其餘版本的python
-------------------------------------------------- ----------------------------
注意此處用默認的python執行上面命令,通常會報錯,以下:
ImportError: No module named django.core.management
這個通常是因爲python版本引發的,由於系統自帶有好幾個版本的python
[root@openstack webvirtmgr]# python //按Tab鍵自查找
python python2.6
python2 python2.6-config python-config
[root@openstack webvirtmgr]# python -V
Python 2.6.6
由此可看出,系統默認的Python版本是2.6.6
說明上面命令默認是python2.6執行的
既然使用python2.6執行上面的命令報錯,那就換用其餘版本python2執行(若是當前是python3.3.0,那麼就將下面的/usr/bin/python2換成/usr/bin/python2.6)
[root@openstack webvirtmgr]# /usr/bin/python2 manage.py syncdb //最終發現使用python2執行這個命令就不報錯了
............
............
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: wangshibo@163.com
Password:*********
Password (again):*********
--------------------- --------------------- --------------------- ---------------------
[root@openstack webvirtmgr]#/usr/bin/python2 manage.py collectstatic //生成配置文件(一樣使用python2版本執行,不要使用默認的python執行)
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
..........
..........
[root@openstack webvirtmgr]#/usr/bin/python2 manage.py createsuperuser //添加管理員帳號(一樣使用python2版本執行,不要使用默認的python執行)
WARNING:root:No local_settings file found.
Username: ops //這個是管理員帳號,用上面的admin和這個管理員帳號均可以登錄webvirtmgr的web界面管理平臺
Email address: wangshibo@163.com
Password:
Password (again):
Superuser created successfully.
7)拷貝web到 相關目錄
[root@openstack ops]# mkdir -pv /var/www
[root@openstack ops]# cp -Rv /usr/local/src/webvirtmgr /var/www/webvirtmgr
8)設置ssh
[root@openstack ops]# ssh-keygen -t rsa //產生公私鑰
[root@openstack ops]# ssh-copy-id 192.168.1.17 //因爲這裏webvirtmgr和kvm服務部署在同一臺機器,因此這裏本地信任。若是kvm部署在其餘機器,那麼這個是它的ip
[root@openstack ops]# ssh 192.168.1.17 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60
9)編輯nginx配置文件
提早確保/etc/nginx/nginx.conf文件裏開啓了「include /etc/nginx/conf.d/*.conf;」
[root@openstack ops]#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
}
}
[root@openstack ops]# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
10)啓動nginx
[root@openstack ops]#/ etc/init.d/nginx restart
11)修改防火牆規則
[root@ops ~]# vim /etc/sysconfig/selinux
......
SELINUX=disabled
[root@ops ~]# setenforce 0
setenforce: SELinux is disabled
[root@ops ~]# getenforce
Disabled
[root@openstack ops]#/usr/sbin/setsebool httpd_can_network_connect true
12)設置 supervisor (若是iptables防火牆開啓的話,就必需要開通80、8000、6080端口訪問)
[root@openstack ops]# chown -R nginx:nginx /var/www/webvirtmgr
[root@openstack ops]# vim /etc/supervisord.conf //在文件末尾添加,注意將默認的python改成python2,由於上面只有用這個版本執行纔不報錯!
[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
[root@openstack ops]#vim /var/www/webvirtmgr/conf/gunicorn.conf.py //確保下面bind綁定的是本機的8000端口,這個在nginx配置中定義了,被代理的端口
bind = '127.0.0.1:8000'
13)設置開機啓動
[root@openstack ops]#chkconfig supervisord on
[root@openstack ops]#vim /etc/rc.local
/usr/sbin/setsebool httpd_can_network_connect true
14)啓動進程
[root@openstack ops]#/etc/init.d/supervisord restart
15)查看進程
[root@openstack ops]#netstat -lnpt //便可以看到6080和8000已經啓動
[root@openstack ops]# lsof -i:6080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python2 53476 nginx 3u IPv4 364124 0t0 TCP *:6080 (LISTEN)
[root@openstack ops]#lsof -i:8000
------------------------------------------------------------------------------
通常來講,只要上面的supervisord服務啓動了,8000和6080端口就起來了。
由於在/etc/supervisord.conf文件裏配置了這兩個端口的啓動設置
若是supervisord服務啓動了,8000和6080端口仍是沒起來!
那麼就須要手動啓動/etc/supervisord.conf文件裏配置的這兩個端口的啓動命令,即:
[root@openstack ops]# /usr/bin/python2 /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py //這個命令會一直在操做
[root@openstack ops]# /usr/bin/python2 /var/www/webvirtmgr/console/webvirtmgr-console //這個命令會一直在操做
[root@openstack ops]# /etc/init.d/supervisord restart
[root@openstack ops]# lsof -i:8000
[root@openstack ops]# lsof -i:6080
------------------------------------------------------------------------------
16)web訪問
http://111.101.186.163/login/
這裏用超級管理員登錄,只有超級管理員登錄後才能看到「基礎構架」窗口
普通用戶登錄後,只能看到「WebVirtMgr」一個窗口
選擇「SSH連接「,設置Label,IP,用戶
注意:Label與IP要相同
打開後,有報錯!看來在上面使用ssh鏈接的配置環節有誤所致!
解決措施:
1)在webvirtmgr服務器(服務端)上(這裏kvm和WebVirtMgr部署在同一臺機器上)建立nginx用戶家目錄(默認nginx服務安裝時是沒有nginx家目錄的),生成nginx的公私鑰
[root@openstack ops]# cd /home/
[root@openstack home]# mkdir nginx
[root@openstack home]# chown nginx.nginx nginx/
[root@openstack home]# chmod 700 nginx/ -R
[root@openstack home]# su - nginx -s /bin/bash
-bash-4.1$ ssh-keygen #期間輸入yes後直接回車,回車
-bash-4.1$ touch ~/.ssh/config && echo -e "StrictHostKeyChecking=no\nUserKnownHostsFile=/dev/null" >> ~/.ssh/config
-bash-4.1$ chmod 0600 ~/.ssh/config
2)在kvm(客服端)服務器上(這裏kvm和WebVirtMgr部署在同一臺機器上)配置用戶,這裏默認採用root用戶
---------------------------------------------------------------------------------------------------------------------
若是採用其餘用戶,好比webvirtmgr,操做以下:
[root@openstack ops]#useradd webvirtmgr
[root@openstack ops]#echo "123456" | passwd --stdin webvirtmgr
[root@openstack ops]#groupadd libvirt
[root@openstack ops]#usermod -G libvirt -a webvirtmgr
---------------------------------------------------------------------------------------------------------------------
3)在webvirtmgr服務器(服務端)上(這裏kvm和WebVirtMgr部署在同一臺機器上),將nginx用戶的ssh-key上傳到kvm服務器上(這裏kvm和WebVirtMgr部署在同一臺機器上)
[root@openstack ops]# su - nginx -s /bin/bash
-bash-4.1$ ssh-copy-id root@192.168.1.17
Warning: Permanently added '192.168.1.17' (RSA) to the list of known hosts.
root@192.168.1.17's password: #輸入192.168.1.17即本機的root帳號
Now try logging into the machine, with "ssh 'root@192.168.1.17'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
---------------------------------------------------------------------------------------------------------------------
這裏採用的是root用戶,若是採用其餘用戶,好比上面假設的webvirtmgr用戶,操做以下:
[root@openstack ops]#su - nginx -s /bin/bash
-bash-4.1$ssh-copy-id webvirtmgr@192.168.0.23
---------------------------------------------------------------------------------------------------------------------
4)在kvm(客服端)服務器上(這裏kvm和WebVirtMgr部署在同一臺機器上)配置 libvirt ssh受權
[root@openstack ops]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:root #注意這裏採用的是root用戶
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[root@openstack ops]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
-------------------------------------------------------------------------------------------------------------------------------
這裏採用的是root用戶,若是採用其餘用戶,好比上面假設的webvirtmgr用戶,操做以下:
[root@openstack ops]#vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
[Remote libvirt SSH access]
Identity=unix-user:webvirtmgr #這裏就設定webvirtmgr用戶
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes
[root@openstack ops]#chown -R webvirtmgr.webvirtmgr /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
--------------------------------------------------------------------------------------------------------------------------------
5)重啓 libvirtd 服務
/etc/init.d/libvirtd restart
這樣上面報錯的問題就迎仍而解了!
而後從新ssh方式鏈接就ok了,就不會有上面那個報錯了~
可是,又出現了其餘報錯(以下)!尼瑪~~ 接續排查!
解決措施:
在WebVirtMgr服務器本地使用ssh方式鏈接,在終端命令行裏:
[root@openstack .ssh]# virsh -c qemu+ssh://103.10.86.17/system list
The authenticity of host '103.10.86.17 (103.10.86.17)' can't be established.
RSA key fingerprint is 3d:c1:2e:70:e9:e5:1d:84:40:a2:63:82:af:e5:cc:cd.
Are you sure you want to continue connecting (yes/no)? yes
error: End of file while reading data: Warning: Permanently added '103.10.86.17' (RSA) to the list of known hosts.: Input/output error
error: failed to connect to the hypervisor
看日誌 tail /var/log/secure | grep sshd 發現是我這裏主動發出斷開的.有可能檢測到libvirtd有些問題致使的。
當時使用virt-manage能夠查詢到遠程的信息.估計是sshd出現的問題把.
折騰一會,暫時沒找到解決方案
決定先選用經過tcp協議進行遷移的(可是這種方式沒有用ssh鏈接方式安全——)
等後面有時間了,再想辦法解決上面ssh方式鏈接的錯誤吧
使用tcp進行對遠程libvirtd進行鏈接訪問的配置以下:
1)修改文件/etc/sysconfig/libvirtd,用來啓用tcp的端口
[root@openstack ops]# cat /etc/sysconfig/libvirtd
........
LIBVIRTD_CONFIG=/etc/libvirt/libvirtd.conf
LIBVIRTD_ARGS="--listen"
2)修改文件/etc/libvirt/libvirtd.conf
[root@openstack ops]#vim /etc/libvirt/libvirtd.conf
listen_tls = 0
listen_tcp = 1
tcp_port = "16509"
listen_addr = "0.0.0.0"
auth_tcp = "none"
3)運行 libvirtd
[root@openstack ops]#service libvirtd restart
若是沒起效果(個人就沒有生效,那麼使用命令行.若是生效了,執行下面命令就會報錯
[root@openstack ops]#libvirtd --daemon --listen --config /etc/libvirt/libvirtd.conf
4)查看運行進程
[root@openstack ops]# ps aux | grep libvirtd
root 16563 1.5 0.1 925880 7056 ? Sl 16:01 0:28 libvirtd -d -l --config /etc/libvirt/libvirtd.conf
5)查看端口
[root@openstack ops]# lsof -i:16509
6)在source host鏈接dest host遠程libvirtd查看信息(也能夠用公網ip)
[root@openstack ops]# virsh -c qemu+tcp://192.168.1.17/system
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh #
成功使用tcp去訪問libvirtd。
注意:
在使用tcp方式鏈接後,會出現鏈接終端的狀況!
[root@openstack .ssh]# virsh -c qemu+tcp://192.168.1.17/system
error: Cannot recv data: Connection reset by peer
error: failed to connect to the hypervisor
鏈接斷開,從新鏈接即可。
[root@openstack ops]# ps aux | grep libvirtd
root 59619 0.6 0.0 1008128 22048 ? Sl 19:17 0:06 libvirtd --daemon --config /etc/libvirt/libvirtd.conf --listen
root 61081 0.0 0.0 103316 1004 pts/2 S+ 19:33 0:00 grep --color libvirtd
[root@openstack ops]# kill -9 59619
[root@openstack ops]# ps aux | grep libvirtd
root 61083 0.0 0.0 103312 904 pts/2 S+ 19:33 0:00 grep --color libvirtd
[root@openstack ops]# libvirtd --daemon --listen --config /etc/libvirt/libvirtd.conf
[root@openstack ops]# ps aux | grep libvirtd
root 61086 13.5 0.0 418240 6576 ? Sl 19:33 0:00 libvirtd --daemon --listen --config /etc/libvirt/libvirtd.conf
root 61176 0.0 0.0 103312 908 pts/2 S+ 19:33 0:00 grep --color libvirtd
[root@openstack ops]# virsh -c qemu+tcp://192.168.1.17/system
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh #
後續發現,webvirtmgr連上後,過一下子就會斷開!
針對這個狀況,能夠能夠寫個定時腳本,以下:
[root@openstack ops]# cat /usr/local/src/libvirtd.sh
#!/bin/bash
ps -ef | grep "libvirtd --daemon --listen"|grep -v grep|awk -F" " '{print $2}'|xargs kill -9
/usr/sbin/libvirtd --daemon --listen --config /etc/libvirt/libvirtd.conf
[root@openstack ops]# crontab -l
* * * * * /bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1
* * * * * sleep 10;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1
* * * * * sleep 20;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1
* * * * * sleep 30;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1
* * * * * sleep 40;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1
* * * * * sleep 50;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1
*********************************************************************************
通常如上配置後,webvirtmgr裏的控制檯是能夠正常鏈接虛擬機的。
但若是webvirtmgr裏經過控制檯頁面(vnc)鏈接虛擬機失敗,能夠按照下面的操做方法嘗試解決:
kvm原來的安裝方式是客戶端須要安裝vncviewer,才能看到安裝頁面,而webvirtmgr使用了novnc,頁面經過websocket進行通訊。
1)首先須要安裝novnc
[root@openstack ops]# yum install -y novnc
2)防火牆打開vnc的6080端口
[root@openstack ops]# vim /etc/sysconfig/iptables
.......
-A INPUT -p tcp -m state --state NEW -m tcp --dport 6080 -j ACCEPT
.......
[root@openstack ops]# /etc/init.d/iptables restart
3)由上面可知,webvirtmgr進程經過supervisor管理。這裏須要重啓supervisor進程
[root@openstack ops]# /etc/init.d/supervisord restart
這樣,再次打開Webvirtmgr的控制檯,發現就能連上虛擬機了!
******************
能夠在webvirtmgr服務器上經過命令行嘗試下鏈接:
[root@openstack ops]# novnc_server --help
Usage: novnc_server [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT]
Starts the WebSockets proxy and a mini-webserver and
provides a cut-and-paste URL to go to.
--listen PORT Port for proxy/webserver to listen on
Default: 6080
--vnc VNC_HOST:PORT VNC server host:port proxy target
Default: localhost:5900
--cert CERT Path to combined cert/key file
Default: self.pem
--web WEB Path to web files (e.g. vnc.html)
Default: ./
[root@openstack ops]# novnc_server --listen 192.168.1.17:6086 #端口在6080後的均可以用
Warning: could not find self.pem
Starting webserver and WebSockets proxy on port 192.168.1.17:6086
WARNING: no 'numpy' module, HyBi protocol will be slower
WebSocket server settings:
- Listen on 192.168.1.17:6086
- Flash security policy server
- Web server. Web root: /usr/share/novnc
- No SSL/TLS support (no cert file)
- proxying from 192.168.1.17:6086 to localhost:5900
Navigate to this URL:
http://kvm-server:192.168.1.17:6086/vnc.html?host=kvm-server&port=192.168.1.17:6086
Press Ctrl-C to exit
===============================================
上面介紹的是WebVirtMgr和KVM部署在一臺機器上,下面再記錄下添加其餘KVM宿主機(好比192.168.1.50)的方法
1)在192.168.1.50機器上配置虛擬化及網橋環境 參考:https://www.cnblogs.com/kevingrace/p/5737487.html 2)手動建立下面文件並配置SSH鏈接(若是採用tcp方式鏈接,其實這一步就不用配置了) [root@kvm02 ~]# vim /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla [Remote libvirt SSH access] Identity=unix-user:root Action=org.libvirt.unix.manage ResultAny=yes ResultInactive=yes ResultActive=yes [root@kvm02 ~]# chown -R root.root /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla 3)在WebVirtMgr部署機(上面的192.168.1.17 )上執行: [root@openstack ops]# ssh-copy-id 192.168.1.50 [root@openstack ops]# ssh 192.168.1.50 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60 [root@openstack ops]# su - nginx -s /bin/bash -bash-4.1$ ssh-copy-id root@192.168.1.50 驗證從WebVirtMgr部署機192.168.1.17無密碼登陸到其餘kvm宿主機(192.168.1.50)的信任關係 [root@openstack ops]# ssh -p22 root@192.168.1.50 Last login: Thu Jun 7 14:17:37 2018 from 192.168.10.10 [root@kvm02 ~]# [root@openstack ops]# ssh 192.168.1.50 -L localhost:8000:localhost:8000 -L localhost:6080:localhost:60 bind: Address already in use bind: Address already in use Last login: Thu Jun 7 14:49:44 2018 from 192.168.10.10 [root@kvm02 ~]# [root@openstack ops]# su - nginx -s /bin/bash -bash-4.1$ ssh root@192.168.1.50 Warning: Permanently added '192.168.1.50' (RSA) to the list of known hosts. Last login: Thu Jun 7 14:49:17 2018 from 192.168.10.10 [root@kvm02 ~]# 4)在192.168.1.50機器上進行libvirtd的TCP鏈接配置 修改文件/etc/sysconfig/libvirtd,用來啓用tcp的端口 [root@kvm02 ~]# cat /etc/sysconfig/libvirtd ........ LIBVIRTD_CONFIG=/etc/libvirt/libvirtd.conf LIBVIRTD_ARGS="--listen" 修改文件/etc/libvirt/libvirtd.conf [root@kvm02 ~]# vim /etc/libvirt/libvirtd.conf listen_tls = 0 listen_tcp = 1 tcp_port = "16509" listen_addr = "0.0.0.0" auth_tcp = "none" 運行 libvirtd [root@kvm02 ~]# service libvirtd restart 建議使用下面方式運行libvirtd [root@kvm02 ~]# service libvirtd stop [root@kvm02 ~]# ps -ef|grep libvirtd|grep -v grep|awk '{print $2}'|xargs kill -9 [root@kvm02 ~]# libvirtd --daemon --listen --config /etc/libvirt/libvirtd.conf 查看運行進程 [root@kvm02 ~]# ps aux | grep libvirtd root 16563 1.5 0.1 925880 7056 ? Sl 16:01 0:28 libvirtd -d -l --config /etc/libvirt/libvirtd.conf 查看端口 [root@kvm02 ~]# lsof -i:16509 關閉iptables防火牆,若是防火牆打開了,則須要添加下面規則: [root@kvm02 ~]# vim /etc/sysconfig/iptables ...... -A INPUT -m state --state NEW -m tcp -p tcp --dport 16509 -j ACCEPT [root@kvm02 ~]# /etc/init.d/iptables restart 而後在WebVirtMgr部署機192.168.1.17上進行驗證tcp鏈接驗證 [root@openstack ops]# virsh -c qemu+tcp://192.168.1.50/system Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # 最後爲了防止在使用tcp方式鏈接後出現"error: Cannot recv data: Connection reset by peer",即連上後一下子就斷開了。 須要在kvm宿主機上添加下面腳本 [root@kvm02 ~]# vim /usr/local/src/libvirtd.sh #!/bin/bash ps -ef | grep "libvirtd --daemon --listen"|grep -v grep|awk -F" " '{print $2}'|xargs kill -9 /usr/sbin/libvirtd --daemon --listen --config /etc/libvirt/libvirtd.conf [root@kvm02 ~]# chmod 755 /usr/local/src/libvirtd.sh [root@kvm02 ~]# sh /usr/local/src/libvirtd.sh [root@kvm02 ~]# crontab -e * * * * * /bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1 * * * * * sleep 10;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1 * * * * * sleep 20;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1 * * * * * sleep 30;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1 * * * * * sleep 40;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1 * * * * * sleep 50;/bin/bash -x /usr/local/src/libvirtd.sh > /dev/null 2>&1 這樣,登陸WebVirtMgr界面就能夠成功添加上面的kvm宿主機(192.168.10.50)了。
========================================================
上面是在centos6下的操做記錄。下面簡單介紹下在centos7版本下的操做
1)yum源的配置及安裝所需軟件包 # yum -y install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.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軟件 # cd /usr/local/src/ # git clone git://github.com/retspen/webvirtmgr.git # git clone https://github.com/retspen/webvirtmgr.git 3)數據庫安裝 # cd /usr/local/src/ # 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 /usr/local/src/webvirtmgr # pip install -r requirements.txt ............ 後面跟在centos6版本系統下的安裝操做步驟同樣。