Ubuntu服务器使用active-backup模式进行网口绑定

简介

在这次阿拉善的出差过程中,自己也在疲惫的工作中学到一些可以在以后的工作中使用或者自己觉得重要的东西,昨天晚上已经总结过XShell快速命令配置使用,在阿拉善出差的9天中,还有另外两个主题的工作内容需要总结。

  • Ubuntu服务器使用active-backup(模式1)模式进行网口绑定
  • Ubuntu服务器使用动态链接聚合(模式4)模式进行网口绑定
  • CPU核数变为1如何解决

在9天的出差过程中,虽然被搞得很疲惫,但自己依然从过程中学到了一些东西,通过把这些东西总结,并输出博客上,加深理解,防止在以后的工作中遇到相同的场景而束手无策。毕竟经验是需要积攒的。不要让一个问题在第一次遇到时是一个问题,在第二次遇到时,依然是一个问题,这样,我们便在不同的不断的小进步,当积少成多,量变导致质变,会很客观的。

在操作是,主要是参考Ubuntu 网口绑定进行实践的

为什么要进行网口绑定

绑定,也称为端口聚合或链路聚合,意味着将多个网络接口(NIC)组合到单个链路,从而提供高可用性(容错),负载平衡,最大吞吐量或这些组合。 说白了,也是客户要求,通过这种网口绑定的机制实现高性能、可靠性,没有办法,只能去实现了。

网口绑定的模式

  • 0:(balance-rr) Round-robin policy: (平衡轮询策略):传输数据包顺序是依次传输,直到最后一个传输完毕,此模式提供负载平衡和容错能力。
  • 1:(active-backup) Active-backup policy:(活动备份策略):只有一个设备处于活动状态。一个宕掉另一个马上由备份转换为主设备。mac地址是外部可见得。此模式提供了容错能力
  • 2:(balance-xor) XOR policy:(平衡策略):传输根据[(源MAC地址xor目标MAC地址)mod设备数量]的布尔值选择传输设备。 此模式提供负载平衡和容错能力。
  • 3:(broadcast) Broadcast policy:(广播策略):将所有数据包传输给所有设备。此模式提供了容错能力。
  • 4:(802.3ad) IEEE 802.3ad Dynamic link aggregation. IEEE 802.3ad 动态链接聚合:创建共享相同的速度和双工设置的聚合组。此模式提供了容错能力。每个设备需要基于驱动的重新获取速度和全双工支持;如果使用交换机,交换机也需启用 802.3ad 模式。
  • 5:(balance-tlb) Adaptive transmit load balancing(适配器传输负载均衡):通道绑定不需要专用的交换机支持。发出的流量根据当前负载分给每一个设备。由当前设备处理接收,如果接受的设 备传不通就用另一个设备接管当前设备正在处理的mac地址。
  • 6:(balance-alb) Adaptive load balancing: (适配器负载均衡):包括mode5,由 ARP 协商完成接收的负载。bonding驱动程序截获 ARP在本地系统发送出的请求,用其中之一的硬件地址覆盖从属设备的原地址。就像是在服务器上不同的人使用不同的硬件地址一样。

材料

ifenslave

负载均衡软件fenslave,它是一款linux下的负载均衡工具,可以将数据包有效的分配到bonding驱动。

网口绑定配置过程

总览

配置的主要步骤如下所示:

配置步骤

安装ifenslave

负载均衡软件fenslave,它是一款linux下的负载均衡工具,可以将数据包有效的分配到bonding驱动。

安装如果在联网环境下,可以采用

apt-get install ifenslave

如果是在离线环境下,可以在ifenslave 2.7ubuntu1 (amd64 binary) in ubuntu xenial下载ifenslave的安装包和源码包。

在此需要简单的说明一下,在安装该可执行程序时,由于自己不知道ifenslave是否依赖其他文件,因此在网站上查看该软件包,不知为何就觉得一定依赖很多文件,因此就直接下载了源码包(并不明白为什么自己会先入为主),然后自己花时间通过光盘把源码包导入到服务器上,虽然解压就可以使用,但由于不知道应该把可执行文件放置在何处,这种方式不得不作罢。

