##一、编辑虚拟网络接口配置文件,指定网卡IP
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-em1 ifcfg-bond0
[root@localhost network-scripts]# vi ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
IPADDR=10.8.6.30
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
-------------
DEVICE=bond0
BOOTPROTO=static
IPADDR=[IP]
NETMASK=[MASK]
BROADCAST=[BROADCAST]
GATEWAY=[GATEWAY]
ONBOOT=yes
TYPE=Ethernet
##二、配置真实网卡
[root@localhost network-scripts]# vi ifcfg-em3
DEVICE=em3
HWADDR=B8:2A:72:DA:61:D4
TYPE=Ethernet
UUID=f1833de4-39f2-45c8-bb8e-f33bfd0efc54
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=yes
[root@localhost network-scripts]# vi ifcfg-em4
DEVICE=em4
HWADDR=B8:2A:72:DA:61:D5
TYPE=Ethernet
UUID=13f74ea4-dc0b-4af2-a28f-10e3a9c6f2d8
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=yes
##三、加载模块,让系统 支持bonding
[root@localhost network-scripts]# vi /etc/modprobe.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
----------
说明:
mode指定了bond0的工作模式,在redhat中有0-6共7种工作模式,常用的是0和1。
mode=0 表示 load balancing (round-robin)为负载均衡方式,两块网卡都工作。
mode=1 表示 fault-tolerance (active-backup)提供冗余功能,工作方式是主 从的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份。
mode=2 表示 XOR policy 为平衡策略。此模式提供负载平衡和容错能力
mode=3 表示 broadcast 为广播策略。此模式提供了容错能力
mode=4 表示 IEEE 802.3ad Dynamic link aggregation 为 IEEE 802.3ad 为 动态链接聚合。该策略可以通过 xmit_hash_policy 选项从缺省的 XOR 策略改变到其他策略。
mode=5 表示 Adaptive transmit load balancing 为适配器传输负载均衡。该 模式的必要条件:ethtool 支持获取每个 slave 的速率
mode=6 表示 Adaptive load balancing 为适配器适应性负载均衡。该模式包含 了 balance-tlb 模式,同时加上针对 IPV4 流量的接收负载均衡(receive load balance, rlb),而且不需要任何 switch(交换机)的支持。
bonding 只能提供链路监测,即从主机到交换机的链路是否接通。如果只是交换机对 外的链路 down 掉了,而交换机本身并没有故障,那么 bonding 会认为链路没有问题而继 续使用。
----------
##四、增加开机启动脚本
[root@localhost network-scripts]# vi /etc/rc.d/rc.local
ifenslave bond0 em3 em4
#如果eth0和eth1都写了MASTER和SLAVE,则上面的步骤做不做都无所谓
##五、重启
#reboot或者service network restart 都可以看到结果。
[root@localhost network-scripts]# /etc/init.d/network restart
##六、查看绑定在哪张网卡上
[root@localhost network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: em3
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: em3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: b8:2a:72:da:61:d4
Slave queue ID: 0
Slave Interface: em4
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: b8:2a:72:da:61:d5
Slave queue ID: 0
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28572479/viewspace-2130628/
,如需转载,请注明出处,否则将追究法律责任。