使用bond实现网卡聚合链路脚本:
[plain] view plain copy print?
#!/bin/bash
#创建一个名为bond0的链路接口
IP=192.168.101.1
GATE=192.168.101.254
ETH1=eno1
ETH2=eno2
ETH3=eno3
ETH4=eno4
modprobebonding
cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
TYPE=Bond
NAME=bond0
BONDING_MASTER=yes
BOOTPROTO=static
USERCTL=no
ONBOOT=yes
IPADDR=$IP
PREFIX=24
GATEWAY=$GATE
BONDING_OPTS="mode=1miimon=100"
EOF
cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-bond1
DEVICE=bond1
TYPE=Bond
NAME=bond1
BONDING_MASTER=yes
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
BONDING_OPTS="mode=1miimon=100"
EOF
cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH1
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$ETH1
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF
cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH2
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$ETH2
ONBOOT=yes
MASTER=bond0
SLAVE=yes
EOF
cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH3
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$ETH3
ONBOOT=yes
MASTER=bond1
SLAVE=yes
EOF
cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH4
TYPE=Ethernet
BOOTPROTO=none
DEVICE=$ETH4
ONBOOT=yes
MASTER=bond1
SLAVE=yes
EOF
systemctlrestartnetwork
ping$GATE-c1
reboot
#!/bin/bash #创建一个名为bond0的链路接口 IP=192.168.101.1 GATE=192.168.101.254 ETH1=eno1 ETH2=eno2 ETH3=eno3 ETH4=eno4 modprobebonding cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 TYPE=Bond NAME=bond0 BONDING_MASTER=yes BOOTPROTO=static USERCTL=no ONBOOT=yes IPADDR=$IP PREFIX=24 GATEWAY=$GATE BONDING_OPTS="mode=1miimon=100" EOF cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-bond1 DEVICE=bond1 TYPE=Bond NAME=bond1 BONDING_MASTER=yes USERCTL=no BOOTPROTO=none ONBOOT=yes BONDING_OPTS="mode=1miimon=100" EOF cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH1 TYPE=Ethernet BOOTPROTO=none DEVICE=$ETH1 ONBOOT=yes MASTER=bond0 SLAVE=yes EOF cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH2 TYPE=Ethernet BOOTPROTO=none DEVICE=$ETH2 ONBOOT=yes MASTER=bond0 SLAVE=yes EOF cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH3 TYPE=Ethernet BOOTPROTO=none DEVICE=$ETH3 ONBOOT=yes MASTER=bond1 SLAVE=yes EOF cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH4 TYPE=Ethernet BOOTPROTO=none DEVICE=$ETH4 ONBOOT=yes MASTER=bond1 SLAVE=yes EOF systemctlrestartnetwork ping$GATE-c1 reboot
验证:
1.查看bond0状态:
[plain] view plain copy print?
[root@localhost~]#cat/proc/net/bonding/bond0
EthernetChannelBondingDriver:v3.7.1(April27,2011)
BondingMode:fault-tolerance(active-backup)
PrimarySlave:None
CurrentlyActiveSlave:eno2#当前主接口
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0
SlaveInterface:eno2
MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:2c:76:8a:51:d2:09
SlavequeueID:0
SlaveInterface:eno1
MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:2c:76:8a:51:d2:08
SlavequeueID:0
[root@localhost~]#cat/proc/net/bonding/bond0 EthernetChannelBondingDriver:v3.7.1(April27,2011) BondingMode:fault-tolerance(active-backup) PrimarySlave:None CurrentlyActiveSlave:eno2#当前主接口 MIIStatus:up MIIPollingInterval(ms):100 UpDelay(ms):0 DownDelay(ms):0 SlaveInterface:eno2 MIIStatus:up Speed:1000Mbps Duplex:full LinkFailureCount:0 PermanentHWaddr:2c:76:8a:51:d2:09 SlavequeueID:0 SlaveInterface:eno1 MIIStatus:up Speed:1000Mbps Duplex:full LinkFailureCount:0 PermanentHWaddr:2c:76:8a:51:d2:08 SlavequeueID:0
2.测试,宕掉当前主接口,看是否切换
[plain] view plain copy print?
[root@localhost~]#ifdowneno2
Device'eno2'successfullydisconnected.
[root@localhost~]#cat/proc/net/bonding/bond0
EthernetChannelBondingDriver:v3.7.1(April27,2011)
BondingMode:fault-tolerance(active-backup)
PrimarySlave:None
CurrentlyActiveSlave:eno1#切换成功
MIIStatus:up
MIIPollingInterval(ms):100
UpDelay(ms):0
DownDelay(ms):0
SlaveInterface:eno1
MIIStatus:up
Speed:1000Mbps
Duplex:full
LinkFailureCount:0
PermanentHWaddr:2c:76:8a:51:d2:08
SlavequeueID:0
[root@localhost~]#ifdowneno2 Device'eno2'successfullydisconnected. [root@localhost~]#cat/proc/net/bonding/bond0 EthernetChannelBondingDriver:v3.7.1(April27,2011) BondingMode:fault-tolerance(active-backup) PrimarySlave:None CurrentlyActiveSlave:eno1#切换成功 MIIStatus:up MIIPollingInterval(ms):100 UpDelay(ms):0 DownDelay(ms):0 SlaveInterface:eno1 MIIStatus:up Speed:1000Mbps Duplex:full LinkFailureCount:0 PermanentHWaddr:2c:76:8a:51:d2:08 SlavequeueID:0
详细可参考红帽官网