1. 程式人生 > >kvm+webvirtmgr在centos7上的部署

kvm+webvirtmgr在centos7上的部署

url 硬盤 重新 top client mir lis listen 一份

#!/bin/bash
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++安裝配置kvm並創建虛擬機+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#驗證cpu是否支持kvm
egrep (vmx|svm) /proc/cpuinfo 

#然後需要在bios設置中打開cpu virtual technology!!!!!!!

#關閉selinux
vi /etc/sysconfig/selinux
selinux=disabled

#關閉防火墻
systemctl stop firewalld
systemctl disable firewalld

#更換yum源(可選,一般不用換)
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum makecache #安裝依賴環境 yum install epel-release net-tools vim unzip zip wget ftp -y #安裝kvm及其依賴項 yum install qemu-kvm libvirt virt-install bridge-utils -y #驗證安裝結果
lsmod | grep kvm #開啟kvm服務,並且設置其開機自動啟動 systemctl start libvirtd systemctl enable libvirtd #配置網絡橋接模式 #手動修改 配置網橋模式,先將 /etc/sysconfig/network-scripts/ 目錄下的網卡配置文件備份一份(不要備在當前目錄以及子目錄下,其他目錄隨意) #a. 創建 ifcfg-br0 文件,內容如下: BOOTPROTO=static DEVICE=br0 TYPE=Bridge NM_CONTROLLED=no IPADDR=192.168.1.95 NETMASK=255.255
.255.0 GATEWAY=192.168.1.1 DNS1=61.177.7.1 DNS2=8.8.8.8 #b. 移除掉原來的 ifcfg-enp0s25 ,重新創建該文件,內容如下: BOOTPROTO=none DEVICE=enp0s25 NM_CONTROLLED=no ONBOOT=yes BRIDGE=br0 #c.重啟網絡服務 systemctl restart network #安裝虛擬機 #準備虛擬機鏡像文件,把該文件放到 /home/iso(沒有可創建)目錄下 #創建虛擬機 mkdir -p /home/kvm-bak virt-install -n xiaocanan_media -r 4096 --vcpus=4 --os-type=linux --accelerate -c /home/iso/CentOS-7-x86_64-Minimal-1611.iso --disk path=/home/vmdisk_pool/xiaocanan_media.img,format=qcow2,bus=ide --network bridge=br0 --vnc --vncport=5993 --vnclisten=0.0.0.0 --force --autostart #關閉防火墻 systemctl stop firewalld systemctl disable firewalld #關閉selinux vi /etc/sysconfig/selinux selinux=disabled #用vnc連接虛擬機,進行虛擬機操作系統的安裝 #手動啟動虛擬機 virsh list --all virsh start virt-centos #++++++++++++++++++++++++++++++++++++++++++++++++++++++++安裝配置webvirtmgr+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #yum源的配置及所需軟件包 yum -y install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm #repo源,可選 yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx yum -y install gcc python-devel #更換pip源 vi ~/.pip/pip.conf [global] index-url = https://pypi.douban.com/simple #安裝numpy pip install numpy #下載webvirtmgr源碼 from git mkdir /application/ cd /application/ git clone git://github.com/retspen/webvirtmgr.git #sqlite3數據庫安裝 cd /application/ wget http://www.sqlite.org/sqlite-3.5.6.tar.gz cd sqlite-3.5.6/ ./configure --disable-tcl make make install #webvirtmgr安裝 cd /application/webvirtmgr pip install -r requirements.txt ./manage.py syncdb ./manage.py collectstatic ./manage.py createsuperuser #創建super用戶 可選 #webvirtmgr配置 mkdir -pv /var/www cp -Rv /application/webvirtmgr /var/www/webvirtmgr vim /etc/nginx/conf.d/webvirtmgr.conf 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 } } #確保bind綁定的端口是本機的8000端口 grep ^bind = /var/www/webvirtmgr/conf/gunicorn.conf.py #註釋掉 /etc/nginx/nginx.conf server內容 systemctl restart nginx.service systemctl enable nginx.service */9-/* #kvm被管理端配置 vi /etc/sysconfig/libvirtd #取消以下字段的註釋 LLIBVIRTD_CONFIG=/etc/libvirt/libvirtd.conf LIBVIRTD_ARGS="--listen" vi /etc/libvirt/libvirtd.conf #取消以下字段的註釋並修改 listen_tls = 0 listen_tcp = 1 tcp_port = "16509" listen_addr = "0.0.0.0" auth_tcp = "none" systemctl restart libvirtd.service #設置ssh免密登錄 1. vi /etc/ssh/sshd_config RSAAuthentication yes #新版本ssh可能不需要配置此項   PubkeyAuthentication yes   AuthorizedKeysFile .ssh/authorized_keys 2.重啟sshd服務:systemctl restart sshd 3.生成證書公私鑰 ssh-keygen -t dsa -P ‘‘ -f ~/.ssh/id_dsa cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys 4.chmod 600 ~/.ssh/authorized_keys #免密登錄遠程服務器 cat ~/.ssh/id_rsa.pub | ssh 遠程用戶名@遠程服務器ip ‘cat - >> ~/.ssh/authorized_keys‘ #啟動webvirtmgr server nohup /var/www/webvirtmgr/manage.py runserver 0:8000 nohup /var/www/webvirtmgr/console/webvirtmgr-console #設置webvirtmgr和webvirtmgr-console開機自啟動腳本 nohup /var/www/webvirtmgr/manage.py runserver 0:8000 & nohup /var/www/webvirtmgr/console/webvirtmgr-console & #切記!!!! webvirtmgr第一次一定要手動運行,不然會提示密碼驗證失敗 #切記!!!! 使用webvirtmgr創建windows虛擬機時不能選virtio,因為沒有相應驅動的話,硬盤和網卡都會無法識別 #webvirtmgr web地址 http://本機ip:8000 #windows server 2008 r2 激活 www.xpgod.com/soft/12388.html

kvm+webvirtmgr在centos7上的部署