之前一直用xen,但是随着kvm的崛起,xen行将就木,是时候改弦易辙了。以下是kvm的安装步骤。

服务器硬件:

  • 2 * Intel Xeon(VT-d)

  • 4 * broadcom Gb nic

  • 2 * SAS 300G hardisk

安装

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

如果嫌上面的安装方式不够简洁的话,请用下列命令:

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

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

$ sudo service libvirtd status

如果libvirtd没有启动,则需要先启动messagebusavahi-daemon

$ sudo service messagebus start
$ sudo service avahi-daemon start
$ sudo service libvirtd start

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

网络

  • eth0/eth1做成bond0,通过br0与业务交换机(huawei S5328-1)相连

  • eth2/eth3做成bond1,通过br1与存储交换机(huawei S5328-2)相连

配置网卡

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

配置bonding

$ sudo cat /etc/modprobe.d/bonding.conf
alias bond1 bonding

假如没有bonding.conf文件,则自行创建一个。

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

假如bonding内核模块尚未加载,则手工加载之:

$ sudo modprobe bonding
$ sudo cat ifcfg-bond1
DEVICE=bond1
BRIDGE=br1
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
BONDING_OPTS="mode=4 miimon=80"

配置bridge

$ sudo 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"

最后重启网络:

$ sudo service network restart

检查

$ sudo 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
$ sudo ifconfig br1
$ sudo brctl show

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