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
二、關閉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
打開管理界面,
webvirtmgr管理部分
一、登錄上去,須要添加被管理主機,這裏是空的,咱們要添加被管理的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,裝系統的時候若是提示找不到安裝介質在這裏點鏈接就好了
開機啓動,點擊重製臺鏈接安裝系統,就能夠正常管理虛擬機了
到此結束