我同事说,或许可以直接安装了,这样可以按照程序自己设定的位置去自动放置应该位于的位置。因此自己就转向了这个思路,自己采用源码安装的思路是因为自己觉得很有可能,这个软件在安装时会需要依赖其他的软件,一旦产生依赖树,依赖爆炸的问题就没有办法解决了。然而实际上,这种问题并不存在,而是自己这种自己吓唬自己的思维方式限制了自己,导致自己浪费了一些时间,自己很明显应该先去验证是否真的存在依赖爆炸的问题,就像上图中,ifenslave2.7依赖了命令ifupdown(>=0.7.46),自己可以通过

dpkg -l | grep ifupdownsqh@sqh-virtual-machine:~$ dpkg -l | grep -E "ifupdown|iproute2"
ii  ifupdown  0.8.10ubuntu1.4         amd64   high level tools to configure network interfaces
ii  iproute2  4.3.0-1ubuntu3.16.04.4  amd64   networking and traffic control tools
sqh@sqh-virtual-machine:~$

这就表明,ifupdown所需要的依赖,系统已经预先安装,因此可以放心的直接下载可执行deb包进行安装。

离线压缩包。

可以在ifenslave 2.7ubuntu1 (amd64 binary) in ubuntu xenial下载ifenslave的安装包和源码包。

在获取离线压缩包ifenslave_2.7ubuntu1_all.deb,使用dpkg -i 即可实现安装。

dpkg -i ifenslave_2.7ubuntu1_all.deb

配置内核管理

介绍一下几个命令lsmodmodinfomodprobe

lsmod主要是显示系统当前加载了那些内核模块。

NAMElsmod - Show the status of modules in the Linux KernelSYNOPSISlsmodDESCRIPTIONlsmod is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded.简言之,lsmod就是表示系统加载了那些内核。

modinfo则用于提取内核模块的信息。可以通过该命令查看内核模块是否已经存在,并且被系统所支持

MODINFO(8)                                         modinfo                                        MODINFO(8)NAMEmodinfo - Show information about a Linux Kernel moduleSYNOPSIS
MODINFO(8)                                         modinfo                                        MODINFO(8)NAMEmodinfo - Show information about a Linux Kernel moduleSYNOPSISmodinfo [-0] [-F field] [-k kernel] [modulename|filename...]modinfo -Vmodinfo -hDESCRIPTIONmodinfo extracts information from the Linux Kernel modules given on the command line. If the modulename is not a filename, then the /lib/modules/version directory is searched, as is also done bymodprobe(8) when loading kernel modules.modinfo by default lists each attribute of the module in form fieldname : value, for easy reading.The filename is listed the same way (although it's not really an attribute).This version of modinfo can understand modules of any Linux Kernel architecture.

modprobe的主要作用从Linux内核中添加和移除模块。

MODPROBE(8)                                       modprobe                                       MODPROBE(8)NAMEmodprobe - Add and remove modules from the Linux Kernel

因此我的思路也是一样的,首先判断内核模块是否存在。

注意:通过modinfo可以查看内核模块支持的参数,从下属的命令中,可以看到bonding的重要参数包括

miimon(Link check interval in milliseconds (int))、mode(Mode of operation; 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp))、primary(Primary network device to use (charp))等重要参数

