QEMU-KVM安装KVM
作为虚拟化来用时,与KVM结合,称之为QEMU-KVM。QEMU-KVM是基于硬件虚拟化技术(例如Intel VT ,AMD SVM),并结合了QEMU提供设备虚拟化功能,来实现整个系统虚拟化。
从QEMU-KVM定义来看好像物理计算机系统只能是x86体系结构硬件平台,运行Linux操作系统计算机。
但是任何事物都发展的,将来当QEMU-KVM采用IPS , PPC等硬件虚拟化技术,并且KVM移植到其他操作系统上(FreeBSD等),也是有可能。
1.BIOS开启虚拟化
2.启用kvm模块
#modprobe kvm
关闭防火墙
# systemctl stop firewalld.service
3.功能区分intel/amd的启用
#modprobe kvm-intel
# lsmod | grep kvm
kvm_intel 170181 3
kvm 554609 1 kvm_intel
irqbypass 13503 1 kvm
4.安装kvm
#yum install -y qemu-kvm libvirt virt-manager qemu-kvm-tools
5.安装网桥管理工具tunctl
下载:http://www.rpmfind.net/linux/rpm2html/search.php?query=tunctl
# yum install tunctl-1.5-3.el6.x86_64.rpm
6.挂载U盘,拷贝镜像文件
首先要进入官网下载NTFS-3G工具
http://www.tuxera.com/community/ntfs-3g-download/
6.1.下载之后进行解压
wget http://tuxera.com/opensource/ntfs-3g_ntfsprogs-2014.2.15.tgz
tar -xvf ntfs-3g_ntfsprogs-2014.2.15.tgz
6.2.编译并进行安装
cd ntfs-3g_ntfsprogs-2014.2.15
./configure
make
make install
6.3.挂载NTFS
mount -t ntfs-3g /dev/sda2 /mnt/ckl
6.5.拷贝
cp /mnt/ckl/CentOS-7-x86_64-DVD-1611.iso /root/CentOS-7-x86_64-DVD-1611.iso
7.配置网卡
7.1.会自动启动一个桥设备,这相当于VMware Workstation中的host-only仅主机的网络设备;
# ifconfig
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.3 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::ec4:17fa:8756:5a8f prefixlen 64 scopeid 0x20<link>
ether 00:1d:72:58:6f:93 txqueuelen 1000 (Ethernet)
RX packets 2606 bytes 162013 (158.2 KiB)
RX errors 0 dropped 2269 overruns 0 frame 0
TX packets 177 bytes 16706 (16.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 96 bytes 8308 (8.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 96 bytes 8308 (8.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7e:e7:ca txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
7.2.使用网桥管理命令查看
# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.5254007ee7ca yes virbr0-nic
7.4.需要将NetworkManager服务关闭,开机启动也关闭
# chkconfig NetworkManager off
# service NetworkManager stop
7.5.创建桥接设备及关联网卡到桥接设备上
# virsh iface-bridge ens3 br0
Created bridge br0 with attached device ens3
Bridge interface br0 started
7.6.查看网卡情况
# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.3 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::21d:72ff:fe58:6f93 prefixlen 64 scopeid 0x20<link>
ether 00:1d:72:58:6f:93 txqueuelen 1000 (Ethernet)
RX packets 22 bytes 1636 (1.5 KiB)
RX errors 0 dropped 15 overruns 0 frame 0
TX packets 22 bytes 4045 (3.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:1d:72:58:6f:93 txqueuelen 1000 (Ethernet)
RX packets 522 bytes 34644 (33.8 KiB)
RX errors 0 dropped 341 overruns 0 frame 0
TX packets 148 bytes 16251 (15.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 14 bytes 770 (770.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14 bytes 770 (770.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7e:e7:ca txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
7.7.为GUEST添加虚拟网卡tap10,并加入网桥tap10
# tunctl -t tap10
Set ‘tap10’ persistent and owned by uid 0
# brctl addif br0 tap10
# ifconfig tap10 up
# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.001d72586f93 yes ens3
tap10
virbr0 8000.5254007ee7ca yes virbr0-nic
查看多出tap10
# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.3 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::21d:72ff:fe58:6f93 prefixlen 64 scopeid 0x20<link>
ether 00:1d:72:58:6f:93 txqueuelen 1000 (Ethernet)
RX packets 13615 bytes 6924507 (6.6 MiB)
RX errors 0 dropped 3445 overruns 0 frame 0
TX packets 5742 bytes 7811746 (7.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:1d:72:58:6f:93 txqueuelen 1000 (Ethernet)
RX packets 14517 bytes 7182587 (6.8 MiB)
RX errors 0 dropped 341 overruns 0 frame 0
TX packets 6733 bytes 7868932 (7.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 14 bytes 770 (770.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14 bytes 770 (770.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tap10: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 5a:c7:ec:11:0b:b8 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7e:e7:ca txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
7.8.为虚拟桥接网卡tap10建立配置文件,重启系统时能随系统启动,并加入网桥 br0
# vim /etc/sysconfig/network-scripts/ifcfg-tap10
DEVICE=tap10
TYPE=Tap
ONBOOT=yes
BRIDGE=br0
8.安装vnc
yum install vnc-server tigervnc -y
设置vnc密码
# vncpasswd
9.开始安装kvm
9.1.创建虚拟磁盘目录
# mkdir -pv /home/kvm/image/
9.2.创建虚拟磁盘文件
# qemu-img create -o preallocation=metadata -f qcow2 /home/kvm/image/cent7_1.qcow2 20G
9.3.vnc连接
9.4.安装虚拟机
# /usr/libexec/qemu-kvm -m 512 -smp 1 \
-drive file=/home/kvm/image/cent7_1.qcow2 \
-net nic,vlan=2,model=e1000,macaddr=52:54:00:12:34:56 \
-net tap,vlan=2,ifname=tap10,script=no -boot d \
-cdrom /root/CentOS-7-x86_64-DVD-1611.iso -vnc 192.168.1.3:1 –daemonize
查看进程:
# ps aux | grep kvm
root 605 0.0 0.0 0 0 ? S< 10:26 0:00 [kvm-irqfd-clean]
root 5168 2.8 1.8 941392 34832 ? Sl 11:03 0:00 /usr/libexec/qemu-kvm -m 512 -smp 1 -drive file=/home/kvm/image/cent7_1.qcow2 -net nic,vlan=2,model=e1000,macaddr=52:54:00:12:34:56 -net tap,vlan=2,ifname=tap10,script=no -boot d -cdrom /root/CentOS-7-x86_64-DVD-1611.iso -vnc 192.168.1.3:1 –daemonize
root 5173 0.0 0.0 0 0 ? S 11:03 0:00 [kvm-pit/5168]
root 5234 0.0 0.0 112652 944 pts/1 S+ 11:04 0:00 grep –color=auto kvm
9.5.安装过程
9.6.安装完毕后结束掉kvm进程
# kill -15 5168
9.7.重新启动,启动Guest虚拟机,修改启动方式为硬盘 -boot c ,去除光盘资源
# /usr/libexec/qemu-kvm -m 512 -smp 1 \
-drive file=/home/kvm/image/cent7_1.qcow2 \
-net nic,vlan=2,model=e1000,macaddr=52:54:00:12:34:56 \
-net tap,vlan=2,ifname=tap10,script=no -boot c \
-vnc 192.168.1.3:1 –daemonize
10.安装完成
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-05/143292.htm