--- title: "CentOS7 双网卡绑定" date: 2019-10-30T11:07:30+08:00 lastmod: 2019-10-30T11:07:30+08:00 keywords: [] tags: ["centos", "bond"] categories: ["network"] --- ## bond 概要 ### 什么是 bond - 网卡bond是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡。在应用部署中是一种常用的技术。 ### bond的模式种类 - Mode=0(balance-rr) 表示负载分担round-robin,和交换机的聚合强制不协商的方式配合 - Mode=1(active-backup) 表示主备模式,只有一块网卡是active,另外一块是备的standby - **如果交换机配的是捆绑,将不能正常工作,因为交换机往两块网卡发包,有一半包是丢弃的** - Mode=2(balance-xor) 表示XOR Hash负载分担,和交换机的聚合强制不协商方式配合(需要xmit_hash_policy) - Mode=3(broadcast) 表示所有包从所有interface发出,这个不均衡,只有冗余机制...和交换机的聚合强制不协商方式配合 - Mode=4(802.3ad) 表示支持802.3ad协议,和交换机的聚合LACP方式配合(需要xmit_hash_policy) - Mode=5(balance-tlb) 是根据每个slave的负载情况选择slave进行发送,接收时使用当前轮到的slave - Mode=6(balance-alb) 在5的tlb基础上增加了rlb ## CentOS7 配置 bond ### 环境 - 操作系统 CentOS7.6,禁用 NetworkManager 服务 - 物理网卡 eth0, eth1 绑定到 bond0 - 物理网卡 eth2, eth3 绑定到 bond1 ### 网卡 eth0 配置 - 修改 /etc/sysconfig/network-scripts/ifcfg-eth0 ``` TYPE=Ethernet BOOTPROTO=none DEVICE=eth0 ONBOOT=yes USERCTL=no SLAVE=yes MASTER=bond0 ``` ### 网卡 eth1 配置 - 修改 /etc/sysconfig/network-scripts/ifcfg-eth1 ``` TYPE=Ethernet BOOTPROTO=none DEVICE=eth1 ONBOOT=yes USERCTL=no SLAVE=yes MASTER=bond0 ``` ### 网卡 eth2 配置 - 修改 /etc/sysconfig/network-scripts/ifcfg-eth2 ``` TYPE=Ethernet BOOTPROTO=none DEVICE=eth2 ONBOOT=yes USERCTL=no SLAVE=yes MASTER=bond1 ``` ### 网卡 eth3 配置 - 修改 /etc/sysconfig/network-scripts/ifcfg-eth3 ``` TYPE=Ethernet BOOTPROTO=none DEVICE=eth3 ONBOOT=yes USERCTL=no SLAVE=yes MASTER=bond1 ``` ### 增加网卡 bond0 配置 - 创建 /etc/sysconfig/network-scripts/ifcfg-bond0 ``` TYPE=Ethernet BOOTPROTO=static NAME=bond0 DEVICE=bond0 ONBOOT=yes IPADDR=192.168.1.101 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=114.114.114.114 ``` ### 增加网卡 bond1 配置 - 创建 /etc/sysconfig/network-scripts/ifcfg-bond1 ``` TYPE=Ethernet BOOTPROTO=static NAME=bond0 DEVICE=bond0 ONBOOT=yes IPADDR=192.168.1.102 NETMASK=255.255.255.0 #GATEWAY=192.168.1.1 #DNS1=114.114.114.114 ``` ### 配置绑定模式 - 创建 /etc/modprobe.d/bonding.conf,加入以下内容 ``` alias bond0 bonding alias bond1 bonding options bonding miimon=100 mode=1 ``` ### 载入 bonding 模块,重启 network 服务 ```bash modprobe bonding systemctl restart network ``` ### 查看网卡绑定状态 ```bash cat /proc/net/bonding/bond0 cat /proc/net/bonding/bond1 ``` ## CentOS8 配置 bond - 建立 bond 连接配置文件 ```bash nmcli c add con-name bond0 type bond ifname bond0 mode active-backup ``` - 增加两个网卡都 bond0 ```bash nmcli c add type bond-slave ifname eth1 master bond0 nmcli c add type bond-slave ifname eth2 master bond0 ``` - 启动这两个 slave 连接 ```bash nmcli c up bond-slave-eth1 nmcli c up bond-slave-eth2 ```