sqh@sqh-virtual-machine:~$ modinfo bonding
filename:       /lib/modules/4.15.0-46-generic/kernel/drivers/net/bonding/bonding.ko
author:         Thomas Davis, tadavis@lbl.gov and many others
description:    Ethernet Channel Bonding Driver, v3.7.1
version:        3.7.1
license:        GPL
alias:          rtnl-link-bond
srcversion:     10478C9FE27D36218C487F5
depends:
retpoline:      Y
intree:         Y
name:           bonding
vermagic:       4.15.0-46-generic SMP mod_unload
parm:           max_bonds:Max number of bonded devices (int)
parm:           tx_queues:Max number of transmit queues (default = 16) (int)
parm:           num_grat_arp:Number of peer notifications to send on failover event (alias of num_unsol_na) (int)
parm:           num_unsol_na:Number of peer notifications to send on failover event (alias of num_grat_arp) (int)
parm:           miimon:Link check interval in milliseconds (int)
parm:           updelay:Delay before considering link up, in milliseconds (int)
parm:           downdelay:Delay before considering link down, in milliseconds (int)
parm:           use_carrier:Use netif_carrier_ok (vs MII ioctls) in miimon; 0 for off, 1 for on (default) (int)
parm:           mode:Mode of operation; 0 for balance-rr, 1 for active-backup, 2 for balance-xor, 3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, 6 for balance-alb (charp)
parm:           primary:Primary network device to use (charp)
parm:           primary_reselect:Reselect primary slave once it comes up; 0 for always (default), 1 for only if speed of primary is better, 2 for only on active slave failure (charp)
parm:           lacp_rate:LACPDU tx rate to request from 802.3ad partner; 0 for slow, 1 for fast (charp)
parm:           ad_select:802.3ad aggregation selection logic; 0 for stable (default), 1 for bandwidth, 2 for count (charp)
parm:           min_links:Minimum number of available links before turning on carrier (int)
parm:           xmit_hash_policy:balance-xor and 802.3ad hashing method; 0 for layer 2 (default), 1 for layer 3+4, 2 for layer 2+3, 3 for encap layer 2+3, 4 for encap layer 3+4 (charp)
parm:           arp_interval:arp interval in milliseconds (int)
parm:           arp_ip_target:arp targets in n.n.n.n form (array of charp)
parm:           arp_validate:validate src/dst of ARP probes; 0 for none (default), 1 for active, 2 for backup, 3 for all (charp)
parm:           arp_all_targets:fail on any/all arp targets timeout; 0 for any (default), 1 for all (charp)
parm:           fail_over_mac:For active-backup, do not set all slaves to the same MAC; 0 for none (default), 1 for active, 2 for follow (charp)
parm:           all_slaves_active:Keep all frames received on an interface by setting active flag for all slaves; 0 for never (default), 1 for always. (int)
parm:           resend_igmp:Number of IGMP membership reports to send on link failure (int)
parm:           packets_per_slave:Packets to send per slave in balance-rr mode; 0 for a random slave, 1 packet per slave (default), >1 packets per slave. (int)
parm:           lp_interval:The number of seconds between instances where the bonding driver sends learning packets to each slaves peer switch. The default is 1. (uint)

由此,我们可以看到,Ubuntu 16.04支持模块bonding。

可以执行命令

sqh@sqh-virtual-machine:~$ lsmod | grep modinfo
sqh@sqh-virtual-machine:~$ lsmod | grep bonding
sqh@sqh-virtual-machine:~$ modprobe bonding
modprobe: ERROR: could not insert 'bonding': Operation not permitted
sqh@sqh-virtual-machine:~$ su
Password:
root@sqh-virtual-machine:/home/sqh# modprobe bonding
root@sqh-virtual-machine:/home/sqh# lsmod | grep bonding
bonding               163840  0
root@sqh-virtual-machine:/home/sqh# 

从上面可以看到,确实只有在使用root用户加载了bonding模块之后,lsmod才能看到该模块。

配置开机自动加载模块

配置系统开机自动加载模块

sudo 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

配置interfaces

配置网口绑定一个较为重要的内容,就是在配置文件**/etc/network/interfaces**中配置网口绑定的模式和检测率

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback#auto enp96s0f0
#iface enp96s0f0 inet static
#address 66.10.66.168
#netmask 255.255.255.0
#gateway 66.10.66.1#auto enp96s0f1
#iface enp96s0f1 inet static
#address 9.9.9.246
#netmask 255.255.255.0
#gateway 9.9.9.1auto enp96s0f0
iface enp96s0f0 inet manual
bond-master bond0
bond-primary enp96s0f0auto enp96s0f1
iface enp96s0f1 inet manual
bond-master bond0auto bond0
iface bond0 inet static
address 66.10.66.168
netmask 255.255.255.0
gateway 66.10.66.1
bond-mode active-backup
bond-miimon 100
bond-slaves none

