Bonding

Bonding

Tips

Link aggregation

  • Bonding Modes
  • 模式
    • balance-rr - 0 - 轮询
      • 代价是碎片化
      • 对有些协议(CIFS)来说会影响性能
    • active-backup - 1 - 主备
    • balance-xor - 2 - XOR
      • 基于 HASH 算法进行负载均衡
    • broadcast - 3 - 广播
      • 所有绑定的网卡都收到相同的数据, 用于特殊需求, 例如两个互相没连接的交换机发送相同的数据
    • 802.3ad - 4 - IEEE 802.3ad
      • 要求交换机支持 IEEE 802.3ad, 网卡带宽理论上可以翻倍
    • and balance-tlb - Adaptive transmit load balancing - 5 - 适配器传输负载均衡
      • 输出的数据会通过所有被绑定的网卡输出, 接收则只选择其中一个
    • balance-alb - Adaptive load balancing - 6 - 适配器输入/输出负载模式
      • balance-tlb + receive load balancing (rlb)
      • 在 5 的基础上, 接收数据也实现负载均衡
  • balance-rr, active-backup, balance-tlb 和 balance-alb 不需要交换机支持
  • balance-alb 和 balance-tlb 不一定所有交换机都能使用
    • 可能会有 arp 问题, 例如有些机器不能相互连接
    • 需要对 miimon, updelay 进行调试
  • balance-xor 可能会需要交换机配置
    • You need to set up an interface group (not LACP) on HP and Cisco switches, but apparently it's not necessary on D-Link, Netgear and Fujitsu switches.
  • 选项
    • lacp_rate
    • downdelay
  • 参考
  • NOTE
    • 无论如何配置, 单个网络链接都不会超过单个物理链路的速度
    • 802.3ad 需要交换机支持 LACP 组, 性能最好
  • Alpine Bonding
  • ifenslave
# /etc/network/if-post-down.d/bonding
# /etc/network/if-pre-up.d/bonding
# /etc/network/if-up.d/bonding
apk add bonding
# 手动加载驱动
modprobe bonding
# 查看模式
cat /sys/class/net/bond0/bonding/mode
# 查看状态
cat /proc/net/bonding/bond0
ethtool eth0
# jumbo frames
ifconfig bond0 mtu 9000 up

配置案例

最简单的配置

auto bond0
iface bond0 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1
# specify the ethernet interfaces that should be bonded
bond-slaves eth0 eth1 eth2 eth3

四网口聚合

auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet manual
allow-hotplug eth1
iface eth1 inet manual
allow-hotplug eth2
iface eth2 inet manual
allow-hotplug eth3
iface eth3 inet manual
auto bond0
iface bond0 inet static
address 192.168.1.5
netmask 255.255.252.0
gateway 192.168.1.1
bond-slaves eth0 eth1 eth2 eth3
bond-mode active-backup
bond-miimon 100
bond-downdelay 200
bond-updelay 200

无线和有线聚合

allow-hotplug wlan0
iface wlan0 inet manual
wpa-ssid "*censored*"
wpa-key-mgmt WPA-PSK
wpa-group TKIP CCMP
wpa-psk *censored*
wpa-bridge bond0 # fixes mac address of outgoing packets so that they are consistent
bond-master bond0
bond-mode active-backup
bond-miimon 100 # checks link status every 100 msec
bond-give-a-chance 10 # when wlan comes up wait up to 10 seconds for it to
allow-hotplug bond0
iface bond0 inet static
address 192.168.178.130
netmask 255.255.255.0
gateway 192.168.178.1
bond-slaves eth0 # automatically brings up eth0 and slaves it to this bond
bond-mode active-backup # uses primary if available, otherwise fallback to other
bond-primary eth0 # priority to use eth0 when available
bond-miimon 100

tree /sys/class/net/bond0

  • 所有信息
/sys/class/net/bond0
├── addr_assign_type
├── addr_len
├── address
├── bonding
│   ├── active_slave
│   ├── ad_actor_key
│   ├── ad_actor_sys_prio
│   ├── ad_actor_system
│   ├── ad_aggregator
│   ├── ad_num_ports
│   ├── ad_partner_key
│   ├── ad_partner_mac
│   ├── ad_select
│   ├── ad_user_port_key
│   ├── all_slaves_active
│   ├── arp_all_targets
│   ├── arp_interval
│   ├── arp_ip_target
│   ├── arp_validate
│   ├── downdelay
│   ├── fail_over_mac
│   ├── lacp_rate
│   ├── lp_interval
│   ├── mii_status
│   ├── miimon
│   ├── min_links
│   ├── mode
│   ├── num_grat_arp
│   ├── num_unsol_na
│   ├── packets_per_slave
│   ├── primary
│   ├── primary_reselect
│   ├── queue_id
│   ├── resend_igmp
│   ├── slaves
│   ├── tlb_dynamic_lb
│   ├── updelay
│   ├── use_carrier
│   └── xmit_hash_policy
├── broadcast
├── carrier
├── carrier_changes
├── dev_id
├── dev_port
├── dormant
├── duplex
├── flags
├── gro_flush_timeout
├── ifalias
├── ifindex
├── iflink
├── link_mode
├── lower_eth1 -> ../../../pci0000:00/0000:00:1c.4/0000:02:00.1/net/eth1
├── lower_eth2 -> ../../../pci0000:00/0000:00:1c.4/0000:02:00.2/net/eth2
├── lower_eth3 -> ../../../pci0000:00/0000:00:1c.4/0000:02:00.3/net/eth3
├── mtu
├── name_assign_type
├── netdev_group
├── operstate
├── phys_port_id
├── phys_port_name
├── phys_switch_id
├── power
│   ├── autosuspend_delay_ms
│   ├── control
│   ├── runtime_active_time
│   ├── runtime_status
│   └── runtime_suspended_time
├── proto_down
├── queues
│   ├── rx-0
│   │   ├── rps_cpus
│   │   └── rps_flow_cnt
│   ├── tx-0
│   │   ├── byte_queue_limits
│   │   │   ├── hold_time
│   │   │   ├── inflight
│   │   │   ├── limit
│   │   │   ├── limit_max
│   │   │   └── limit_min
│   │   ├── tx_maxrate
│   │   ├── tx_timeout
│   │   └── xps_cpus
├── speed
├── statistics
│   ├── collisions
│   ├── multicast
│   ├── rx_bytes
│   ├── rx_compressed
│   ├── rx_crc_errors
│   ├── rx_dropped
│   ├── rx_errors
│   ├── rx_fifo_errors
│   ├── rx_frame_errors
│   ├── rx_length_errors
│   ├── rx_missed_errors
│   ├── rx_nohandler
│   ├── rx_over_errors
│   ├── rx_packets
│   ├── tx_aborted_errors
│   ├── tx_bytes
│   ├── tx_carrier_errors
│   ├── tx_compressed
│   ├── tx_dropped
│   ├── tx_errors
│   ├── tx_fifo_errors
│   ├── tx_heartbeat_errors
│   ├── tx_packets
│   └── tx_window_errors
├── subsystem -> ../../../../class/net
├── tx_queue_len
├── type
└── uevent