在CentOS6.3中安装KVM

产品实验室服务器之前安装的是xen,kvm作为后起之秀也值得测试一下,于是将其中一台服务器格了,重装CentOS6和kvm。

服务器硬件:

  • 2 * Intel Xeon(支持虚拟化)
  • 4 * broadcom千兆网卡
  • 2 * SAS 300G硬盘

安装

# yum -y groupinstall Virtualization "Virtualization Client" \
                      "Virtualization Platform" \
                      "Virtualization Tools"
# yum -y install libguestfs-tools

这种安装方式还是不够简洁,可以尝试以下方式:

# yum -y install qemu-kvm libvirt python-virtinst bridge-utils
# modprobe kvm
# modprobe kvm_intel # if AMD, "kvm_amd"
# /etc/init.d/libvirtd start

安装完之后需重启相关服务:

# service libvirtd status

如果libvirtd没有启动,需要先启动messagebus和avahi-daemon

# service messagebus start
# service avahi-daemon start
# service libvirtd start

至此,KVM的安装就结束了,非常简单。不过在生产环境中还需要考虑网络和存储,相对复杂一些,网络拓扑环境如下:

网络

  • eth0/eth1做成bond0,通过br0与业务交换机(huawei S5328-1)相连
  • eth2/eth3做成bond1,通过br1与存储交换机(huawei S5328-2)相连

以下是网络配置

配置网卡

# cat ifcfg-eth2
DEVICE="eth2"
TYPE="Ethernet"
BOOTPROTO="none"
ONBOOT="yes"
USERCTL="no"
MASTER="bond1"
SLAVE="yes"
NM_CONTROLLED="no"
# cat ifcfg-eth3
DEVICE="eth3"
TYPE="Ethernet"
BOOTPROTO="none"
ONBOOT="yes"
USERCTL="no"
MASTER="bond1"
SLAVE="yes"
NM_CONTROLLED="no"

配置bonding

# cat /etc/modprobe.d/bonding.conf 
alias bond1 bonding

假如没有/etc/modprobe.d/bonding.conf,就自己创建一个。

# lsmod | grep bonding
bonding               127060  0 
8021q                  25058  1 bonding
ipv6                  322541  78 bonding,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6

假如bonding还没有加载,那就手工加载。

# modprobe bonding

[root@RH2285-4 network-scripts]# cat ifcfg-bond1
DEVICE=bond1
BRIDGE=br1
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
BONDING_OPTS="mode=4 miimon=80"

配置bridge

# cat ifcfg-br1
DEVICE="br1"
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.55.232
NETMASK=255.255.255.0
NETWORK=192.168.55.0
NM_CONTROLLED="no"

最后重启网络:

# service network restart

检查

# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 80
Up Delay (ms): 0
Down Delay (ms): 0

802.3ad info
LACP rate: slow
Aggregator selection policy (ad_select): stable
Active Aggregator Info:
        Aggregator ID: 3
        Number of ports: 2
        Actor Key: 17
        Partner Key: 305
        Partner Mac Address: 54:89:98:73:bb:07

Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 3c:d9:2b:fd:39:f0
Aggregator ID: 3
Slave queue ID: 0

Slave Interface: eth3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 3c:d9:2b:fd:39:f2
Aggregator ID: 3
Slave queue ID: 0
# ifconfig br1
# brctl show

网络配置完成之后,可从其它机器ssh登录br1的ip地址,测试网络是否可正常工作。