重启网络

/etc/init.d/networing restart
/etc/init.d/network-manager restart

如果能够正常的重启网络,则不需要重启,否则需要通过reboot命令重启网络。

查看结果

/proc/net/bonding/bond0

在配置完interfaces之后,通过重启网络或者重启服务器,如果能够正常运行,可以看到下面的结果

root@ubuntu-desktop:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)(容错能力)
Primary Slave: None
Currently Active Slave: enp96s0f0MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: enp96s0f1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:11:0a:57:5f:4e
Slave queue ID: 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:11:0a:57:5f:4f
Slave queue ID: 0

ifconfig命令

root@ubuntu-desktop:~# ifconfigbond0     Link encap:Ethernet  HWaddr 00:11:0a:57:5f:4e  inet addr:192.168.4.200  Bcast:192.168.4.255  Mask:255.255.255.0inet6 addr: fe80::211:aff:fe57:5f4e/64 Scope:LinkUP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1RX packets:78 errors:0 dropped:2 overruns:0 frame:0TX packets:125 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:7645 (7.6 KB)  TX bytes:18267 (18.2 KB)enp96s0f0 Link encap:Ethernet  HWaddr 00:11:0a:57:5f:4e  UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1RX packets:76 errors:0 dropped:0 overruns:0 frame:0TX packets:125 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:7525 (7.5 KB)  TX bytes:18267 (18.2 KB)enp96s0f1 Link encap:Ethernet  HWaddr 00:11:0a:57:5f:4e  UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1RX packets:2 errors:0 dropped:2 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:120 (120.0 B)  TX bytes:0 (0.0 B)

通过对命令可以看到,虚拟出来的网卡bond0和两个物理网卡的Mac地址都变成同一个了,

00:11:0a:57:5f:4e

这也就表示在Ubuntu16.04服务器使用active-backup模式配置端口绑定已经成功了。

验证

验证的方式较为简单,当enp96s0f1和enp96s0f0两个网卡组合成模式1的网口绑定时,表示两个网卡形成主备模式,当网卡enp96s0f0故障时,可以直接把网线插入另一个网卡,系统仍然工作,就好像两个网卡是一个一样。

总结

通过本文,详细介绍了使用active-backup模式配置Ubutun服务器的过程,算是情景在现吧,这样当再次出现相同情景时,只要按部就班,就能自信的完成网口绑定的工作了。虽然现在总结了一上午挺累的,但还是挺开心的。

参考

  • bond下插拔网线和命令关闭端口造成结果不同的原因 从中可以获得bond-miimon 100的含义的理解。
  • Ubuntu及RHEL linux环境下多端口捆绑实战验证(基于模式4和1)可以查看配置过后的文件结果状态
  • Ubuntu 网口绑定进行实践的,主要是借鉴这个实现active-backup模式的网口绑定的。
  2020年5月24日 12点37分于奥克斯时代未来之城

