Centos 6.5安装配置KVM
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos 6.5安装配置KVM相关的知识,希望对你有一定的参考价值。
1 egrep --color=auto 'vmx|svm' /proc/cpuinfo2 yum install kvm qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools virt-viewer
3 modprobe -a kvm kvm_intel (Bios里面先开启虚拟化)
4 yum -y upgrade device-mapper-libs
5 service libvirtd start
6 chkconfig libvirtd on
7 新建虚拟机,磁盘方面设置:
然后进入桌面使用图形化操作,新建虚拟机的时候。
存储:配置存储的时候选择大的分区(编辑---链接详细---存储---添加池---新建卷---选择qcow2格式,只有这个格式才能做快照),默认是选择根分区的存储池的。
设置存储池参考:http://www.3566t.com/news/nosb/1493020.html http://xiangcun168.blog.51cto.com/4788340/1680498
8 网络方面设置
网络:默认是NAT模式,物理机会有一个virbr0网卡192.168.122.1,虚拟机也是这个网段的192.168.122.133。
需要给虚拟机配置NAT上网。
需要给虚拟机配置iptables端口转发。
物理机防火墙配置文件如下:
# Generated by iptables-save v1.4.7 on Thu Mar 23 18:07:55 2017
*filter
:INPUT ACCEPT [1224:109875]
:FORWARD ACCEPT [1125:176375]
:OUTPUT ACCEPT [415:56424]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8732 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 465 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 993 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 995 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 99 -j ACCEPT
COMMIT
# Completed on Thu Mar 23 18:07:55 2017
# Generated by iptables-save v1.4.7 on Thu Mar 23 18:07:55 2017
*mangle
:PREROUTING ACCEPT [3600:428906]
:INPUT ACCEPT [1376:127143]
:FORWARD ACCEPT [1448:225520]
:OUTPUT ACCEPT [463:60779]
:POSTROUTING ACCEPT [1902:285843]
-A POSTROUTING -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
COMMIT
# Completed on Thu Mar 23 18:07:55 2017
# Generated by iptables-save v1.4.7 on Thu Mar 23 18:07:55 2017
*nat
:PREROUTING ACCEPT [1239:116781]
:POSTROUTING ACCEPT [6:484]
:OUTPUT ACCEPT [6:484]
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.122.133:80
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 8732 -j DNAT --to-destination 192.168.122.133:8732
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 25 -j DNAT --to-destination 192.168.122.133:25
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 110 -j DNAT --to-destination 192.168.122.133:110
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 143 -j DNAT --to-destination 192.168.122.133:143
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 443 -j DNAT --to-destination 192.168.122.133:443
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 465 -j DNAT --to-destination 192.168.122.133:465
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 993 -j DNAT --to-destination 192.168.122.133:993
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 995 -j DNAT --to-destination 192.168.122.133:995
-A POSTROUTING -o eth0 -j MASQUERADE
-A PREROUTING -d 192.168.1.107/32 -p tcp -m tcp --dport 99 -j DNAT --to-destination 192.168.122.133:99
-A POSTROUTING -o eth0 -j MASQUERADE
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p udp -j MASQUERADE --to-ports 1024-65535
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -j MASQUERADE
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 80 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 8732 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 25 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 110 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 143 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 443 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 465 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 993 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 995 -j SNAT --to-source 192.168.122.1
-A POSTROUTING -s 192.168.122.0/24 -d 192.168.122.133/32 -p tcp -m tcp --dport 99 -j SNAT --to-source 192.168.122.1
COMMIT
# Completed on Thu Mar 23 18:07:55 2017
/etc/init.d/iptables restart
重启服务器,测试虚拟机能否上网,其他电脑能否用物理机的IP地址访问虚拟机的web服务。
设置NAT网络参考:http://blog.chinaunix.net/uid-21710354-id-4467679.html
9、查看虚拟机
查看虚拟机:virsh list
查看umail虚拟机的快照:virsh snapshot-list umail
创建umail虚拟机的快照:virsh snapshot-create-as umail umail_webmail-1.6.41-1.el6.x86_64_umail_app-2.2.25-1.el6.x86_64
以上是关于Centos 6.5安装配置KVM的主要内容,如果未能解决你的问题,请参考以下文章