公司机房有一台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版本系统下的安装操做步骤同样。