Ubuntu服务器使用active-backup模式进行网口绑定相关推荐

  1. foxmail 服务器备份 立刻删除_PC整机备份与还原教程 Active Backup for Business

    使用 Synology Active Backup Business 备份套件(以下简称 ABB ),就能享有备份一体机,集中备份 Winodws PC 和服务器整机.文件服务器.虚拟机.公有云的数据 ...

  2. Ubuntu服务器直连交换机,网口灯不亮

    问题排查: 1.网线影响,检查网线还能否正常使用,有可能网线水晶头松动造成直连不通: 2.交换机影响,可用笔记本直连交换机,网口灯闪烁,证明交换机没问题,排查设备质量问题: 3.兆数不匹配:终端输入e ...

  3. 一篇文章彻底掌握 FTP 服务器的 ACTIVE 与 PASSIVE 工作模式

    1 背景 某客户现场,每天都会批量生成大量 CSV 文件存放到 FTP 系统,这些 CSV 文件需要导入到大数据平台 HIVE 数仓中做后续离线分析,且 HIVE 数仓中的离线分析作业目前是使用 JE ...

  4. 无法安装冰点还原_PC整机备份与还原教程 Active Backup for Business

    使用 Synology Active Backup Business 备份套件(以下简称 ABB ),就能享有备份一体机,集中备份 Winodws PC 和服务器整机.文件服务器.虚拟机.公有云的数据 ...

  5. Ubuntu 服务器初始化、系统安全加固、系统内核参数优化以及常用软件安装脚本分享...

    描述: 该加固脚本符合等级保护要求,后续将会持续扩充. Github 下载地址: https://github.com/WeiyiGeek/SecOpsDev/blob/master/OS-%E6%9 ...

  6. 服务器ubuntu系统版本选型原则,系统集成 - 选择Ubuntu服务器版操作系统的六大理由_服务器应用_Linux公社-Linux系统门户网站...

    二. 系统集成 (1)集成现有的系统 Ubuntu服务器版本用常用的身份认证方式和服务入口工具简单地集成企业现有的客户/服务器结构.我们都知道系统集成技术的重要性,这也是Ubuntu团队花费大量时间研 ...

  7. ft服务器设置传输协议,ft服务器设置成主动模式

    ft服务器设置成主动模式 内容精选 换一换 如果您选择使用SFS Turbo实现文件共享存储,此章节操作可跳过,您可以参见<SAP HANA用户指南>中的"格式化磁盘" ...

  8. 创建使用 Active Directory 模式隔离用户的新 FTP 站点

    "使用 Active Directory 隔离用户"模式根据相应的 Active Directory 容器验证用户凭据,而不是搜索整个 Active Directory,因为这样做 ...

  9. 使用samba服务在Linux与Windows直接共享文件夹,海康威视网络摄像头录像视频存储到ubuntu服务器

    目录 背景 SMB共享介绍 访问共享的命令和方式 本人亲测环境 海康威视网络摄像头录像视频存储到ubuntu服务器 背景 应项目要求,海康威视网络摄像头的监控客户端要在windows系统上,录像视频要 ...

最新文章

  1. 重读【代码整洁之道】
  2. 2021-07-27 对labelme标注出来的JSON文件进行灰度图转化(标签值0.1.2.3.4)
  3. leetcode 380. Insert Delete GetRandom O(1) | 380. O(1) 时间插入、删除和获取随机元素(Java)
  4. STM8 ADC转换模式-------单次模式
  5. 什么是控制台应用程序
  6. php redis令牌桶,php 基于redis使用令牌桶算法实现流量控制
  7. iOS Facebook pop动画进阶
  8. 【python进阶】古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
  9. 计算机基础知识教程 pdf,《计算机基础知识教程》.pdf
  10. SHOUG线上活动 Maclean Liu分享《学习甲骨文数据库的自由之翼-与Oracle的世界相连接》...
  11. Ubuntu 6.10 (Edgy) 黑体解决方案
  12. 易基因|ctDNA甲基化测序分析(ctDNA-WGBS)用于癌症检测和分子分型 | 精准医学
  13. unfortunately, system ui has stopped
  14. 【OpenFOAM学前预备1——安装Win10系统】
  15. target=_blank的使用
  16. linux关机命令60秒,Linux关机重启命令有哪些用法
  17. 简单的banner代码,用css实现滚动banner焦点图, 不用jq也能滚动banner
  18. [深蓝学院]自动驾驶环境感知
  19. 数学思想 之 归纳法
  20. doccano(NLP标签)使用

热门文章

  1. C#重要知识点在游戏开发中的应用
  2. 一篇文章入门Word2Vec
  3. W ndows10如何清理使用痕迹,Windows10怎么清除使用痕迹?
  4. margin和padding之我见
  5. python:PDF转音频文件--有声读物(附完整源码)
  6. 从ppu端向spu端发送信号的小程序
  7. 使用python对音频信号进行降噪
  8. Python 下载大文件,哪种方式速度更快
  9. [转载]FPGA学习步骤
  10. android切图尺寸_iOS、Android 开发单位换算及 UI 切图要求