1. 程式人生 > >WebVirtMgr 基於Centos7.3的KVM虛擬化管理平臺安裝

WebVirtMgr 基於Centos7.3的KVM虛擬化管理平臺安裝

cenots7 kvm webvirtmgr 虛擬化平臺


KVM是centos下面的虛擬機,是一個比較好用的一種虛擬化技術,但是通常來說服務器跑Centos很少會安裝圖形界面,使用命令來管理虛擬機也是比較麻煩的,所以有一種web的虛擬化管理平臺就很方便了。


安裝環境,Centos7.3,硬件Dell R710,3塊1TB硬盤做陣列5


安裝KVM部分


1、首先,對服務器Bios開啟虛擬化支持,

然後,查看服務器CPU是否支持虛擬化,一般服務器都會支持,可以看到是支持的

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

技術分享


2、關閉Selinux,設置selinux=disabled

[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


3、最後安裝kvm

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

設置開機啟動

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


4、配置網卡橋接,這樣kvm虛擬機就可以使用物理機網段了

編輯物理網卡

[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安裝部分


1、安裝依賴包

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


2、下載程序代碼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


3、配置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


4、啟動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


打開管理界面,

技術分享



webvirtmgr管理部分


1、登陸上去,需要添加被管理主機,這裏是空的,我們要添加被管理的KVM主機是本機,只要做ssh免密碼登陸即可

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


登陸默認是空的


技術分享


添加連接,選ssh連接

技術分享


添加成功後就到這裏了,這裏我創建過一臺虛擬機

技術分享


創建虛擬機前我們需要創建一個存儲池,也就是虛擬機磁盤存放位置


技術分享


創建目錄類型卷

技術分享


再添加一個ISO鏡像卷,安裝磁盤鏡像就放這裏

技術分享


這是網絡接口部分,我之前創建的橋接端口br0就顯示在這裏了


技術分享


再來創建一個叫offices的網絡池


技術分享


創建完成了

技術分享


我們再到存儲池裏面給我們要創建的虛擬機劃一個50G的磁盤

點擊storage池進去添加鏡像, 註意,勾選Metadata就會真的創建一個50G的文件


技術分享

創建完成

技術分享


接下來可以創建虛擬機了,選擇newinstance

註意,這裏的temple是沒用的 ,點擊custom instance

技術分享


主要設置名字,cpu、內存,還有剛才創建的磁盤鏡像hugw.img和網絡池offices橋接


技術分享


創建完成之後點擊虛擬機名字可以進入管理


技術分享


這裏是連接控制臺


技術分享


在這裏選擇安裝磁盤ISO,裝系統的時候如果提示找不到安裝介質在這裏點連接就行了

技術分享


開機啟動,點擊重制臺連接安裝系統,就可以正常管理虛擬機了


技術分享

到此結束





本文出自 “飛一般的愛情故事” 博客,請務必保留此出處http://niubdada.blog.51cto.com/3511133/1981760

WebVirtMgr 基於Centos7.3的KVM虛擬化管理平臺安裝