标签:
目标:构造CentOS6高速虚拟机平台
特点:KVM支持、大页内存、内存预分配、virtio存储设备、桥接网卡(或VFIO直接分配物理网卡)
1 #!/bin/bash 2 mkdir -p /mnt/hugepages 3 mount -t hugetlbfs hugetlbfs /mnt/hugepages 4 sysctl vm.nr_hugepages=2048 5 /*以上内容为Guest机启用2M大页内容支持*/ 6 qemu-system-x86_64 7 -enable-kvm \ /*启用kvm*/ 8 -machine accel=kvm,usb=off \ /*Guest机加速方式选择kvm*/ 9 -cpu host \ /*Guest机cpu特性最大程度继承Host机cpu*/ 10 -smp sockets=1,cores=2,threads=1 \ /*虚拟出1颗物理cpu,这颗物流cpu上有2个核心,每个核心支持1个线程*/ 11 -m 2048 -mem-path /mnt/hugepages -mem-prealloc \ /*内存设置为2G,占用大页内存,而且是预分配,不是动态分配*/ 12 -net nic,model=virtio,macaddr=66:66:66:66:66:66 -net tap,ifname=tap6,script=bridge.sh,downscript=no,vhost=on \ /*桥接方式网卡*/ 13 -boot order=dcn \ /*Guest机启动顺序:光盘、硬盘、网络*/ 14 -drive file=/home/f/Downloads/ISO_files/CentOS_6.8_x64.iso,media=cdrom \ /*指定虚拟存储设备*/ 15 -drive file=C600.img,if=virtio,cache=writeback,media=disk 16 -rtc base=localtime,clock=host \ /*Guest机时钟与Host机保持同步*/ 17 -display none \ /*启动后不显示虚似机画面,可通过SSH连接*/ 18 -monitor stdio /*Qemu monitor管理界面显示在当前输入输出界面*,方面监控、Hotplug及Dynamic Migration/ 19 #-vnc :6 -daemonize /*若选择VNC连接Guest机,则启用本行*,且注释掉17、18行/
bridge.sh内容如下:
1 #!/bin/env bash 2 del_IP() { 3 interfaces=$(ip addr | grep -oP ‘\w+(?=:\s+<)‘ | grep -v ‘lo‘) 4 local y 5 for y in $interfaces 6 do 7 local x 8 local ips=$(ip addr | sed -n "/$y$/p" | grep -oP ‘(\d+\.){3}\d+/\d+‘) 9 for x in $ips 10 do 11 ip addr del $x dev $y 12 done 13 done 14 #All interfaces‘ IPs have been deleted except "lo". 15 } 16 17 set_IP() { 18 brctl addbr br0 19 ip link set br0 up 20 brctl addif br0 eth0 21 ip addr add $ipaddr dev br0 22 if [[ $gateway == "" ]] 23 then 24 x=$(echo $ipaddr | grep -oP ‘(\d+\.){3}(?=\d+\/\d+)‘)1 25 ip route replace default via $x dev br0 26 else 27 ip route replace default via $gateway dev br0 28 #brctl stp br0 on 29 fi 30 } 31 32 echo -n "Your desired IP ? (example: 10.1.0.10/8): " 33 read ipaddr 34 echo -n "Your Gateway ? (example: 10.1.0.1): " 35 read gateway 36 del_IP 37 set_IP 2>/dev/null 38 39 ip link set $1 up 40 sleep 1 41 brctl addif br0 $1
标签:
原文地址:http://www.cnblogs.com/hadex/p/5720742.html