`
guoyu841020
  • 浏览: 7116 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Linux下实现网卡绑定(负载均衡和冗余备份)

阅读更多
1 创建网卡配置文件,通过绑定获得的逻辑(虚拟)网卡的名称为bondx,其中x取值0,1,1,...,对于第一组绑定,逻辑网卡的名称为bond0,对应的配置文件为/etc/sysconfig/network-scripts/ifcfg-bond0
#cd /etc/sysconfig/network-scripts
#cp ifcfg-eth0 ifcfg-bond0
2 修改逻辑网卡的配置文件ifcfg-bond0
#vi ifcfg-bond0
device=bond0
bootproto=static
onboot=yes
broadcast=ipaddress
ipadds=
netmask=
network=
gateway=
userctl=no
type=Ethernet
网卡绑定后,只能在逻辑网卡上配置IP地址,参与绑定的物理网卡不要配置IP地址信息,并删除网卡MAC地址
3 配置ifcfg-eth0和ifcfg-eth1
#vi ifcfg-eth0
device=eth0
bootproto=none
onboot=yes
type=Ethernet
#vi ifcfg-eth1
device=eth1
bootproto=dhcp
onboot=yes
type=Ethernet
4 加载bonding模块
编辑修改/etc/modprobe.conf文件,加入以下内容,使Linux启动时加载bonding模块,支持bond0设备名
alias bond0 bonding
option bond0 miimon=100 mode=0
miimon用于指定每隔多少毫秒(ms)监测一次主机到交换机的链路的连接状态。mode设置绑定的工作模式,其取值为0~6,最常用的主要是0和1模式。0代表负载均衡(balance-rr)模式,1代表冗余备份(active-backup)模式。
       插曲:modinfo bonding命令可查询内核是否支持bonding模块
5 配置网卡绑定
#ifenslave bond0 eth0 eth1
通常将该命令添加到/etc/rc.local配置文件
#echo 'ifenslave bond0 eth0 eth1'>>/etc/rc.local
       注意:bond0、eth0和eth1网卡的MAC地址都会被系统设置为第一个Slave网卡的MAC地址,即eth0网卡的MAC地址。
                                          大功告成!
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics