KVM(系统虚拟化模块)安装

Kernel-based Virtual Machine的简称 ,是一个开源的系统虚拟化模块,自Linux 2.6.20之后集成在Linux的各个主要发行版本中。它使用Linux自身的调度器进行管理,所以相对于Xen,其核心源码很少。KVM目前已成为学术界的主流VMM之一。
KVM的虚拟化需要硬件支持(如Intel VT技术或者AMD V技术) 。是基于硬件的完全虚拟化。而Xen早期则是基于软件模拟的Para-Virtualization,新版本则是基于硬件支持的完全虚拟化
1.安装要用的软件;安装软件的时,关闭selinux 
安装kvm模块 
#yum install qemu-kvm.x86_64 
安装kvm调试工具(可以不安装) 
#yum install qemu-kvm-tools.x86_64 
安装python组件,主要用来记录创建vm时的xml文件 
#yum install python-virtinst.noarch 
安装qemu组件,使用qemu命令来创建磁盘,启动虚拟机等(这个可能在安装时qemu-kvm.x86_64已安装) 
#yum install qemu-img.x86_64 
安装网络支持工具 
#yum install bridge-utils.x86_64 
安装虚拟机管理工具,使用virsh来管理虚拟机 
#yum install libvirt 
二.汇总:安装软件:
yum -y install qemu-kvm kvm qemu-kvm qemu-img python-virtinst libvirt bridge-utils qemu-kvm-tools virt-viewer virt-v2v tunctl virt-manager libvirt-python kmod-kvm qemu 

三.重新启动libvirtd 
    #/etc/init.d/libvirtd start 
    #ps -e| grep libvirtd 
    30706 ? 00:00:01 libvirtd 
四.检查kvm模块是否安装完成 
    #lsmod | grep kvm 
    会显示两个模块 
    kvm_intel/ kvm_amd 
    kvm 
五.配置网卡桥接 
[ root@localhost  network-scripts]# cat ifcfg-eth0 |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}' 
DEVICE=eth0 
TYPE=Ethernet 
ONBOOT=yes 
BOOTPROTO=none 
BRIDGE=br0 
IPV6INIT=no 
HWADDR=F8:BC:12:60:99:86 
[ root@localhost  network-scripts]# cat ifcfg-br0 |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}' 
DEVICE=br0 
TYPE=Bridge 
ONBOOT=yes 
BOOTPROTO=static 
IPADDR=192.168.10.103 
GATEWAY=192.168.10.1 
NETMASK=255.255.255.0 
DNS1=192.168.10.1 
IPV6INIT=no 
DELAY=0 
#service network restart 
重启网络报错: 
    弹出界面 br0: 错误:激活连接失败:Failed to determine connection's virtual interface name 
解决的方法: 
    #service NetworkManager stop //这个关闭掉就行 
如果以下内容就说明配置成功了: 
[root@station1 network-scripts]# ifconfig 
br0 Link encap:Ethernet HWaddr 5E:0E:C2:8E:CC:E6 
inet addr:192.168.23.89 Bcast:192.168.23.255 Mask:255.255.255.0 
inet6 addr: fe80::5c0e:c2ff:fe8e:cce6/64 Scope:Link 
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0 
collisions:0 txqueuelen:0 
RX bytes:0 (0.0 b) TX bytes:636 (636.0 b) 

eth0 Link encap:Ethernet HWaddr 00:0C:29:EA:5F:9A 
inet addr:10.10.21.13 Bcast:10.10.255.255 Mask:255.255.0.0 
inet6 addr: fe80::20c:29ff:feea:5f9a/64 Scope:Link 
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
RX packets:2995655 errors:0 dropped:0 overruns:0 frame:0 
TX packets:40564 errors:0 dropped:0 overruns:0 carrier:0 
collisions:0 txqueuelen:1000 
RX bytes:302081352 (288.0 MiB) TX bytes:3884529 (3.7 MiB) 
Interrupt:19 Base address:0x2000 

