#!/bin/bash#+++++++++++++++++++++++++++++++++++++++++++++++++++++++安装配置kvm并创建虚拟机+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#验证cpu是否支持kvmegrep ‘(vmx|svm)‘ /proc/cpuinfo #然后需要在bios设置中打开cpu virtual technology!!!!!!!#关闭selinuxvi /etc/sysconfig/selinuxselinux=disabled#关闭防火墙systemctl stop firewalldsystemctl disable firewalld#更换yum源(可选,一般不用换)mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backupwget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repoyum 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 libvirtdsystemctl enable libvirtd#配置网络桥接模式#手动修改 ?配置网桥模式,先将 /etc/sysconfig/network-scripts/ 目录下的网卡配置文件备份一份(不要备在当前目录以及子目录下,其他目录随意)#a. 创建 ifcfg-br0 文件,内容如下:BOOTPROTO=staticDEVICE=br0TYPE=BridgeNM_CONTROLLED=noIPADDR=192.168.1.95NETMASK=255.255.255.0GATEWAY=192.168.1.1DNS1=61.177.7.1DNS2=8.8.8.8#b. 移除掉原来的 ifcfg-enp0s25 ,重新创建该文件,内容如下:BOOTPROTO=noneDEVICE=enp0s25NM_CONTROLLED=noONBOOT=yesBRIDGE=br0#c.重启网络服务systemctl restart network#安装虚拟机 #准备虚拟机镜像文件,把该文件放到 /home/iso(没有可创建)目录下#创建虚拟机mkdir -p /home/kvm-bakvirt-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 firewalldsystemctl disable firewalld#关闭selinuxvi /etc/sysconfig/selinuxselinux=disabled#用vnc连接虚拟机,进行虚拟机操作系统的安装#手动启动虚拟机virsh list --allvirsh 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 nginxyum -y install gcc python-devel#更换pip源vi ~/.pip/pip.conf[global]index-url = https://pypi.douban.com/simple#安装numpypip install numpy#下载webvirtmgr源码 from gitmkdir /application/cd /application/git clone git://github.com/retspen/webvirtmgr.git #sqlite3数据库安装 cd /application/wget http://www.sqlite.org/sqlite-3.5.6.tar.gzcd sqlite-3.5.6/./configure --disable-tcl ?makemake install #webvirtmgr安装cd /application/webvirtmgrpip install -r requirements.txt./manage.py syncdb ?./manage.py collectstatic ./manage.py createsuperuser ?#创建super用户 ?可选#webvirtmgr配置mkdir -pv /var/wwwcp -Rv /application/webvirtmgr /var/www/webvirtmgrvim /etc/nginx/conf.d/webvirtmgr.confserver {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 /varexpires 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.servicesystemctl enable nginx.service*/9-/*#kvm被管理端配置vi /etc/sysconfig/libvirtd ?#取消以下字段的注释LLIBVIRTD_CONFIG=/etc/libvirt/libvirtd.confLIBVIRTD_ARGS="--listen"vi /etc/libvirt/libvirtd.conf ?#取消以下字段的注释并修改listen_tls = 0listen_tcp = 1tcp_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 servernohup /var/www/webvirtmgr/manage.py runserver 0:8000nohup /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上的部署
原文地址:http://www.cnblogs.com/dmj666/p/8031928.html