CentOS 7.2 bond实现网卡聚合链路(双网卡绑定)脚本及验证(适合云平台)

前端之家收集整理的这篇文章主要介绍了CentOS 7.2 bond实现网卡聚合链路(双网卡绑定)脚本及验证(适合云平台)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用bond实现网卡聚合链路脚本:


[plain] view plain copy print?

  1. #!/bin/bash

  2. #创建一个名为bond0的链路接口

  3. IP=192.168.101.1

  4. GATE=192.168.101.254

  5. ETH1=eno1

  6. ETH2=eno2

  7. ETH3=eno3

  8. ETH4=eno4

  9. modprobebonding

  10. cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-bond0

  11. DEVICE=bond0

  12. TYPE=Bond

  13. NAME=bond0

  14. BONDING_MASTER=yes

  15. BOOTPROTO=static

  16. USERCTL=no

  17. ONBOOT=yes

  18. IPADDR=$IP

  19. PREFIX=24

  20. GATEWAY=$GATE

  21. BONDING_OPTS="mode=1miimon=100"

  22. EOF

  23. cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-bond1

  24. DEVICE=bond1

  25. TYPE=Bond

  26. NAME=bond1

  27. BONDING_MASTER=yes

  28. USERCTL=no

  29. BOOTPROTO=none

  30. ONBOOT=yes

  31. BONDING_OPTS="mode=1miimon=100"

  32. EOF

  33. cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH1

  34. TYPE=Ethernet

  35. BOOTPROTO=none

  36. DEVICE=$ETH1

  37. ONBOOT=yes

  38. MASTER=bond0

  39. SLAVE=yes

  40. EOF

  41. cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH2

  42. TYPE=Ethernet

  43. BOOTPROTO=none

  44. DEVICE=$ETH2

  45. ONBOOT=yes

  46. MASTER=bond0

  47. SLAVE=yes

  48. EOF

  49. cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH3

  50. TYPE=Ethernet

  51. BOOTPROTO=none

  52. DEVICE=$ETH3

  53. ONBOOT=yes

  54. MASTER=bond1

  55. SLAVE=yes

  56. EOF

  57. cat<<EOF>/etc/sysconfig/network-scripts/ifcfg-$ETH4

  58. TYPE=Ethernet

  59. BOOTPROTO=none

  60. DEVICE=$ETH4

  61. ONBOOT=yes

  62. MASTER=bond1

  63. SLAVE=yes

  64. EOF

  65. systemctlrestartnetwork

  66. ping$GATE-c1

  67. 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?

  1. [root@localhost~]#cat/proc/net/bonding/bond0

  2. EthernetChannelBondingDriver:v3.7.1(April27,2011)

  3. BondingMode:fault-tolerance(active-backup)

  4. PrimarySlave:None

  5. CurrentlyActiveSlave:eno2#当前主接口

  6. MIIStatus:up

  7. MIIPollingInterval(ms):100

  8. UpDelay(ms):0

  9. DownDelay(ms):0

  10. SlaveInterface:eno2

  11. MIIStatus:up

  12. Speed:1000Mbps

  13. Duplex:full

  14. LinkFailureCount:0

  15. PermanentHWaddr:2c:76:8a:51:d2:09

  16. SlavequeueID:0

  17. SlaveInterface:eno1

  18. MIIStatus:up

  19. Speed:1000Mbps

  20. Duplex:full

  21. LinkFailureCount:0

  22. PermanentHWaddr:2c:76:8a:51:d2:08

  23. 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?

  1. [root@localhost~]#ifdowneno2

  2. Device'eno2'successfullydisconnected.

  3. [root@localhost~]#cat/proc/net/bonding/bond0

  4. EthernetChannelBondingDriver:v3.7.1(April27,2011)

  5. BondingMode:fault-tolerance(active-backup)

  6. PrimarySlave:None

  7. CurrentlyActiveSlave:eno1#切换成功

  8. MIIStatus:up

  9. MIIPollingInterval(ms):100

  10. UpDelay(ms):0

  11. DownDelay(ms):0

  12. SlaveInterface:eno1

  13. MIIStatus:up

  14. Speed:1000Mbps

  15. Duplex:full

  16. LinkFailureCount:0

  17. PermanentHWaddr:2c:76:8a:51:d2:08

  18. 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


详细可参考红帽官网

原文链接:https://www.f2er.com/centos/377160.html

猜你在找的CentOS相关文章