1.首先關閉NetworkManager服務
service NetworkManager stop
2、查看網卡名稱,確定要綁定的網卡,本次配置選擇雙網卡綁定
ifconfig #使用ifconfig命令可以看到網卡的列表
實現物理網口enp5s0f0,enp5s0f1網卡綁定,綁定后的虛擬邏輯網口bond0
3、modinfo bonding 檢查自己的操作系統是否支持bonding
[root@localhost ~]# modinfo bonding filename: /lib/modules/3.10.0-693.lns7.8.mips64el/kernel/drivers/net/bonding/bonding.ko author: Thomas Davis, tadavis@lbl.gov and many others description: Ethernet Channel Bonding Driver, v3.7.1 version: 3.7.1 license: GPL alias: rtnl-link-bond rhelversion: 7.4 srcversion: 694CF99DDA3170BD385D0E1 depends: intree: Y vermagic: 3.10.0-693.lns7.8.mips64el SMP preempt mod_unload modversions LOONGSON3 64BIT parm: max_bonds:Max number of bonded devices (int) ... ... ... ... ... ... ... ...
如果沒有消息返回,說明內核不支持bonding
4、創建網卡綁定配置文件
cd /etc/sysconfig/network-scripts/
備份原來的配置文件
cp ifcfg-enp5s0f0 bak/
cp ifcfg-enp5s0f1 bak/
新建綁定文件
vi ifcfg-bond0 DEVICE=bond0 TYPE=Ethernet ONBOOT=yes BOOTPROTO=none IPADDR=10.150.1.200 NETMASK=255.255.255.0 GATEWAY=10.150.1.1 DNS1=202.99.192.68 DNS2=8.8.8.8 USERCTL=no
5、修改原網卡enp5s0f0和enp5s0f1配置文件
ifcfg-enp5s0f0: DEVICE=enp5s0f0 ONBOOT=yes BOOTPROTO=none MASTER=bond0 SLAVE=yes USERCTL=no
ifcfg-enp5s0f1: DEVICE=enp5s0f1 ONBOOT=yes BOOTPROTO=none MASTER=bond0 SLAVE=yes USERCTL=no
6、修改modprobe相關設定文件,並加載bonding模塊
vi /etc/modprobe.d/bonding.conf alias bond0 bonding options bonding mode=6 miimon=200
執行命令加載模塊
modprobe bonding
miimon=100為每100毫秒(0.1秒)檢查網絡一次,可以根據自己需求修改
mode為網卡工作模式,共七種,通常設置0、1、6這幾種
7、重啟網卡
[root@localhost network-scripts]# lsmod | grep bonding bonding 134260 0 [root@localhost network-scripts]# service network restart
8、查看綁定狀態
[root@localhost network-scripts]# cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: enp5s0f0 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: enp5s0f0 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:23:9e:05:72:7f Slave queue ID: 0 Slave Interface: enp5s0f1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:23:9e:05:72:80 Slave queue ID: 0
9、斷網測試
(略)
Mode模式說明:
Mode | 功能 | 功能說明 |
0 | balance-rr | 負載均衡模式需要switch配置(trunk)支持才能發揮實際 效果,具有容錯功能,其中一塊網卡失效仍可持續工作 |
1 | active-backup | 同一時間終於一塊網卡工作,Active Slave其中一塊網卡斷 線時自動啟用另一塊網卡,不需要switch支持 |
2 | balance-xor | 具容錯作用 |
3 | broadcast | 所有網卡一起收發網絡數據包,具容錯功能,其中一塊網卡 斷線仍可持續工作 |
4 | 802.3ad | 無實際功能,不建議使用 |
5 | balance-tlb | 發送數據包自動負載均衡,接收數據包有Current Active Slave 負責,具容錯功能,其中一塊網卡失效仍可持續工 作,不需要switch支持配置 |
6 | balance-alb | 發送及接收皆自動負載均衡。具有容錯功能,其中一塊網卡 斷線時仍可持續工作,網卡驅動程序需要支持setting hardware address功能,不需要switch支持及配置 |