安装环境:
一、KVM安装
linunx:CentOS Linux release 7.1.1503 (Core)
CPU   :16核
内 存 :48G


检查是否支持虚拟化:
[root@pri36 ~]# egrep "(vmx|svm)" /proc/cpuinfo
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi

mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl

xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm

pcid dca sse4_1 sse4_2 popcnt aes lahf_lm ida arat epb dtherm tpr_shadow vnmi flexpriority ept vpid


安装KVM组件
[root@pri36 ~]# yum groupinstall -y "Virtualization" "Virtualization Client" "Virtualization Platform"

"Virtualization Tools"

检查kvm模块是否加载
[root@pri36 ~]# lsmod |grep kvm
kvm_intel             148081  0
kvm                   461126  1 kvm_intel

开启CPU的虚拟化支持

yum install policycoreutils-python
virsh pool-define-as kvm_p_w_picpaths dir - - - - "/home/kvm/p_w_picpaths"
virsh pool-define-as kvm_p_w_picpaths02 dir - - - - "/home/kvm/p_w_picpaths"
virsh pool-list --all
virsh pool-build kvm_p_w_picpaths02
virsh pool-start kvm_p_w_picpaths02
virsh pool-autostart kvm_p_w_picpaths02
virsh pool-info kvm_p_w_picpaths02
virsh vol-create-as kvm_p_w_picpaths2 guest2-rhel7.0.img 8G --formatqcow2
virsh pool-list --all
virsh pool-info kvm_p_w_picpaths02
 yum install acpid -y
virsh vol-create-as kvm_p_w_picpaths02 centos_ceshi6.7.img 8G --format qcow2
virsh vol-list kvm_p_w_picpaths02
virt-install --connect qemu:///system -n centos_ceshi6.7 -r 512 -f /home/kvm/p_w_picpaths/centos_ceshi6.7.img -
s 8 --vnc --os-type=linux --os-variant=rhel6  --vcpus=1 --network bridge=br0 -c /home/CentOS-6.7-x86_64-

Gewara-SP2-bin.iso

virt-viewer centos_ceshi6.7





二、网卡绑定:
cd /etc/sysconfig/network-scripts/
cat > ifcfg-br0 << END
TYPE=Bridge
BOOTPROTO=none
DEVICE=br0
NAME=br0
NM_CONTROLLED=no
ONBOOT=yes
IPADDR=192.168.2.36
NETMASK=255.255.255.0
GATEWAY=192.168.2.11
DNS1=192.168.3.224
DNS2=202.96.209.5
END

cat > ifcfg-enp2s0 < END
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=enp2s0
UUID=157e14ff-4338-4849-9c2c-495d77b86357
HWADDR=f4:6d:04:16:e0:46
DEVICE=enp2s0
ONBOOT=yes
IPADDR=192.168.2.36
PREFIX=24
GATEWAY=192.168.2.11
DNS1=192.168.3.224
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
BRIDGE=br0

END


systemctl stop ModemManager.service
yum remove ModemManager
systemctl start network.service



WebVirtMgr配置

1、配置epel源(已配置则忽略)
# cd /usr/local/src
# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm –ivh epel-release-6-8.noarch.rpm
2、安装所需包
# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx
3、# vim /etc/sysconfig/libvirtd—去掉注释
    LIBVIRTD_ARGS="--listen"
4、# vim /etc/libvirt/libvirtd.conf—去掉注释
    listen_tls = 0
    listen_tcp = 1
    tls_port = "16514"
    tcp_port = "16509"
    listen_addr = "0.0.0.0"
    auth_tcp = "sasl"
#/etc/init.d/libvirtd restart
5、创建libvirt管理用户
# saslpasswd2 -a libvirt virtadmin       //添加实例账号
# sasldblistusers2 -f /etc/libvirt/passwd.db
    virtadmin@webvirt: userPassword
# saslpasswd2 -a libvirt -d virtadmin        //禁止virtadmin用户
6、WebVirtMgr安装及初始化配置
通过git克隆WebVirtMgr代码,并安装需要的Python组件
# cd /usr/local/src/
# git clone git://github.com/retspen/webvirtmgr.git
# cd webvirtmgr
# pip install -r requirements.txt
安装python-sqlite
# yum install python-sqlite2
对django进行环境配置
# ./manage.py syncdb          //设置账号密码邮箱,此账号可以登录webvirtmgr
#./manage.py collectstatic            //生成配置文件
#./manage.py createsuperuser             //添加管理员账号,此账号同样可以登录webvirtmgr
7、将WebVirtMgr复制到nginx网站根目录
# mkdir /var/www/
# cp -a /usr/local/src/webvirtmgr /var/www/
# chown -R nginx:nginx /var/www/webvirtmgr
8、配置nginx
# vim /etc/nginx/conf.d/webvirtmgr.conf
add:
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
    }
}
# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
# /etc/init.d/nginx start
# chkconfig nginx on
9、配置supervisor
# vim /etc/supervisord.conf     //add in the end
[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
#/var/www/webvirtmgr/conf/gunicorn.conf.py
modify:
    bind = "0:8000"
# /etc/init.d/supervisord start
# chkconfig supervisord on
10、查看端口6080和8000是否已经启动
#netstat -ntlp | grep 6080
#netstat -ntlp | grep 8000
11、测试
# virsh -c qemu+tcp://127.0.0.1/system nodeinfo
Please enter your authentication name: virtadmin
Please enter your password: xxxxxx
CPU model:             x86_64
CPU(s):                   1
CPU frequency:       1599 MHz
CPU socket(s):        1
Core(s) per socket: 1
Thread(s) per core: 1
NUMA cell(s):           1
Memory size:            1907936 kB
12、访问
192.168.2.35