Linux学习-2.网卡绑定

一.bond技术

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

1.编辑两个需要绑定的网卡的配置文件:

[root@shijie ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=eno16777736
MASTER=bond0
SLAVE=yes
[root@shijie ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno33554968
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=eno33554968
MASTER=bond0
SLAVE=yes

2.编辑绑定后的网卡

[root@shijie ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
DEVICE=bond0
IPADDR=192.168.10.10
PREFIX=24
DNS=192.168.10.1

3.加载模块

编辑/etc/modprobe.d/bond.conf文件,没有的话直接创建,配置bond0的链路检查时间为100ms,模式为6,fail_over_mac=1是在vmware workstation虚拟机中添加,防止实验失败,实际物理机不需要添加。

[root@shijie ~]# vim /etc/modprobe.d/bond.conf
alias bond0 bonding
options bond0 miimon=100 mode=6 fail_over_mac=1

bond的几个常用模式:

mode0(平衡负载模式):平时两块网卡均工作,且自动备援,但需要在与服务器本地网卡相连的交换机设备上进行端口聚合来支持绑定技术。
mode1(自动备援模式):平时只有一块网卡工作,在它故障后自动替换为另外的网卡。
mode6(平衡负载模式):平时两块网卡均工作,且自动备援,无须交换机设备提供辅助支持。

4.重启网络服务

systemctl restart network

二.team技术

team,聚合链接(也称为链路聚合)有多块网卡(team-slave)一起组建而成的虚拟网卡。

1.添加team组

nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"} }'

team模式:轮询式(roundrobin)的流量负载均衡,热备份(activebackup)连接冗余。

2.添加成员

添加两个网卡到team0中

nmcli connection add type team-slave ifname eno16777736 master team0
nmcli connection add type team-slave ifname eno33554992 master team0

将原网卡的配置文件备份

mv /etc/sysconfig/network-scripts/ifcfg-eno16777736  /etc/sysconfig/network-scripts/ifcfg-eno16777736.bak
mv /etc/sysconfig/network-scripts/ifcfg-eno33554992  /etc/sysconfig/network-scripts/ifcfg-eno33554992.bak

3.配置地址

ifconfig eno16777736 192.168.10.10 netmask 255.255.255.0

4.激活设备

nmcli connection  up  team-slave-eno16777736  激活从设备eno16777736
nmcli connection  up  team-slave-eno33554992  激活从设备eno33554992
nmcli connection  up  team0            激活主设备team0
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章