当前位置: 移动技术网 > 网络运营>服务器>Linux > Linux采用双网卡bond、起子接口的方式

Linux采用双网卡bond、起子接口的方式

2019年04月18日  | 移动技术网网络运营  | 我要评论

什么是bond

网卡bond是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术。

适用场景

服务器两张网卡需要做bond,并且bond后网卡需配置不同网段的地址,用于走不同流量,这个时候就可以采用起子接口的方式。

实验场景

设备

  • 服务器:server_a
  • 核心交换机:switch_a、switch_b

交换机连接方式:堆叠

服务器网卡:enp176s0f0、enp176s0f1做bond

ip段划分

  • 业务段
        vlan 201:10.10.51.0/24
  • 公网
         vlan 401:111.20.200.88/27

要求

服务器server_a上联的两台核心交换机switch_a和switch_b采用堆叠方式,server_a的enp176s0f0和enp176s0f1光口分别互联switch_a和switch_b;现要求enp176s0f0和enp176s0f1做bond,地址10.10.51.16走业务流量,地址111.20.200.90走公网流量,交换机端口做捆绑eth-trunk并透传vlan201和vlan401。

网卡配置脚本

# 停掉networkmanager服务
systemctl stop networkmanager.service 
systemctl disable networkmanager.service

# 备份
cp /etc/sysconfig/network-scripts/ifcfg-enp176s0f0{,.bak}
cp /etc/sysconfig/network-scripts/ifcfg-enp176s0f1{,.bak}

# 将网卡协议改为none并设备未开机自启动,并做双网卡配置
sed -i 's/bootproto=dhcp/bootproto=none/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f0
sed -i 's/onboot=no/onboot=yes/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f0
echo "master=bond0" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f0
echo "slave=yes" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f0

sed -i 's/bootproto=dhcp/bootproto=none/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f1
sed -i 's/onboot=no/onboot=yes/' /etc/sysconfig/network-scripts/ifcfg-enp176s0f1
echo "master=bond0" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f1
echo "slave=yes" >>/etc/sysconfig/network-scripts/ifcfg-enp176s0f1

# 配置网卡bond0
echo "device=bond0
type=ethernet
onboot=yes
bootproto=static" >/etc/sysconfig/network-scripts/ifcfg-bond0

# 写模块文件,bond模式为mode 0
echo "alias bond0 bonding
options bond0 miimon=100 mode=0" >/etc/modprobe.d/bond.conf
# 加载模块
modprobe bonding

# 起子接口bond0.201
echo "device=bond0.201
type=vlan
physdev=bond0
onboot=yes
bootproto=static
reorder_hdr=yes
ipaddr=10.10.51.16
gateway=10.10.51.1
netmask=255.255.255.0
dns1=114.114.114.114
dns2=8.8.8.8
vlan=yes
vlan_id=201" >/etc/sysconfig/network-scripts/ifcfg-bond0.201

# 起子接口bond0.401
echo "device=bond0.401
type=vlan
physdev=bond0
onboot=yes
bootproto=static
reorder_hdr=yes
ipaddr=111.20.200.90
gateway=111.20.200.89
netmask=255.255.255.0
dns1=114.114.114.114
dns2=8.8.8.8
vlan=yes
vlan_id=401" >/etc/sysconfig/network-scripts/ifcfg-bond0.401

# 加载模块并重启主机
modprobe 8021q
reboot

关键点

交换机侧如果起eth-trunk,那么服务器侧则必须起子接口

交换机侧和服务器侧要么都起lacp协商,要么都不起,否则将造成端口不同

交换机侧eth-trunk口配置示例

[hh2b108-h01-2-hw9006x-sw001-eth-trunk12]display this 
#
interface eth-trunk12
port link-type trunk
port trunk allow-pass vlan 201 401
#
return

服务器侧起lacp协议使用bond模式4,示例如下

 # more /etc/modprobe.d/bond.conf
 alias bond0 bonding
 options bond0 miimon=100 mode=4 lacp_rate=1

子接口配置文件中"device=bond0.401“中的vlan号一定要和需要透传的vlan号保持一致

配置子接口后一定要重启服务器才能生效!!!

总结:

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网