作者:邓聪聪
我们常在Windowns下使用VMware,当然在Liunx中也有这样的软件供我们使用。生产环境的KVM宿主机越来越多,需要对宿主机的状态进行调控。这里用webvirtmgr进行管理。图形化的WEB,让人能更方便的查看kvm 宿主机的情况和操作
环境:CentnOS 6.8
工具:git clone git://github.com/retspen/webvirtmgr.git (去git_hub求源代码),(增加安装支持的软件源)yum -y install http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
依赖:git python-pip libvirt-python libxml2-python python-websockify upervisor nginx novnc python-virtinst libvirt vm ridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v tunctl unzip zip
安装KVM前需要查看本机系统配置是否支持安装(cat /proc/cpuinfo | egrep '(vmx|svm)' | wc -l; 结果>0 表示支持)
1 安装支持的软件源;
yum -y install http://dl.fedoraproject.org/pub/epel//i386/epel-release--.noarch.rpm
2 安装相关软件;
yum -y install git python-pip libvirt-python libxml2-python python-websockify upervisor nginx novnc python-virtinst libvirt vm ridge-utils virt-manager qemu-kvm-tools virt-viewer virt-v2v tunctl unzip zip
3 从git-hub中下载相关的webvirtmgr代码;
cd /usr/local/src/
git clone git://github.com/retspen/webvirtmgr.git
4 安装webvirtmgr;
cd webvirtmgr/
pip install -r requirements.txt
6 对django进行环境配置;
./manage.py syncdb
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'): 用户
Email address: 邮箱
Password:密码
Password (again):密码
###==========================###
./manage.py collectstatic #生成配置文件
./manage.py createsuperuser #添加管理员账号
/usr/bin/python2 manage.py createsuperuser #添加管理员账号(同样使用python2版本执行,不要使用默认的python执行)
7 拷贝web到 相关目录;
cd ..
mkdir -pv /var/www
cp -Rv webvirtmgr /var/www/webvirtmg
chown -R nginx:nginx /var/www/webvirtmgr
8 设置ssh;
su - nginx -s /bin/bash
ssh-keygen #产生公私钥
ssh-copy-id (kvm-ip) #由于这里webvirtmgr和kvm服务部署在同一台机器,所以这里本地信任。如果kvm部署在其他机器,那么这个是它的ip
9 辑nginx配置文件
提前确保/etc/nginx/nginx.conf文件里开启了“include /etc/nginx/conf.d/*.conf;”
[root@local]#vim /etc/nginx/conf.d/webvirtmgr.conf //添加下面内容到文件中
server {
listen 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:;
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 ;
proxy_read_timeout ;
proxy_send_timeout ;
client_max_body_size 1024M; # Set higher depending on your needs
}
}
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
10 设置 supervisor;
[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端口***如果报错无法启动,查看/var/www/wvirtmgr权限是否正常!!!
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@localhost ~]# netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 1698/python2
tcp 0 0 0.0.0.0:6080 0.0.0.0:* LISTEN 1697/python2
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN 544/qemu-kvm
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 32518/nginx
11 修改eth为物理网口,br为桥接网口配置文件
cp ifcfg-eth0 ifcfg-br0 [root@vfeelit network-scripts]# cat ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPV6INIT=no
ONBOOT=yes
DELAY=
IPADDR=192.168.1.66
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
[root@vfeelit network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
BRIDGE=br0
BOOTPROTO=none
IPV6INIT=no
ONBOOT=yes
=========================
ifdown eth
ifup br0
ifup eth
================================================至此,web的部署基本完成。内部功能可参考其他文档
web创建虚拟机;
1:首先创建iso目录和虚拟机文件的存储目录
2
3 a:b;
4