lo Link encap:Local Loopback 
inet addr:127.0.0.1 Mask:255.0.0.0 
inet6 addr: ::1/128 Scope:Host 
UP LOOPBACK RUNNING MTU:16436 Metric:1 
RX packets:80537 errors:0 dropped:0 overruns:0 frame:0 
TX packets:80537 errors:0 dropped:0 overruns:0 carrier:0 
collisions:0 txqueuelen:0 
RX bytes:8967119 (8.5 MiB) TX bytes:8967119 (8.5 MiB) 

virbr0 Link encap:Ethernet HWaddr 52:54:00:B2:93:53 
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
collisions:0 txqueuelen:0 
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 
[ root@station1  network-scripts]# brctl show 
bridge name bridge id STP enabled interfaces 
br0 8000.000c29ea5f9a no eth0 //显示这个ok 
virbr0 8000.525400b29353 yes virbr0-nic 
六、可以用virt-install 生成.img文件;来新建虚拟机了,但是启动后没办法看到所以要安装客户端来管理,也可以用virsh来管理但还要加VNC来连接虚拟机 
①安装VNC 
    #yum install tigervnc-server.x86_64 

改防火墙:还要改一下iptables #vi /etc/sysconfig/iptables 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6900 -j ACCEPT 
#service iptables restart 

②开始新建虚拟机 
[ root@station1  ~]# virt-install --name vmxp1 --ram 1024 --vcpus=1 --disk path=/home/kvm/img/xp1.img,size=20 --network bridge=br0 --os-variant=winxp --cdrom /home/kvm/soft/XP.iso --vnclisten=192.168.1.12 --vncport=6900 --vnc 

[ root@station1  network-scripts]# virt-install --name=ubuntu1 --ram 1024 --vcpus=1 --disk path=/root/ubuntu1.img,size=10 --accelerate --cdrom /root/ubuntu-14.04-desktop-amd64.iso --graphics vnc,port=5920 --network bridge=br0 
报错: 
could not open disk image : Permission denied 
解决方法: 
[ root@localhost  ~]# cat /etc/libvirt/qemu.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'
vnc_listen = "0.0.0.0" 
user = "root" //去掉注释 
group = "root" //去掉注释 
dynamic_ownership = 0 //去掉注释,把1改为0 
这一步做完,系统文件就好了 
七.启动虚拟机 
如果报错: 
[ root@localhost  ~]# virsh start ubuntu1 
错误:域已经活跃 
解决方法: 
[ root@localhost  ~]# pkill qemu-kvm 
[ root@localhost  ~]# virsh start ubuntu1 
域 ubuntu1 已开始 
[ root@localhost  ~]# virt-viewer ubuntu1 //进入图形界面 

或者进入系统; 
应用程序中;找到虚拟系统管理器==>配置新系统
#qemu-img snapshot  #创建虚拟快照
#使用 virsh snapshot-create-as 命令进行生成快照
关闭虚拟机并转换磁盘
#virsh  shutdown  oeltest01   
查看虚拟状态
#virsh list --all
raw格式的不具备快照功能,需要raw镜像转换为qcow2格式,
#qemu-img convert -f raw -O qcow2  100.img 111.img
# qemu-img snapshot -l  test.qcow2  #列出某个镜像的所有快照
#qemu-img snapshot -a snapshot01  test.qcow2#使用快照
附:
  'snapshot' is the name of the snapshot to create, apply or delete
  '-a' applies a snapshot (revert disk to saved state)
  '-c' creates a snapshot
  '-d' deletes a snapshot
  '-l' lists all snapshots in the given image
3 查看虚拟机testsnp已有的快照 
  [root@nc1 boss]# virsh snapshot-list testsnp
4 可以通过snapshot-dumpxml命令查询该虚拟机某个快照的详细配置
[root@nc1 boss]# virsh snapshot-dumpxml testsnp 1315385065
5 查看最新的快照信息
  [root@nc1 boss]# virsh snapshot-current testsnp

6 使用快照,指定使用哪一个快照恢复虚拟机
 [root@nc1 boss]# virsh snapshot-revert testsnp snapshot02

7 删除指定快照
  [root@nc1 boss]# virsh snapshot-delete testsnp snapshot02

转载于:https://www.cnblogs.com/wangyao3568/p/7675774.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值