WebVirtMgr 基于Centos7.3的KVM虚拟化管理平台安装


KVM是centos下面的虚拟机,是一个比较好用的一种虚拟化技术,可是一般来讲服务器跑Centos不多会安装图形界面,使用命令来管理虚拟机也是比较麻烦的,因此有一种web的虚拟化管理平台就很方便了。css


安装环境,Centos7.3,硬件Dell R710,3块1TB硬盘作阵列5python


安装KVM部分linux


一、首先,对服务器Bios开启虚拟化支持,ios

而后,查看服务器CPU是否支持虚拟化,通常服务器都会支持,能够看到是支持的nginx

[root@localhost ~]# egrep '(svm|vmx)' /proc/cpuinfo

191ec04b9e6850b71fe37c0e5471ae0a.png-wh_


二、关闭Selinux,设置selinux=disabledgit

[root@localhost ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted


三、最后安装kvm
github

[root@localhost ~]# yum install qemu-kvm libvirt virt-install bridge-utils -y

设置开机启动
web

[root@localhost ~]# systemctl enable libvirtd.service 
[root@localhost ~]# systemctl start libvirtd.service


四、配置网卡桥接,这样kvm虚拟机就可使用物理机网段了数据库

编辑物理网卡
django

[root@localhost network-scripts]# vim ifcfg-em1
BRIDGE=br0        #增长这段br0是桥接网卡名字
BOOTPROTO=none
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=em1
UUID=db488d6c-f2bd-4162-91b0-b093da627043
DEVICE=em1
ONBOOT=yes            #设置网卡启用

拷贝一份em1配置文件更名成br0

[root@localhost network-scripts]# cp ifcfg-em1 ifcfg-br0
TYPE=Bridge        #增长这段
BOOTPROTO=none
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=br0            #名字改为br0
DEVICE=br0            #名字改为br0
ONBOOT=yes            #设置网卡启用
IPADDR=192.168.30.4    #设置IP,这是物理机IP
NETMASK=255.255.255.0
GATEWAY=192.168.30.1
DNS1=8.8.8.8

配置完成重启网卡,配置成功

[root@localhost network-scripts]# ifconfig 
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.30.4  netmask 255.255.255.0  broadcast 192.168.30.255
        inet6 fe80::97ef:e8ee:ec13:7b67  prefixlen 64  scopeid 0x20<link>
        ether 00:24:e8:79:5f:9a  txqueuelen 1000  (Ethernet)
        RX packets 94700  bytes 38161377 (36.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 52912  bytes 24224444 (23.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:24:e8:79:5f:9a  txqueuelen 1000  (Ethernet)
        RX packets 115799  bytes 70980112 (67.6 MiB)
        RX errors 0  dropped 6  overruns 0  frame 0
        TX packets 74826  bytes 26101223 (24.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


KVM部分到此基本完成了


WebVirtMgr安装部分


一、安装依赖包

yum -y install git python-pip libvirt-python libxml2-python python-websockify python-devel
pip install numpy


二、下载程序代码webvirtmgr


[root@localhost]# git clone git://github.com/retspen/webvirtmgr.git        #clone代码
[root@localhost]# mv webvirtmgr/ /var/www/                                #移动到/var/www目录
[root@localhost ~]# cd /var/www/webvirtmgr/
[root@localhost webvirtmgr]# pip install -r requirements.txt                #安装依赖

初始化数据库,配置管理用户

[root@localhost webvirtmgr]# ./manage.py syncdb
WARNING:root:No local_settings file found.
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table servers_compute
Creating table instance_instance
Creating table create_flavor

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'): root        #管理帐号
Email address: 
Password:                                         #管理密码
Password (again): 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 6 object(s) from 1 fixture(s)


下一步,选yes

[root@localhost webvirtmgr]# ./manage.py collectstatic
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
Copying '/var/www/webvirtmgr/webvirtmgr/static/css/bootstrap-multiselect.css'
Copying '/var/www/webvirtmgr/webvirtmgr/static/css/bootstrap.min.css'
Copying '/var/www/webvirtmgr/webvirtmgr/static/css/signin.css'
Copying '/var/www/webvirtmgr/webvirtmgr/static/css/table-sort.css'
Copying '/var/www/webvirtmgr/webvirtmgr/static/css/webvirtmgr.css'
Copying '/var/www/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.eot'
Copying '/var/www/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.svg'
Copying '/var/www/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.ttf'
Copying '/var/www/webvirtmgr/webvirtmgr/static/fonts/glyphicons-halflings-regular.woff'
Copying '/var/www/webvirtmgr/webvirtmgr/static/img/asc.gif'


添加额外管理用户,选作

[root@localhost webvirtmgr]# ./manage.py createsuperuser


三、配置nginx,安装nginx过程略


配置虚拟主机站点,配置以下

server {
    listen 80 default_server;

    server_name $hostname;
    access_log /var/log/nginx/webvirtmgr_access_log; 

    location /static/ {
        root /var/www/webvirtmgr/webvirtmgr; 
        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; 
    }
}

而后启动nginx


四、启动webvirtmgr程序和webvirtmgr-console

   nohup /usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn 127.0.0.1:8000 &
   nohup /usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-console &


防火墙部分

    firewall-cmd --permanent --add-port=80/tcp
    firewall-cmd --permanent --add-port=6080/tcp
    firewall-cmd  --permanent  --add-port=5900/tcp
    firewall-cmd  --permanent  --add-port=5901/tcp        #控制台端口,能够多
                                                          #开放几个5900起
    firewall-cmd --reload


打开管理界面,

b3fedbe84a39df9007edc5248898a44a.png-wh_



webvirtmgr管理部分


一、登录上去,须要添加被管理主机,这里是空的,咱们要添加被管理的KVM主机是本机,只要作ssh免密码登录便可

[root@localhost ~]# ssh-keygen -t rsa
[root@localhost ~]# ssh-copy-id 192.168.30.4


登录默认是空的


3e4510fd4cf38386767cc434a7e3c858.png-wh_


添加链接,选ssh链接

9cac2cf3cbce7b3773d26a9e7cbef455.png-wh_


添加成功后就到这里了,这里我建立过一台虚拟机

6c6c93f4c2f91ba90630c6924e4fbc41.png-wh_


建立虚拟机前咱们须要建立一个存储池,也就是虚拟机磁盘存放位置


4c2def3006f9175b0d4cc0cb80b858c7.png-wh_


建立目录类型卷

844a9f1f6f1af6f0324471b096d97d7d.png-wh_


再添加一个ISO镜像卷,安装磁盘镜像就放这里

fab73c4ac35fb251346e6a1108f57b33.png-wh_


这是网络接口部分,我以前建立的桥接端口br0就显示在这里了


8efa953156386f679481be9be6d46731.png-wh_


再来建立一个叫offices的网络池


b0f1f6f429d2bbff0394c484833950aa.png-wh_


建立完成了

16bf82284b491ad44a52ec84217b5066.png-wh_


咱们再到存储池里面给咱们要建立的虚拟机划一个50G的磁盘

点击storage池进去添加镜像,  注意,勾选Metadata就会真的建立一个50G的文件


c9d583b7d59aea822b16aa5b3ade62c2.png-wh_

建立完成

c83a50f3eb08534b17abd49857f16fef.png-wh_


接下来能够建立虚拟机了,选择newinstance

注意,这里的temple是没用的    ,点击custom instance

f0c6354da26632c3cfed1dfe4484f6e2.png-wh_


主要设置名字,cpu、内存,还有刚才建立的磁盘镜像hugw.img和网络池offices桥接


5fc9b84e746a413a0b098aeac9e0e777.png-wh_


建立完成以后点击虚拟机名字能够进入管理


42391623cb9b02b8d8426d1e21cb6eef.png-wh_


这里是链接控制台


ae38bc99327401bda28192fb4eee25a9.png-wh_


在这里选择安装磁盘ISO,装系统的时候若是提示找不到安装介质在这里点链接就好了

6a1cb9f462d415dd8bacd483b9f3bfcf.png-wh_


开机启动,点击重制台链接安装系统,就能够正常管理虚拟机了


7843da4b5a99472aad914eb1a5bd0442.png-wh_

到此结束

相关文章
相关标签/搜索