ubuntu 下安装KVM虚拟化

来源:互联网 发布:网络女主播视频种子 编辑:程序博客网 时间:2024/05/29 06:41

ubuntu-server 上安装KVM

一:检查CPU是否支持安装 KVM。

egrep -o '(vmx|svm)' /proc/cpuinfo

二:安装KVM所需要的软件包:

apt-get install qemu-kvm libvirt-bin virt-manager bridge-utils

注:virt-manager为GUI管理窗口,bridge-utils:用于网络桥接

三:检查安装是否成功

lsmod | grep kvm

四:拉取镜像

wget http://mirrors.ustc.edu.cn/ubuntu-releases/trusty/ubuntu-14.04.4-server-amd64.iso

qemu-img create -f raw /data1/kvm/data/kvm-20160724-01.img 1024G

五:网卡配置参照:

cat > /etc/network/interfaces <<OEF# The loopback network interfaceauto loiface lo inet loopbackauto eth0iface eth0 inet manualauto eth1iface eth1 inet manualauto br0iface br0 inet staticaddress 118.123.9.86netmask 255.255.255.192gateway 118.123.9.65dns-nameservers 144.114.114.114bridge_ports eth0auto br1iface br1 inet staticaddress 10.10.20.16netmask 255.255.255.0gateway 10.10.20.254bridge_ports eth1OEF

六:虚拟机安装

virt-install --name kvm-20160725-01     --ram 8196     --vcpus=8,sockets=1,cores=8,threads=1     --arch=x86_64     --os-type=linux     --os-variant=ubuntutrusty     --accelerate --cdrom /data8/kvm/images/ubuntu-14.04.4-server-amd64.iso     --boot menu=on     --disk path=/data8/kvm/data/kvm-20160725-01.img,size=500,cache=writeback,device=disk     --network network=default,model=virtio     --graphics vnc,port=-1,listen=0.0.0.0

kvm iptables转发

#!/bin/bashpro='tcp'NAT_Host='125.65.43.197'NAT_Port=3000Dst_Host='10.10.20.100'Dst_Port=22iptables -t nat -A PREROUTING  -m $pro -p $pro  --dport $NAT_Port -j DNAT --to-destination $Dst_Host:$Dst_Portiptables -t nat -A POSTROUTING -m $pro -p $pro --dport $Dst_Port -d $Dst_Host -j SNAT --to-source $NAT_Host#iptables -t nat -A POSTROUTING -j MASQUERADEiptables -I FORWARD -d 192.168.122.0/24 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT

克隆:

virt-clone --original ubuntu-14-tmp --name kvm-20160715-01 --file /data1/kvm/data/kvm-20160715-01.img

在线添加网卡:

virsh attach-interface --domain kvm-20160725-01 --type bridge --source br0 --model virtio --config --live

进入virt-manager

在桌面版的命令窗出入:virt-manager

快速建虚拟机:

修改配置文件:

sudo vim /opt/cd-image/isolinux/isolinux.cfg

# D-I config version 2.0include menu.cfgdefault vesamenu.c32prompt 0timeout 1ui gfxboot bootlogo

sudo vim /opt/cd-image/preseed/ubuntu-bbd-installer.seed
截取修改的部分

# Static network configuration.d-i netcfg/get_nameservers string 10.0.0.1d-i netcfg/get_ipaddress string 10.0.0.171  (只修改此行,为虚拟机ip)d-i netcfg/get_netmask string 255.255.255.0d-i netcfg/get_gateway string 10.0.0.1d-i netcfg/confirm_static boolean true# from being shown, even if values come from dhcp.d-i netcfg/get_hostname string bbdtao01 (虚拟机主机名)d-i netcfg/get_domain string

镜像制作:

mkisofs -r -V "BBD Server Install CD" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ubuntu-bbd-installer-bbdhdp02-net162.iso /opt/cd-image/

创建虚拟机:

virt-install --name bbdhdp02 --hvm --ram 20480 --vcpus 2 --disk path=/data/kvm/bbdhdp02.qcow2,size=100 --bridge=br0 --accelerate --vnc --vncport=5982 --cdrom /home/bbd/ubuntu-bbd-installer-bbdhdp02-net162.iso -d

网址信息:

http://zhidao.baidu.com/link?url=inrg0yVfsi4JF_Okeq06FnMCZDGWUSwoJaK0LwxR7wne4-3hcaxiAFk0fod1DYNnFEbF2VIA9_4Fx1LhO9Z8fdjYMJyPlO8HgTsqQFe-JjS

http://www.linuxidc.com/Linux/2011-03/33653p3.htm

https://wiki.xargs.cn/wiki/doku.php/linux:kvm:kvm%E6%89%8B%E5%86%8C

原创粉丝点击