百花洲 發表於 2021-1-22 10:37:00

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

<h2 id="debian-94-多网卡链路聚合bond配置">Debian 9.4 多网卡链路聚合bond配置</h2>
<h3 id="安装ifenslave">安装ifenslave</h3>
<ol>
<li><strong>ifenslave</strong> 的作用是网卡的负载均衡</li>
</ol>
<pre><code>root@debian:~# apt-get install ifenslave
root@debian:~# dpkg -l | grep ifenslave
iiifenslave                           2.9                                       all          configure network interfaces for parallel routing (bonding)
</code></pre>
<h3 id="编辑-etcnetworkinterfaces-配置文件">编辑 /etc/network/interfaces 配置文件</h3>
<pre><code># 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
</code></pre>
<ul>
<li>注释</li>
</ul>
<pre><code>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-updelay200       #网卡up时间
</code></pre>
<ul>
<li><strong>bond-mode</strong> 模式列表</li>
</ul>
<pre><code>0:      balance-rr       负载均衡模式
1:      active-backup    主备模式
2:      balance-xor      异或策略
3:      broadcast      广播策略
4:      802.3ad          动态链接聚合
5:       balance-tlb      适配器传输负载均衡
6:      balance-alb      适配器负载均衡
</code></pre>
<h3 id="开机自动加载bonding模块">开机自动加载bonding模块</h3>
<ol>
<li>编辑 <strong>/etc/modules</strong> 文件</li>
</ol>
<pre><code>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            #添加这行
</code></pre>
<h3 id="重启服务器">重启服务器</h3>
<pre><code>root@debian:~# reboot
</code></pre>
<ul>
<li>使用 <strong>systemctl restart networking.service</strong> 这个命令重启网络服务会一直报错,不知道为啥,重启就好了</li>
</ul>
<h3 id="查看">查看</h3>
<pre><code>root@debian:~# ip add
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; 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: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; 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: &lt;BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP&gt; 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: &lt;BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP&gt; 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: &lt;BROADCAST,MULTICAST,MASTER,UP,LOWER_UP&gt; 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
</code></pre><br><br>
来源:https://www.cnblogs.com/itwangqiang/p/14311967.html
頁: [1]
查看完整版本: Debian 9.4 多网卡链路聚合bond配置