Debian 9.4 多网卡链路聚合bond配置

Debian 9.4 多网卡链路聚合bond配置

安装ifenslave

  1. ifenslave 的作用是网卡的负载均衡
root@debian:~# apt-get install ifenslave
root@debian:~# dpkg -l | grep ifenslave
ii  ifenslave                             2.9                                         all          configure network interfaces for parallel routing (bonding)

编辑 /etc/network/interfaces 配置文件

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0                    #eth0作为远程使用的IP地址
iface eth0 inet static
      address 192.168.121.94
      netmask 255.255.255.0
      gateway 192.168.121.2

auto bond0
iface bond0 inet static
      address 192.168.121.100
      netmask 255.255.255.0
      gateway 192.168.121.2
      bond-mode 0
      bond-slaves eth1 eth2
      bond-miimon 100
      bond-downdelay 200
      bond-updelay 200

auto eth1                   #eth1和eth2作为需要绑定的网卡,不需要给定IP地址
iface eth1 inet static

auto eth2
iface eth2 inet static
  • 注释
auto bond0
iface bond0 inet static
      address 192.168.121.100
      netmask 255.255.255.0
      gateway 192.168.121.2
      bond-mode 0             #网卡模式(0代表负载均衡模式;1代表主备模式)
      bond-slaves eth1 eth2   #所绑定的网卡
      bond-primary eth1       #设置绑定的主网卡,有流量优先走eth1(当模式为1)
      bond-miimon 100         #网卡状态监测周期100ms
      bond-downdelay 200      #网卡down时间
      bond-updelay  200       #网卡up时间
  • bond-mode 模式列表
0:      balance-rr       负载均衡模式
1:      active-backup    主备模式
2:      balance-xor      异或策略
3:      broadcast        广播策略
4:      802.3ad          动态链接聚合
5:       balance-tlb      适配器传输负载均衡
6:      balance-alb      适配器负载均衡

开机自动加载bonding模块

  1. 编辑 /etc/modules 文件
root@debian:~# vim /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
bonding            #添加这行

重启服务器

root@debian:~# reboot
  • 使用 systemctl restart networking.service 这个命令重启网络服务会一直报错,不知道为啥,重启就好了

查看

root@debian:~# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:38:1f:4c brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.94/24 brd 192.168.121.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe38:1f4c/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
    link/ether 00:0c:29:38:1f:56 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
    link/ether 00:0c:29:38:1f:56 brd ff:ff:ff:ff:ff:ff
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:38:1f:56 brd ff:ff:ff:ff:ff:ff
    inet 192.168.121.100/24 brd 192.168.121.255 scope global bond0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe38:1f56/64 scope link tentative dadfailed 
       valid_lft forever preferred_lft forever
原文地址:https://www.cnblogs.com/itwangqiang/p/14311967.html